-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from godfather1103/dev
issues/4
- Loading branch information
Showing
23 changed files
with
651 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...lugin/p3c-common/src/main/java/io/github/godfather1103/settings/AppSettingsComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
|
||
package io.github.godfather1103.settings; | ||
|
||
import com.intellij.ui.components.JBLabel; | ||
import com.intellij.ui.components.JBTextArea; | ||
import com.intellij.util.ui.FormBuilder; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.*; | ||
import javax.swing.border.Border; | ||
import java.awt.*; | ||
|
||
/** | ||
* <p>Title: Godfather1103's Github</p> | ||
* <p>Copyright: Copyright (c) 2023</p> | ||
* <p>Company: https://github.com/godfather1103</p> | ||
* | ||
* @author 作者: Jack Chu E-mail: [email protected] | ||
* @version 1.0 | ||
* @date 创建时间:2023/8/22 09:43 | ||
* @since 1.0 | ||
*/ | ||
public class AppSettingsComponent { | ||
|
||
private final JPanel myMainPanel; | ||
|
||
private final JBTextArea inData = new JBTextArea(20, 20); | ||
|
||
public AppSettingsComponent() { | ||
Border border = BorderFactory.createLineBorder(Color.BLACK); | ||
inData.setBorder(BorderFactory.createCompoundBorder(border, BorderFactory.createEmptyBorder(5, 5, 5, 5))); | ||
myMainPanel = FormBuilder.createFormBuilder() | ||
.addComponent(new JBLabel("custom namelist.properties"), 1) | ||
.addComponent(inData, 1) | ||
.addComponentFillVertically(new JPanel(), 0) | ||
.getPanel(); | ||
} | ||
|
||
public JBTextArea getInData() { | ||
return inData; | ||
} | ||
|
||
public JPanel getPanel() { | ||
return myMainPanel; | ||
} | ||
|
||
public void setInDataText(@NotNull String text) { | ||
inData.setText(text); | ||
} | ||
|
||
public String getInDataText() { | ||
return inData.getText(); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...in/p3c-common/src/main/java/io/github/godfather1103/settings/AppSettingsConfigurable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
package io.github.godfather1103.settings; | ||
|
||
import com.alibaba.p3c.idea.config.P3cConfig; | ||
import com.alibaba.p3c.pmd.lang.java.util.namelist.NameListConfig; | ||
import com.intellij.openapi.options.Configurable; | ||
import io.github.godfather1103.service.BaseNameListServiceExt; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
|
||
/** | ||
* <p>Title: Godfather1103's Github</p> | ||
* <p>Copyright: Copyright (c) 2023</p> | ||
* <p>Company: https://github.com/godfather1103</p> | ||
* | ||
* @author 作者: Jack Chu E-mail: [email protected] | ||
* @version 1.0 | ||
* @date 创建时间:2023/8/22 09:44 | ||
* @since 1.0 | ||
*/ | ||
public class AppSettingsConfigurable implements Configurable { | ||
|
||
private AppSettingsComponent mySettingsComponent; | ||
|
||
@Nls(capitalization = Nls.Capitalization.Title) | ||
@Override | ||
public String getDisplayName() { | ||
return "P3C Configure"; | ||
} | ||
|
||
@Override | ||
public JComponent getPreferredFocusedComponent() { | ||
return mySettingsComponent.getInData(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public JComponent createComponent() { | ||
mySettingsComponent = new AppSettingsComponent(); | ||
return mySettingsComponent.getPanel(); | ||
} | ||
|
||
@Override | ||
public boolean isModified() { | ||
return !P3cConfig.getInstance() | ||
.getCustomNamelistProperties() | ||
.equals(mySettingsComponent.getInDataText()); | ||
} | ||
|
||
@Override | ||
public void apply() { | ||
var inData = mySettingsComponent.getInDataText(); | ||
P3cConfig.getInstance() | ||
.setCustomNamelistProperties(inData); | ||
var service = NameListConfig.NAME_LIST_SERVICE; | ||
if (service instanceof BaseNameListServiceExt) { | ||
BaseNameListServiceExt base = ((BaseNameListServiceExt) service); | ||
if (!base.getOldData().equals(inData)) { | ||
base.resetData(inData, true); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
mySettingsComponent | ||
.setInDataText(P3cConfig.getInstance().getCustomNamelistProperties()); | ||
} | ||
|
||
@Override | ||
public void disposeUIResources() { | ||
mySettingsComponent = null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
idea-plugin/p3c-common/src/main/kotlin/io/github/godfather1103/rule/IModifyRuleValue.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.github.godfather1103.rule | ||
|
||
import io.github.godfather1103.service.BaseNameListServiceExt | ||
|
||
interface IModifyRuleValue { | ||
|
||
fun className(): String { | ||
return javaClass.simpleName | ||
} | ||
|
||
fun needModifyOnInit(): Boolean = false | ||
|
||
fun modifyValue(base: BaseNameListServiceExt, key: String) | ||
} |
47 changes: 47 additions & 0 deletions
47
...n/src/main/kotlin/io/github/godfather1103/rule/ext/LowerCamelCaseVariableNamingRuleExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.github.godfather1103.rule.ext | ||
|
||
import com.alibaba.p3c.pmd.lang.java.rule.AbstractAliRule | ||
import com.alibaba.p3c.pmd.lang.java.rule.naming.LowerCamelCaseVariableNamingRule | ||
import net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration | ||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator | ||
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId | ||
import java.util.regex.Pattern | ||
|
||
/** | ||
* <p>Title: Godfather1103's Github</p> | ||
* <p>Copyright: Copyright (c) 2023</p> | ||
* <p>Company: https://github.com/godfather1103</p> | ||
* | ||
* @author 作者: Jack Chu E-mail: [email protected] | ||
* @date 创建时间:2023/8/23 13:57 | ||
* @version 1.0 | ||
* @since 1.0 | ||
*/ | ||
class LowerCamelCaseVariableNamingRuleExt : AbstractAliRule() { | ||
|
||
val rule by lazy { LowerCamelCaseVariableNamingRule() } | ||
|
||
override fun visit(node: ASTVariableDeclaratorId, data: Any?): Any? { | ||
if (!(pattern.matcher(node.image)).matches()) { | ||
return rule.visit(node, data) | ||
} | ||
return super.visit(node, data) | ||
} | ||
|
||
override fun visit(node: ASTMethodDeclarator, data: Any?): Any? { | ||
if (!(pattern.matcher(node.image)).matches()) { | ||
return rule.visit(node, data) | ||
} | ||
return super.visit(node, data) | ||
} | ||
|
||
override fun visit(node: ASTAnnotationTypeDeclaration, data: Any?): Any? { | ||
return null | ||
} | ||
|
||
companion object { | ||
var pattern: Pattern = | ||
Pattern.compile("^[a-z][a-z0-9]*([A-Z][a-z0-9]+)*(DO|DTO|VO|DAO|BO|DOList|DTOList|VOList|DAOList|BOList|X|Y|Z|UDF|UDAF|[A-Z])?$") | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...-common/src/main/kotlin/io/github/godfather1103/rule/impl/ClassNamingShouldBeCamelRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.godfather1103.rule.impl | ||
|
||
import io.github.godfather1103.rule.IModifyRuleValue | ||
import io.github.godfather1103.service.BaseNameListServiceExt | ||
|
||
/** | ||
* <p>Title: Godfather1103's Github</p> | ||
* <p>Copyright: Copyright (c) 2023</p> | ||
* <p>Company: https://github.com/godfather1103</p> | ||
* | ||
* @author 作者: Jack Chu E-mail: [email protected]<BR> | ||
* 创建时间:2023-08-22 22:58 | ||
* @version 1.0 | ||
* @since 1.0 | ||
*/ | ||
class ClassNamingShouldBeCamelRule : IModifyRuleValue { | ||
override fun modifyValue(base: BaseNameListServiceExt, key: String) { | ||
when (key) { | ||
"CLASS_NAMING_WHITE_LIST" -> | ||
com.alibaba.p3c.pmd.lang.java.rule.naming.ClassNamingShouldBeCamelRule::class.java | ||
.declaredFields.find { it.name == key }?.apply { | ||
isAccessible = true | ||
val set = get(null) as MutableList<String> | ||
set.clear() | ||
base.getNameList(className(), key) | ||
.forEach { set.add(it) } | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...c/main/kotlin/io/github/godfather1103/rule/impl/CollectionInitShouldAssignCapacityRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.godfather1103.rule.impl | ||
|
||
import io.github.godfather1103.rule.IModifyRuleValue | ||
import io.github.godfather1103.service.BaseNameListServiceExt | ||
|
||
/** | ||
* <p>Title: Godfather1103's Github</p> | ||
* <p>Copyright: Copyright (c) 2023</p> | ||
* <p>Company: https://github.com/godfather1103</p> | ||
* | ||
* @author 作者: Jack Chu E-mail: [email protected]<BR> | ||
* 创建时间:2023-08-22 22:58 | ||
* @version 1.0 | ||
* @since 1.0 | ||
*/ | ||
class CollectionInitShouldAssignCapacityRule : IModifyRuleValue { | ||
override fun modifyValue(base: BaseNameListServiceExt, key: String) { | ||
when (key) { | ||
"COLLECTION_TYPE" -> | ||
com.alibaba.p3c.pmd.lang.java.rule.set.CollectionInitShouldAssignCapacityRule::class.java | ||
.declaredFields.find { it.name == "COLLECTION_LIST" }?.apply { | ||
isAccessible = true | ||
val set = get(null) as MutableList<String> | ||
set.clear() | ||
base.getNameList(className(), key) | ||
.forEach { set.add(it) } | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...n/src/main/kotlin/io/github/godfather1103/rule/impl/ConstantFieldShouldBeUpperCaseRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.godfather1103.rule.impl | ||
|
||
import io.github.godfather1103.rule.IModifyRuleValue | ||
import io.github.godfather1103.service.BaseNameListServiceExt | ||
|
||
/** | ||
* <p>Title: Godfather1103's Github</p> | ||
* <p>Copyright: Copyright (c) 2023</p> | ||
* <p>Company: https://github.com/godfather1103</p> | ||
* | ||
* @author 作者: Jack Chu E-mail: [email protected] | ||
* @date 创建时间:2023/8/22 19:00 | ||
* @version 1.0 | ||
* @since 1.0 | ||
*/ | ||
class ConstantFieldShouldBeUpperCaseRule : IModifyRuleValue { | ||
override fun modifyValue(base: BaseNameListServiceExt, key: String) { | ||
when (key) { | ||
"LOG_VARIABLE_TYPE_SET", "WHITE_LIST" -> | ||
com.alibaba.p3c.pmd.lang.java.rule.naming.ConstantFieldShouldBeUpperCaseRule::class.java | ||
.declaredFields.find { it.name == key }?.apply { | ||
isAccessible = true | ||
val set = get(null) as HashSet<String> | ||
set.clear() | ||
base.getNameList(className(), key) | ||
.forEach { set.add(it) } | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.