Merge pull request #158 from SeanCai/master

fix #149 #60 #58
pull/184/head^2
Feng Wei 7 years ago committed by GitHub
commit 78e2a87a66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -28,6 +28,7 @@ import org.eclipse.swt.graphics.Image
import org.eclipse.swt.widgets.Display import org.eclipse.swt.widgets.Display
import org.eclipse.ui.plugin.AbstractUIPlugin import org.eclipse.ui.plugin.AbstractUIPlugin
import org.osgi.framework.BundleContext import org.osgi.framework.BundleContext
import java.util.Locale
/** /**
* @author caikang * @author caikang
@ -72,20 +73,22 @@ class SmartfoxActivator : AbstractUIPlugin() {
return image!! return image!!
} }
val locale: String get() { val locale: String
val lang = preferenceStore.getString(localeKey) get() {
return if (lang.isNullOrBlank()) { val language = preferenceStore.getString(localeKey)
"zh" if (language.isNullOrBlank()) {
} else { val lang = Locale.getDefault().language
lang return if (lang != Locale.ENGLISH.language && lang != Locale.CHINESE.language) {
Locale.ENGLISH.language
} else Locale.getDefault().language
} }
return language
} }
fun toggleLocale() { fun toggleLocale() {
preferenceStore.setValue(localeKey, when (locale) { val lang = if (Locale.ENGLISH.language == locale) Locale.CHINESE.language else Locale.ENGLISH.language
"en" -> "zh" preferenceStore.setValue(localeKey, lang)
else -> "en"
})
} }
fun getRule(rule: String): Rule { fun getRule(rule: String): Rule {

@ -86,8 +86,12 @@ class MapOrSetKeyShouldOverrideHashCodeEqualsRule : AbstractEclipseRule() {
} }
private fun isOverrideEqualsAndHashCode(genericType: ITypeBinding): Boolean { private fun isOverrideEqualsAndHashCode(genericType: ITypeBinding): Boolean {
// skip enum val skip = genericType.isEnum || genericType.isInterface || genericType.isArray
if (genericType.isEnum || genericType.isInterface || genericType.isTypeVariable || genericType.isWildcardType) { || genericType.isTypeVariable || genericType.isWildcardType
|| genericType.qualifiedName?.startsWith(skipJdkPackageJava) ?: false
|| genericType.qualifiedName?.startsWith(skipJdkPackageJavax) ?: false
// skip
if (skip) {
return true return true
} }

@ -32,15 +32,12 @@ import com.intellij.openapi.project.DumbAware
* @date 2017/06/20 * @date 2017/06/20
*/ */
class SwitchLanguageAction : AnAction(), DumbAware { class SwitchLanguageAction : AnAction(), DumbAware {
val p3cConfig = P3cConfig::class.java.getService() private val p3cConfig = P3cConfig::class.java.getService()
val textKey = "com.alibaba.p3c.action.switch_language.text" private val textKey = "com.alibaba.p3c.action.switch_language.text"
override fun actionPerformed(e: AnActionEvent) { override fun actionPerformed(e: AnActionEvent) {
p3cConfig.locale = when (p3cConfig.locale) { p3cConfig.toggleLanguage()
P3cConfig.localeZh -> P3cConfig.localeEn
else -> P3cConfig.localeZh
}
BalloonNotifications.showSuccessNotification(P3cBundle.getMessage("$textKey.success"), e.project, BalloonNotifications.showSuccessNotification(P3cBundle.getMessage("$textKey.success"), e.project,
NotificationListener { notification, _ -> NotificationListener { notification, _ ->
notification.expire() notification.expire()

@ -20,6 +20,7 @@ import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage import com.intellij.openapi.components.Storage
import com.intellij.openapi.components.StoragePathMacros import com.intellij.openapi.components.StoragePathMacros
import com.intellij.util.xmlb.XmlSerializerUtil import com.intellij.util.xmlb.XmlSerializerUtil
import java.util.Locale
/** /**
* *
@ -27,8 +28,7 @@ import com.intellij.util.xmlb.XmlSerializerUtil
* @author caikang * @author caikang
* @date 2017/06/19 * @date 2017/06/19
*/ */
@State(name = "P3cConfig", @State(name = "P3cConfig", storages = arrayOf(Storage(file = "${StoragePathMacros.APP_CONFIG}/smartfox/p3c.xml")))
storages = arrayOf(Storage(file = "${StoragePathMacros.APP_CONFIG}/smartfox/p3c.xml")))
class P3cConfig : PersistentStateComponent<P3cConfig> { class P3cConfig : PersistentStateComponent<P3cConfig> {
var astCacheTime = 1000L var astCacheTime = 1000L
var astCacheEnable = true var astCacheEnable = true
@ -38,7 +38,21 @@ class P3cConfig : PersistentStateComponent<P3cConfig> {
var analysisBeforeCheckin = false var analysisBeforeCheckin = false
var locale = localeZh var locale: String = ""
get() {
if (field.isEmpty()) {
val lang = Locale.getDefault().language
return if (lang != Locale.ENGLISH.language && lang != Locale.CHINESE.language) {
Locale.ENGLISH.language
} else Locale.getDefault().language
}
return field
}
fun toggleLanguage() {
locale = if (localeEn == locale) localeZh else localeEn
}
override fun getState(): P3cConfig { override fun getState(): P3cConfig {
return this return this
@ -51,8 +65,9 @@ class P3cConfig : PersistentStateComponent<P3cConfig> {
XmlSerializerUtil.copyBean(state, this) XmlSerializerUtil.copyBean(state, this)
} }
companion object { companion object {
val localeEn = "en" val localeEn = Locale.ENGLISH.language!!
val localeZh = "zh" val localeZh = Locale.CHINESE.language!!
} }
} }

@ -29,7 +29,7 @@ import java.util.ResourceBundle
* @date 2017/06/20 * @date 2017/06/20
*/ */
object P3cBundle { object P3cBundle {
val p3cConfig = P3cConfig::class.java.getService() private val p3cConfig = P3cConfig::class.java.getService()
private val resourceBundle = ResourceBundle.getBundle("messages.P3cBundle", private val resourceBundle = ResourceBundle.getBundle("messages.P3cBundle",
Locale(p3cConfig.locale), I18nResources.XmlControl()) Locale(p3cConfig.locale), I18nResources.XmlControl())

@ -171,16 +171,20 @@ class MapOrSetKeyShouldOverrideHashCodeEqualsInspection : BaseInspection, AliBas
companion object { companion object {
private val skipJdkPackageJava = "java."
private val skipJdkPackageJavax = "javax."
private fun redefineHashCodeEquals(psiType: PsiType): Boolean { private fun redefineHashCodeEquals(psiType: PsiType): Boolean {
if (psiType !is PsiClassType) { if (psiType !is PsiClassType) {
return true return true
} }
val psiClass = psiType.resolve() val psiClass = psiType.resolve() ?: return false
if (psiClass == null || psiClass.containingFile == null || psiClass is PsiTypeParameter val skip = psiClass.containingFile == null || psiClass is PsiTypeParameter
|| psiClass.isEnum || psiClass.isInterface) { || psiClass.isEnum || psiClass.isInterface
return true || psiClass.containingFile.fileType !is JavaFileType
} || psiClass.qualifiedName?.startsWith(skipJdkPackageJava) ?: false
if (psiClass.containingFile.fileType !is JavaFileType) { || psiClass.qualifiedName?.startsWith(skipJdkPackageJavax) ?: false
if (skip) {
return true return true
} }
val hashCodeMethods = psiClass.findMethodsByName(ObjectConstants.METHOD_NAME_HASHCODE, false) val hashCodeMethods = psiClass.findMethodsByName(ObjectConstants.METHOD_NAME_HASHCODE, false)

@ -27,6 +27,7 @@ import com.intellij.psi.PsiFile
import com.intellij.psi.PsiIdentifier import com.intellij.psi.PsiIdentifier
import com.intellij.psi.PsiLocalVariable import com.intellij.psi.PsiLocalVariable
import com.intellij.psi.PsiMember import com.intellij.psi.PsiMember
import com.intellij.psi.PsiParameter
/** /**
* *
@ -48,7 +49,9 @@ interface AliQuickFix : LocalQuickFix {
fun doQuickFix(newIdentifier: String, project: Project, psiIdentifier: PsiIdentifier) { fun doQuickFix(newIdentifier: String, project: Project, psiIdentifier: PsiIdentifier) {
val offset = psiIdentifier.textOffset val offset = psiIdentifier.textOffset
if (psiIdentifier.parent !is PsiMember && psiIdentifier.parent !is PsiLocalVariable) { val cannotFix = psiIdentifier.parent !is PsiMember
&& !(psiIdentifier.parent is PsiLocalVariable || psiIdentifier.parent is PsiParameter)
if (cannotFix) {
return return
} }

Loading…
Cancel
Save