Skip to content

Commit

Permalink
better string formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Aug 15, 2024
1 parent 9b8ac2e commit b430981
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
9 changes: 2 additions & 7 deletions core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.ibm.wala.core.util.ref.CacheReference;
import com.ibm.wala.core.util.ref.ReferenceCleanser;
import com.ibm.wala.core.util.strings.Atom;
import com.ibm.wala.core.util.strings.StringStuff;
import com.ibm.wala.core.util.warnings.Warning;
import com.ibm.wala.core.util.warnings.Warnings;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
Expand Down Expand Up @@ -754,13 +755,7 @@ private void helperToJson(Node n, HashMap<String, Set<String>> hash) {
* Removed unnecessary part of Node by turning it into a String (Made for toJson and helperToJson)
*/
private String nodeToString(Node n) {
String key = n.getJavaClass().toString();
key = key.replace("<Primordial,", "");
key = key.replace("<Application,", "");
key = key.replace("<Extension,", "");
key = key.replace("<Synthetic,", "");
key = key.replace(">", "");
return key;
return StringStuff.jvmToBinaryName(n.getJavaClass().getName().toString());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.core.tests.util.TestConstants;
import com.ibm.wala.core.tests.util.WalaTestCase;
import com.ibm.wala.core.util.strings.StringStuff;
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
Expand Down Expand Up @@ -95,24 +96,21 @@ public void classHierarchyToJson() throws ClassHierarchyException, IOException {
ClassHierarchy cha = ClassHierarchyFactory.make(scope);
Gson gson = new Gson();
Type type = new TypeToken<HashMap<String, Set<String>>>() {}.getType();
HashMap<String, Set<String>> list = gson.fromJson(cha.toJson(), type);
assertTrue(list.containsKey(nodeToString(cha.getRootClass().toString())));
String json = cha.toJson();
System.err.println(json);
HashMap<String, Set<String>> list = gson.fromJson(json, type);
assertTrue(list.containsKey(nodeToString(cha.getRootClass())));

Set<String> subclassNames = new HashSet<>();
Iterator<IClass> children = cha.computeSubClasses(cha.getRootClass().getReference()).iterator();
while (children.hasNext()) {
String temp = nodeToString(children.next().toString());
String temp = nodeToString(children.next());
subclassNames.add(temp);
}
assertTrue(subclassNames.containsAll(list.get(nodeToString(cha.getRootClass().toString()))));
assertTrue(subclassNames.containsAll(list.get(nodeToString(cha.getRootClass()))));
}

private String nodeToString(String key) {
key = key.replace("<Primordial,", "");
key = key.replace("<Application,", "");
key = key.replace("<Extension,", "");
key = key.replace("<Synthetic,", "");
key = key.replace(">", "");
return key;
private String nodeToString(IClass klass) {
return StringStuff.jvmToBinaryName(klass.getName().toString());
}
}

0 comments on commit b430981

Please sign in to comment.