Skip to content

Commit

Permalink
fix: 解决集合泛型时报错
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangdahai112 committed Dec 16, 2021
1 parent f96f6a3 commit d5150fe
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group 'org.intellij.sdk'
version '1.0.2'
version '1.0.3'

sourceCompatibility = 11
repositories {
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/org/metersphere/constants/PluginConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,22 @@ public class PluginConstants {
put("Map", new JSONObject());
}};

public enum MessageTitle {
public static final List<String> 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<String> 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
}
}
59 changes: 53 additions & 6 deletions src/main/java/org/metersphere/exporter/PostmanExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -917,6 +918,16 @@ private void getRawMap(LinkedHashMap param, PsiParameter pe) {
}
}

private static final List<String> collectionNames = new ArrayList<>() {
{
add("List");
add("Set");
add("Map");
add("Queue");
add("Vector");
add("Stack");
}
};

/**
* 简单判断 后期优化多重嵌套结构
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<li><b>1.0.0</b> support export Http api to MeterSphere.</li>
<li><b>1.0.1</b> add context-path,xport-name,javadoc support.</li>
<li><b>1.0.2</b> add response support. postman export,fix map jsonobject</li>
<li><b>1.0.3</b> fix List<Map> format error</li>
</ul>]]></change-notes>

<depends>com.intellij.modules.platform</depends>
Expand Down

0 comments on commit d5150fe

Please sign in to comment.