Skip to content

Commit

Permalink
Merge pull request #27 from IzaiahSun/main
Browse files Browse the repository at this point in the history
Fix hashmap overwrite when generate json file.
  • Loading branch information
Lynn-Dai authored Jun 16, 2022
2 parents 514471b + 42a2795 commit 43b8088
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
.idea
8 changes: 5 additions & 3 deletions src/main/java/TempOutput/DependsString.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import entity.properties.Relation;
import util.Configure;
import util.SingleCollect;
import util.Tuple;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -277,7 +278,7 @@ public DependsString getDependsString(String projectName, String projectPath, St
dependsString.nodeNum = dependsString.variables.size();

JsonMap jsonMap = new JsonMap();
Map<Integer, Map<Integer, Relation>> relationMap = jsonMap.getFinalRes();
Map<Integer, ArrayList<Tuple<Integer, Relation>>> relationMap = jsonMap.getFinalRes();
for(int fromEntity:relationMap.keySet()) {
if (singleCollect.getEntityById(fromEntity) instanceof PackageEntity){
continue;
Expand All @@ -289,7 +290,8 @@ public DependsString getDependsString(String projectName, String projectPath, St
catch (IndexOutOfBoundsException e){
continue;
}
for (int toEntity : relationMap.get(fromEntity).keySet()) {
for (Tuple<Integer,Relation> toEntityObj : relationMap.get(fromEntity)) {
int toEntity=toEntityObj.getL();
if (singleCollect.getEntityById(toEntity) instanceof PackageEntity){
continue;
}
Expand All @@ -314,7 +316,7 @@ public DependsString getDependsString(String projectName, String projectPath, St

if (currentCell != null){
// for (String type : relationMap.get(fromEntity).get(toEntity)) {
Relation type = relationMap.get(fromEntity).get(toEntity);
Relation type = toEntityObj.getR();
DetailDTO detail = new DetailDTO(fromEntity, toEntity, type.getKind(), 0, 0);
currentCell.addValue(type.getKind());
currentCell.details.add(detail);
Expand Down
74 changes: 10 additions & 64 deletions src/main/java/TempOutput/JsonMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,82 +7,28 @@
import util.SingleCollect;
import util.Tuple;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class JsonMap {

protected SingleCollect singleCollect = SingleCollect.getSingleCollectInstance();
private Map<Integer, Map<Integer, Relation>> finalRes = new HashMap<Integer, Map<Integer, Relation>>();
private Map<Integer, ArrayList<Tuple<Integer, Relation>>> finalRes = new HashMap<>();

public Map<Integer, Map<Integer, Relation>> getFinalRes (){
public Map<Integer, ArrayList<Tuple<Integer, Relation>>> getFinalRes (){
for(BaseEntity entity :singleCollect.getEntities()){
for(Relation relation : entity.getRelation()){
switch (relation.getKind()){
case Configure.RELATION_IMPORT:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_IMPORT));
break;
case Configure.RELATION_INHERIT:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_INHERIT));
break;
case Configure.RELATION_PARAMETER:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_PARAMETER));
break;
case Configure.RELATION_CALL:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_CALL));
break;
case Configure.RELATION_CALL_NON_DYNAMIC:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_CALL_NON_DYNAMIC));
// finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_CALL));
break;
case Configure.RELATION_IMPLEMENT:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_IMPLEMENT));
break;
case Configure.RELATION_SET:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_SET));
break;
case Configure.RELATION_USE:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_USE));
break;
case Configure.RELATION_MODIFY:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_MODIFY));
break;
case Configure.RELATION_CAST:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_CAST));
break;
case Configure.RELATION_ANNOTATE:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_ANNOTATE));
break;
case Configure.RELATION_CONTAIN:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_CONTAIN));
break;
case Configure.RELATION_DEFINE:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_DEFINE));
break;
case Configure.RELATION_OVERRIDE:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_OVERRIDE));
break;
case Configure.RELATION_REFLECT:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation,Configure.RELATION_REFLECT));
break;
case Configure.RELATION_TYPED:
finalRes.put(entity.getId(),supplementRes(entity.getId(), relation, Configure.RELATION_TYPED));
}
}
}
return finalRes;
}

private Map<Integer, Relation> supplementRes(int entityId, Relation relation, String type){
if(!finalRes.containsKey(entity.getId())){
finalRes.put(entity.getId(),new ArrayList<>());
}
finalRes.get(entity.getId()).add(new Tuple<Integer, Relation>(relation.getToEntity(),relation));

Map<Integer, Relation> dest = new HashMap<>();
if(finalRes.containsKey(entityId)){
dest = finalRes.get(entityId);
}
relation.setKind(type);
dest.put(relation.getToEntity(),relation);

return dest;
}
}
return finalRes;
}


Expand Down
9 changes: 6 additions & 3 deletions src/main/java/TempOutput/JsonString.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.json.JSONObject;

import util.SingleCollect;
import util.Tuple;
import visitor.relationInf.RelationInf;

public class JsonString {
Expand Down Expand Up @@ -39,7 +40,7 @@ else if (singleCollect.getEntityById(singleCollect.getEntityById(id).getParentId
}
}

public static String JSONWriteRelation(Map<Integer, Map<Integer, Relation>> relationMap, String hiddenPath) throws Exception {
public static String JSONWriteRelation(Map<Integer, ArrayList<Tuple<Integer, Relation>>> relationMap, String hiddenPath) throws Exception {

JSONObject obj=new JSONObject();//创建JSONObject对象

Expand Down Expand Up @@ -186,9 +187,11 @@ public static String JSONWriteRelation(Map<Integer, Map<Integer, Relation>> rela


for(int fromEntity:relationMap.keySet()) {
for(int toEntity:relationMap.get(fromEntity).keySet()) {
for(Tuple<Integer,Relation> toEntityObj:relationMap.get(fromEntity)) {
int toEntity=toEntityObj.getL();

// for(Relation type : relationMap.get(fromEntity).get(toEntity)) {
Relation type = relationMap.get(fromEntity).get(toEntity);
Relation type = toEntityObj.getR();
JSONObject subObj=new JSONObject();//创建对象数组里的子对象

// JSONObject srcObj = new JSONObject();
Expand Down

0 comments on commit 43b8088

Please sign in to comment.