Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 2.6.9 #1116

Merged
merged 2 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions IDEA_CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
* 2.6.9
* fix: implement error handling in remoteConfigContent function [(#1115)](https://github.com/tangcent/easy-yapi/pull/1115)

* fix: resolve comment for custom enum field [(#1112)](https://github.com/tangcent/easy-yapi/pull/1112)

* fix: resolve configuration loading issue in several actions [(#1111)](https://github.com/tangcent/easy-yapi/pull/1111)

* feat: optimize configuration loading logic for enhanced efficiency and reliability [(#1107)](https://github.com/tangcent/easy-yapi/pull/1107)

* 2.6.8
* feat: Enhance support for enum fields in 'field' [(#1083)](https://github.com/tangcent/easy-yapi/pull/1083)

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugin_name=EasyYapi
plugin_version=2.6.8.212.0
plugin_version=2.6.9.212.0
kotlin.code.style=official
kotlin_version=1.8.0
junit_version=5.9.2
Expand Down
27 changes: 24 additions & 3 deletions idea-plugin/parts/pluginChanges.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
<a href="https://github.com/tangcent/easy-yapi/releases/tag/v2.6.8">v2.6.8(2023-11-26)</a><br>
<a href="https://github.com/tangcent/easy-yapi/releases/tag/v2.6.9">v2.6.9(2024-03-31)</a><br>
<a href="https://github.com/tangcent/easy-yapi/blob/master/IDEA_CHANGELOG.md">Full Changelog</a>

<br/>

<h3>enhancements:</h3>

<ul>
<li style="list-style: none">enhancements:</li>

<li>enhancements: feat: Enhance support for enum fields in 'field' (<a href="https://github.com/tangcent/easy-yapi/pull/1083">#1083</a>)</li>
<li>feat: optimize configuration loading logic for enhanced efficiency and reliability (<a
href="https://github.com/tangcent/easy-yapi/pull/1107">#1107</a>)
</li>
</ul>

<h3>fixes:</h3>

<ul>

<li>fix: implement error handling in remoteConfigContent function (<a
href="https://github.com/tangcent/easy-yapi/pull/1115">#1115</a>)
</li>

<li>fix: resolve comment for custom enum field (<a href="https://github.com/tangcent/easy-yapi/pull/1112">#1112</a>)
</li>

<li>fix: resolve configuration loading issue in several actions (<a
href="https://github.com/tangcent/easy-yapi/pull/1111">#1111</a>)
</li>
</ul>
26 changes: 15 additions & 11 deletions idea-plugin/parts/pluginDescription.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@ <h1>easy-yapi</h1>

<ul>
<li>Parse API documents based on javadoc & KDoc & ScalaDoc</li>
<li>Note that you can get a fairly complete API document in the case of zero intrusion of the code.</li>
<li>However, special requirements still need some special comments/annotations. Compared with this, you can use
flexible configuration rules to adapt to the characteristics of your project to minimize code intrusion.
<li>Note: It's possible to generate a comprehensive API document with minimal code modification.</li>
<li>However, specific requirements might necessitate additional comments/annotations.
To minimize code intrusion, you can employ flexible configuration rules tailored to your project's needs.
</li>
</ul>
<br/>
<b> Refer to <a href="[https://easyyapi.com ↗](https://easyyapi.com)">Guide</a> for details</b>
<b> For more details, refer to the <a href="[https://easyyapi.com ↗](https://easyyapi.com)">Guide</a></b>

<ul>Export API to Yapi/Postman/Markdown:
<p> Open the file containing <code>api</code> in the project or select the file or folder in the IDE's left project
file area, use the shortcut <kbd>Alt</kbd> <kbd>Shift</kbd> <kbd>E</kbd> (windows) / <kbd>Ctrl</kbd> <kbd>E</kbd> (mac), Then
select the API you want to export, select the export channel <code>Yapi/Markdown/Postman</code>, Click the [✔]
button or press Enter to complete the export.
<ul>How to Export API to Yapi/Postman/Markdown:
<p>
In your project, open the file containing the <code>API</code> or select the desired file or folder in the IDE's
left project file area.
</p>
<p>
Use the shortcut <kbd>Alt</kbd> <kbd>Shift</kbd> <kbd>E</kbd> (windows) / <kbd>Ctrl</kbd> <kbd>E</kbd> (mac).
Then, select the APIs you want to export, select the export channel <code>Yapi/Markdown/Postman</code>,
and click the [✔] button or press Enter to complete the export.
</p>
</ul>
<br/>
<p>
If the shortcut is invalid, please check for shortcut conflicts. You can modify the
shortcut in <kbd>Preferences(Settings)</kbd> > <kbd>KeyMap</kbd>.
<b>Note:</b> If the shortcut does not work, check for shortcut conflicts.
You can modify the shortcut in <kbd>Preferences(Settings)</kbd> > <kbd>KeyMap</kbd>.
</p>
<br/>
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import java.lang.reflect.Modifier
import java.util.*

/**
*1.Try infer the return type of method
*It should be called from the UI thread
* Handles inferring the return type of methods
* It should be executed within the UI thread.
*/
@Singleton
class DefaultMethodInferHelper : MethodInferHelper {
Expand Down Expand Up @@ -58,18 +58,26 @@ class DefaultMethodInferHelper : MethodInferHelper {
@Inject
protected lateinit var intelligentSettingsHelper: IntelligentSettingsHelper

//Cache for storing the results of static method invocations to avoid recomputation.
private val staticMethodCache: HashMap<Pair<PsiMethod, Array<Any?>?>, Any?> = HashMap()

//Tracks the current stack of method inferences to avoid infinite recursion.
private val methodStack: Stack<Infer> = Stack()

//JSON options for controlling the serialization behavior in the inference process.
private var jsonOption: Int = JsonOption.ALL

private var simpleJsonOption: Int = jsonOption and JsonOption.READ_GETTER.inv()

//Limits the depth of object graph exploration to prevent excessively deep or infinite recursion.
private var maxObjectDeep: Int = 4

//A cache for methods that do not require arguments to infer their return types.
private val emptyCallMethodCache: HashMap<PsiMethod, Any?> = HashMap()

/**
* Main methods for inferring the return type of a given PsiMethod.
*/
override fun inferReturn(psiMethod: PsiMethod, option: Int): Any? {
return emptyCallMethodCache.safeComputeIfAbsent(psiMethod) {
return@safeComputeIfAbsent inferReturn(psiMethod, null, null, option)
Expand Down Expand Up @@ -123,6 +131,9 @@ class DefaultMethodInferHelper : MethodInferHelper {
return DirectVariable { psiClassHelper!!.getTypeObject(psiMethod.returnType, psiMethod, jsonOption) }
}

/**
* Cleans up the inferred return values by removing invalid keys, based on predefined criteria.
*/
private fun Any?.cleanInvalidKeys(): Any? {
when (this) {
null -> return null
Expand Down Expand Up @@ -165,6 +176,10 @@ class DefaultMethodInferHelper : MethodInferHelper {

}

/**
* Computes a "point" score for an object based on its complexity and contents.
* This score helps in prioritizing more informative or complex inferred values.
*/
private fun pointOf(obj: Any?): Int {
when (obj) {
null -> return 0
Expand Down Expand Up @@ -207,7 +222,9 @@ class DefaultMethodInferHelper : MethodInferHelper {
}

/**
* Try a simple call
* Attempts a simple method call based on static analysis and predefined patterns,
* like getter/setter methods, to quickly infer the return type without deep analysis.
* e.g.
* static method
* getter/setter
* method of collection(Set/List/Map...)
Expand Down Expand Up @@ -306,6 +323,11 @@ class DefaultMethodInferHelper : MethodInferHelper {
return CALL_FAILED
}

/**
* Handles the inference process when the simple approach fails. This method
* performs a more detailed analysis, potentially involving recursive inference,
* to determine the method's return type.
*/
private fun inferReturnUnsafely(psiMethod: PsiMethod, caller: Any? = null, args: Array<Any?>?, option: Int): Any? {
actionContext!!.checkStatus()
val realCaller = valueOf(caller)
Expand All @@ -314,7 +336,7 @@ class DefaultMethodInferHelper : MethodInferHelper {
if (allowQuickCall(option)) {
try {
return tryInfer(QuicklyMethodReturnInfer(psiMethod, this))
} catch (e: Exception) {
} catch (_: Exception) {
}
}

Expand Down Expand Up @@ -526,11 +548,15 @@ class DefaultMethodInferHelper : MethodInferHelper {

const val DEFAULT_OPTION = ALLOW_QUICK_CALL

//Determines if a method allows for quick call-based inference.
fun allowQuickCall(option: Int): Boolean {
return (option and ALLOW_QUICK_CALL) != 0
}

//Static failure object used to signal that a method call cannot be inferred.
private val CALL_FAILED = Any()

//A set of method names considered for quick invocation without deep analysis.
private val COLLECTION_METHODS = setOf("put", "set", "add", "addAll", "putAll")

private fun isSuperMethod(method: PsiMethod, superMethod: PsiMethod): Boolean {
Expand Down Expand Up @@ -883,6 +909,11 @@ class DefaultMethodInferHelper : MethodInferHelper {
}
}

/*
* Defines the contract for inference strategies, allowing different approaches
* to be implemented and utilized based on the context and needs of the inference
* process.
*/
interface Infer {
fun infer(): Any?

Expand All @@ -891,6 +922,11 @@ class DefaultMethodInferHelper : MethodInferHelper {
fun callMethod(): Any?
}

/**
* Abstract implementation of an inference strategy, providing common functionality
* and utilities for handling method return inference. This includes managing local
* variables, processing PSI elements, and handling control flow constructs.
*/
abstract class AbstractMethodReturnInfer(
var caller: Any? = null,
val args: Array<Any?>?,
Expand All @@ -905,8 +941,6 @@ class DefaultMethodInferHelper : MethodInferHelper {

private var inits: HashSet<String> = HashSet()

// val psiClassHelper = ActionContext.getContext()!!.instance(PsiClassHelper::class)

protected open fun processStatement(statement: PsiStatement): Any? {

when (statement) {
Expand Down
2 changes: 1 addition & 1 deletion idea-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>com.itangcent.idea.plugin.easy-yapi</id>
<name>EasyYapi</name>
<version>2.6.8.212.0</version>
<version>2.6.9.212.0</version>
<vendor email="[email protected]" url="https://github.com/tangcent">Tangcent</vendor>

<description><![CDATA[ Description will be added by gradle build]]></description>
Expand Down
10 changes: 6 additions & 4 deletions plugin-script/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ commits=$(git log --pretty=format:"%s" v${last_version}..HEAD | sed 's/\(#\([0-9
echo "commits:${commits}"

# Separate commits into enhancements and fixes
enhancements=$(echo "${commits}" | grep -i "^feat" | sed 's/^/<li>enhancements: /;s/$/<\/li>/')
fixes=$(echo "${commits}" | grep -i "^fix" | sed 's/^/<li>fixes: /;s/$/<\/li>/')
enhancements=$(echo "${commits}" | grep -i "^feat" | sed 's/^/<li>/;s/$/<\/li>/')
fixes=$(echo "${commits}" | grep -i "^fix" | sed 's/^/<li>/;s/$/<\/li>/')
others=$(echo "${commits}" | grep -ivE "^feat|^fix" | sed 's/^/<li>/;s/$/<\/li>/')


Expand All @@ -49,14 +49,16 @@ echo "<a href=\"https://github.com/tangcent/easy-yapi/releases/tag/v${next_versi
echo "<br/>" >> ${basedir}/idea-plugin/parts/pluginChanges.html
echo "<a href=\"https://github.com/tangcent/easy-yapi/blob/master/IDEA_CHANGELOG.md\">Full Changelog</a>" >> ${basedir}/idea-plugin/parts/pluginChanges.html

echo "<h3>Enhancements:</h3>" >> ${basedir}/idea-plugin/parts/pluginChanges.html
# Write the list of enhancements to the pluginChanges.html file (if there are any)
if [ -n "${enhancements}" ]; then
echo "<ul>enhancements: ${enhancements}</ul>" >> ${basedir}/idea-plugin/parts/pluginChanges.html
echo "<ul>${enhancements}</ul>" >> ${basedir}/idea-plugin/parts/pluginChanges.html
fi

echo "<h3>Fixes:</h3>" >> ${basedir}/idea-plugin/parts/pluginChanges.html
# Append the list of fixes to the pluginChanges.html file (if there are any)
if [ -n "${fixes}" ]; then
echo "<ul>fixes: ${fixes}</ul>" >> ${basedir}/idea-plugin/parts/pluginChanges.html
echo "<ul>${fixes}</ul>" >> ${basedir}/idea-plugin/parts/pluginChanges.html
fi

# Append the list of other commits to the pluginChanges.html file (if there are any)
Expand Down
Loading