From d5150fe726cf9d94ab6d8ba65afc6d9b2ec70ea0 Mon Sep 17 00:00:00 2001 From: zhangdahai111 Date: Thu, 16 Dec 2021 15:24:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E9=9B=86=E5=90=88?= =?UTF-8?q?=E6=B3=9B=E5=9E=8B=E6=97=B6=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- .../constants/PluginConstants.java | 17 +++++- .../metersphere/exporter/PostmanExporter.java | 59 +++++++++++++++++-- src/main/resources/META-INF/plugin.xml | 1 + 4 files changed, 71 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index c79e304..de08ec4 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group 'org.intellij.sdk' -version '1.0.2' +version '1.0.3' sourceCompatibility = 11 repositories { diff --git a/src/main/java/org/metersphere/constants/PluginConstants.java b/src/main/java/org/metersphere/constants/PluginConstants.java index 29654e6..4201838 100644 --- a/src/main/java/org/metersphere/constants/PluginConstants.java +++ b/src/main/java/org/metersphere/constants/PluginConstants.java @@ -65,7 +65,22 @@ public class PluginConstants { put("Map", new JSONObject()); }}; - public enum MessageTitle { + public static final List javaBaseCollectionType = new ArrayList<>(){ { + add("java.util.List"); + add("java.util.ArrayList"); + add("java.util.LinkedList"); + add("java.util.Set"); + add("java.util.HashSet"); + add("java.util.HashTable"); + add("java.util.Queue"); + }}; + public static final List javaMapType = new ArrayList<>(){ { + add("java.util.Map"); + add("java.util.HashMap"); + add("java.util.LinkedHashMap"); + add("java.util.concurrent.ConcurrentHashMap"); + }}; + public enum MessageTitle { Info, Warning } } diff --git a/src/main/java/org/metersphere/exporter/PostmanExporter.java b/src/main/java/org/metersphere/exporter/PostmanExporter.java index 408280a..96df3ea 100644 --- a/src/main/java/org/metersphere/exporter/PostmanExporter.java +++ b/src/main/java/org/metersphere/exporter/PostmanExporter.java @@ -12,6 +12,7 @@ import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; +import com.intellij.psi.impl.source.PsiClassReferenceType; import com.intellij.psi.javadoc.PsiDocToken; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiTreeUtil; @@ -917,6 +918,16 @@ private void getRawMap(LinkedHashMap param, PsiParameter pe) { } } + private static final List collectionNames = new ArrayList<>() { + { + add("List"); + add("Set"); + add("Map"); + add("Queue"); + add("Vector"); + add("Stack"); + } + }; /** * 简单判断 后期优化多重嵌套结构 @@ -925,15 +936,33 @@ private void getRawMap(LinkedHashMap param, PsiParameter pe) { * @return */ private boolean isCollection(PsiField field) { - return field.getType().getCanonicalText().contains("<") && field.getType().getCanonicalText().contains(">") && !field.getType().getCanonicalText().contains("Map"); + for (String s : PluginConstants.javaBaseCollectionType) { + if (field.getType().getCanonicalText().startsWith(s)) { + return true; + } + } + + return false; } private boolean isCollection(PsiTypeElement field) { - return field.getType().getCanonicalText().contains("<") && field.getType().getCanonicalText().contains(">") && !field.getType().getCanonicalText().contains("Map"); + for (String s : PluginConstants.javaBaseCollectionType) { + if (field.getType().getCanonicalText().startsWith(s)) { + return true; + } + } + + return false; } private boolean isCollection(PsiParameter field) { - return field.getType().getCanonicalText().contains("<") && field.getType().getCanonicalText().contains(">") && !field.getType().getCanonicalText().contains("Map"); + for (String s : PluginConstants.javaBaseCollectionType) { + if (field.getType().getCanonicalText().startsWith(s)) { + return true; + } + } + + return false; } /** @@ -943,15 +972,33 @@ private boolean isCollection(PsiParameter field) { * @return */ private boolean isMap(PsiField field) { - return field.getType().getPresentableText().contains("Map"); + for (String s : PluginConstants.javaMapType) { + if (field.getType().getCanonicalText().startsWith(s)) { + return true; + } + } + + return false; } private boolean isMap(PsiTypeElement field) { - return field.getType().getPresentableText().contains("Map"); + for (String s : PluginConstants.javaMapType) { + if (field.getType().getCanonicalText().startsWith(s)) { + return true; + } + } + + return false; } private boolean isMap(PsiParameter field) { - return field.getType().getPresentableText().contains("Map"); + for (String s : PluginConstants.javaMapType) { + if (field.getType().getCanonicalText().startsWith(s)) { + return true; + } + } + + return false; } /** diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 01064d4..d5f3767 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -92,6 +92,7 @@
  • 1.0.0 support export Http api to MeterSphere.
  • 1.0.1 add context-path,xport-name,javadoc support.
  • 1.0.2 add response support. postman export,fix map jsonobject
  • +
  • 1.0.3 fix List format error
  • ]]> com.intellij.modules.platform