Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
do not check array and class starts with java. or javax.
  • Loading branch information
骏烈 committed Nov 1, 2017
1 parent bce928d commit 0cc98d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ class MapOrSetKeyShouldOverrideHashCodeEqualsRule : AbstractEclipseRule() {
}

private fun isOverrideEqualsAndHashCode(genericType: ITypeBinding): Boolean {
// skip enum
if (genericType.isEnum || genericType.isInterface || genericType.isTypeVariable || genericType.isWildcardType) {
val skip = genericType.isEnum || genericType.isInterface || genericType.isArray
|| genericType.isTypeVariable || genericType.isWildcardType
|| genericType.qualifiedName?.startsWith(skipJdkPackageJava) ?: false
|| genericType.qualifiedName?.startsWith(skipJdkPackageJavax) ?: false
// skip
if (skip) {
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,20 @@ class MapOrSetKeyShouldOverrideHashCodeEqualsInspection : BaseInspection, AliBas

companion object {

private val skipJdkPackageJava = "java."
private val skipJdkPackageJavax = "javax."

private fun redefineHashCodeEquals(psiType: PsiType): Boolean {
if (psiType !is PsiClassType) {
return true
}
val psiClass = psiType.resolve()
if (psiClass == null || psiClass.containingFile == null || psiClass is PsiTypeParameter
|| psiClass.isEnum || psiClass.isInterface) {
return true
}
if (psiClass.containingFile.fileType !is JavaFileType) {
val psiClass = psiType.resolve() ?: return false
val skip = psiClass.containingFile == null || psiClass is PsiTypeParameter
|| psiClass.isEnum || psiClass.isInterface
|| psiClass.containingFile.fileType !is JavaFileType
|| psiClass.qualifiedName?.startsWith(skipJdkPackageJava) ?: false
|| psiClass.qualifiedName?.startsWith(skipJdkPackageJavax) ?: false
if (skip) {
return true
}
val hashCodeMethods = psiClass.findMethodsByName(ObjectConstants.METHOD_NAME_HASHCODE, false)
Expand Down

0 comments on commit 0cc98d1

Please sign in to comment.