Skip to content

Commit

Permalink
Redefine constant in class (NumberConstants ObjectConstants...)
Browse files Browse the repository at this point in the history
  • Loading branch information
骏烈 committed Oct 18, 2017
1 parent e7e6fcc commit 6ab9ac3
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 44 deletions.
17 changes: 11 additions & 6 deletions idea-plugin/p3c-common/src/main/java/icons/P3cIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
* @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");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -56,6 +59,7 @@ class AliProjectComponent(private val project: Project,
}

override fun projectOpened() {
Inspections.addCustomTag(project, "date")
VirtualFileManager.getInstance().addVirtualFileListener(listener)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -131,4 +131,4 @@ object ProblemsUtils {
desc, ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
isOnTheFly, quickFix())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
* @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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
* @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 = '.';
}

0 comments on commit 6ab9ac3

Please sign in to comment.