From 1187f335b04178ded3e16808cf3be3a81bd5a979 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Sun, 19 Nov 2023 17:14:34 -0800 Subject: [PATCH 01/40] added toJson function to AnalysisScope --- build.gradle.kts | 1 + cast/.settings/org.eclipse.jdt.core.prefs | 1 + .../java/.settings/org.eclipse.jdt.core.prefs | 1 + .../ecj/.settings/org.eclipse.jdt.core.prefs | 1 + .../data/.settings/org.eclipse.jdt.core.prefs | 1 + cast/js/.settings/org.eclipse.jdt.core.prefs | 1 + .../.settings/org.eclipse.jdt.core.prefs | 1 + .../.settings/org.eclipse.jdt.core.prefs | 1 + .../.settings/org.eclipse.jdt.core.prefs | 1 + core/.settings/org.eclipse.jdt.core.prefs | 2 +- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 19 +++++++++++++++++++ dalvik/.settings/org.eclipse.jdt.core.prefs | 2 +- ide/.settings/org.eclipse.jdt.core.prefs | 1 + ide/jdt/.settings/org.eclipse.jdt.core.prefs | 1 + .../test/.settings/org.eclipse.jdt.core.prefs | 1 + ide/jsdt/.settings/org.eclipse.jdt.core.prefs | 1 + .../.settings/org.eclipse.jdt.core.prefs | 1 + .../.settings/org.eclipse.jdt.core.prefs | 1 + .../.settings/org.eclipse.jdt.core.prefs | 1 + shrike/.settings/org.eclipse.jdt.core.prefs | 2 +- util/.settings/org.eclipse.jdt.core.prefs | 1 + 21 files changed, 39 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b789944d2c..b45d1dd908 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -63,6 +63,7 @@ val aggregatedJavadocClasspath: Configuration by configurations.creating { isCan val aggregatedJavadocSource: Configuration by configurations.creating { isCanBeConsumed = false } dependencies { + implementation 'com.google.code.gson:gson:2.8.6' subprojects { pluginManager.withPlugin("java-base") { aggregatedJavadocClasspath( diff --git a/cast/.settings/org.eclipse.jdt.core.prefs b/cast/.settings/org.eclipse.jdt.core.prefs index bf53eca489..46dc8478d7 100644 --- a/cast/.settings/org.eclipse.jdt.core.prefs +++ b/cast/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/java/.settings/org.eclipse.jdt.core.prefs b/cast/java/.settings/org.eclipse.jdt.core.prefs index 8f8e931c63..cb7184c292 100644 --- a/cast/java/.settings/org.eclipse.jdt.core.prefs +++ b/cast/java/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs b/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs index 5c12c8d1b0..bcfd2a8da2 100644 --- a/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs +++ b/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs b/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs index cf946c8de5..40411da3de 100644 --- a/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs +++ b/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/.settings/org.eclipse.jdt.core.prefs b/cast/js/.settings/org.eclipse.jdt.core.prefs index 463e28aa37..76347aee04 100644 --- a/cast/js/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs b/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs index 2b9d39c4ea..4f191ef2ac 100644 --- a/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs b/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs index 3ad950dfca..9833c75b73 100644 --- a/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs b/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs index 760d320e82..0d62206c7c 100644 --- a/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/core/.settings/org.eclipse.jdt.core.prefs b/core/.settings/org.eclipse.jdt.core.prefs index 9b009e559e..d7762182a3 100644 --- a/core/.settings/org.eclipse.jdt.core.prefs +++ b/core/.settings/org.eclipse.jdt.core.prefs @@ -8,7 +8,7 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=,*.g org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 5a36b459f2..b4be269d7f 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -55,6 +55,8 @@ import java.util.jar.JarFile; import java.util.jar.Manifest; +import com.google.gson.Gson; + /** * Base class that represents a set of files to analyze. * @@ -345,6 +347,23 @@ public String toString() { return result.toString(); } + public String toJson() { + StringBuilder result = new StringBuilder(); + for (ClassLoaderReference loader : loadersByName.values()) { + result.append(loader.getName()); + result.append('\n'); + for (Module m : getModules(loader)) { + result.append(' '); + result.append(m); + result.append('\n'); + } + } + result.append(getExclusionString()); + result.append('\n'); + Gson gson = new Gson(); + return gson.toJson(result.toString()); + } + /** * @return a String that describes exclusions from the analysis scope. */ diff --git a/dalvik/.settings/org.eclipse.jdt.core.prefs b/dalvik/.settings/org.eclipse.jdt.core.prefs index fff9860cf0..b136978268 100644 --- a/dalvik/.settings/org.eclipse.jdt.core.prefs +++ b/dalvik/.settings/org.eclipse.jdt.core.prefs @@ -7,7 +7,7 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=,*.g org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/.settings/org.eclipse.jdt.core.prefs b/ide/.settings/org.eclipse.jdt.core.prefs index cd676248fe..1d033d1fa9 100644 --- a/ide/.settings/org.eclipse.jdt.core.prefs +++ b/ide/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jdt/.settings/org.eclipse.jdt.core.prefs b/ide/jdt/.settings/org.eclipse.jdt.core.prefs index 55d5744105..2939d58ea7 100644 --- a/ide/jdt/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jdt/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs b/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs index 0d9a8a083e..861143ac53 100644 --- a/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jsdt/.settings/org.eclipse.jdt.core.prefs b/ide/jsdt/.settings/org.eclipse.jdt.core.prefs index 1e908e2c71..2cbe9c1cdb 100644 --- a/ide/jsdt/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jsdt/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs b/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs index fa9ef42774..c7caafc691 100644 --- a/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/tests/.settings/org.eclipse.jdt.core.prefs b/ide/tests/.settings/org.eclipse.jdt.core.prefs index b9a5f6959b..a78ffab6a0 100644 --- a/ide/tests/.settings/org.eclipse.jdt.core.prefs +++ b/ide/tests/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/scandroid/.settings/org.eclipse.jdt.core.prefs b/scandroid/.settings/org.eclipse.jdt.core.prefs index c9942e9779..c225f50aa8 100644 --- a/scandroid/.settings/org.eclipse.jdt.core.prefs +++ b/scandroid/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/shrike/.settings/org.eclipse.jdt.core.prefs b/shrike/.settings/org.eclipse.jdt.core.prefs index 3150e13e55..74e011e600 100644 --- a/shrike/.settings/org.eclipse.jdt.core.prefs +++ b/shrike/.settings/org.eclipse.jdt.core.prefs @@ -8,7 +8,7 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=,*.g org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/util/.settings/org.eclipse.jdt.core.prefs b/util/.settings/org.eclipse.jdt.core.prefs index 1ae6eb0923..352ce4e43c 100644 --- a/util/.settings/org.eclipse.jdt.core.prefs +++ b/util/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull From 3a90899aa53b0c2bef40fd110b0392b35691c962 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Mon, 27 Nov 2023 19:47:50 -0800 Subject: [PATCH 02/40] added one successful test for toJson in Analysis Scope --- build.gradle.kts | 1 - core/build.gradle.kts | 1 + .../ibm/wala/ipa/callgraph/AnalysisScope.java | 4 +++- .../wala/core/tests/callGraph/CallGraphTest.java | 2 +- .../wala/core/tests/cha/AnalysisScopeTest.java | 16 ++++++++++++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 14 +++++++------- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b45d1dd908..b789944d2c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -63,7 +63,6 @@ val aggregatedJavadocClasspath: Configuration by configurations.creating { isCan val aggregatedJavadocSource: Configuration by configurations.creating { isCanBeConsumed = false } dependencies { - implementation 'com.google.code.gson:gson:2.8.6' subprojects { pluginManager.withPlugin("java-base") { aggregatedJavadocClasspath( diff --git a/core/build.gradle.kts b/core/build.gradle.kts index f032777f5c..4b66b1fb91 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -61,6 +61,7 @@ dependencies { api(projects.util) { because("public interface CallGraph extends interface NumberedGraph") } testFixturesImplementation(libs.ant) testFixturesImplementation(libs.junit.platform.launcher) + implementation(libs.gson) testImplementation(libs.assertj.core) testImplementation(libs.hamcrest) testRuntimeOnly(sourceSets["testSubjects"].output.classesDirs) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index b4be269d7f..95ae0d1ba5 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -54,9 +54,11 @@ import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; - import com.google.gson.Gson; + +// import com.google.gson.Gson; + /** * Base class that represents a set of files to analyze. * diff --git a/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java b/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java index a20853c202..9dcf85eb39 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java @@ -302,7 +302,7 @@ public void testPrimordial() if (useShortProfile()) { return; } - + AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope( "primordial.txt", diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 151b32dc4f..d8d0402e6b 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -1,5 +1,6 @@ package com.ibm.wala.core.tests.cha; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -18,8 +19,23 @@ import java.nio.file.Paths; import org.junit.jupiter.api.Test; +import com.google.gson.Gson; + public class AnalysisScopeTest { + @Test + public void toJsonTest() throws IOException { + AnalysisScope scope = + AnalysisScopeReader.instance.readJavaScope( + TestConstants.WALA_TESTDATA, + new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), + AnalysisScopeTest.class.getClassLoader()); + Gson gson = new Gson(); + String exp = gson.toJson(scope.toString()); + System.out.println(scope.toString()); + assertEquals(exp, scope.toJson()); + } + @Test public void testJarInputStream() throws IOException, ClassHierarchyException { AnalysisScope scope = diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 01f330a93e..41b59bedc4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionSha256Sum=f2b9ed0faf8472cbe469255ae6c86eddb77076c75191741b4a462f33128dd419 -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 0adc8e1a53..1aa94a4269 100755 --- a/gradlew +++ b/gradlew @@ -145,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -153,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -202,11 +202,11 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ From 6c815292fcb232c0413465cebbce735d95ffb9cb Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Mon, 4 Dec 2023 17:17:36 -0800 Subject: [PATCH 03/40] added json capability --- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 8 +++++ .../core/tests/cha/AnalysisScopeTest.java | 6 ++-- z-out.java | 35 +++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 z-out.java diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 95ae0d1ba5..82750572bb 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -351,18 +351,26 @@ public String toString() { public String toJson() { StringBuilder result = new StringBuilder(); + HashMap> hashMap = new HashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { + ArrayList arr = new ArrayList<>(); result.append(loader.getName()); result.append('\n'); for (Module m : getModules(loader)) { + arr.add(m.toString()); result.append(' '); result.append(m); result.append('\n'); } + hashMap.put(loader.getName().toString(), arr); } result.append(getExclusionString()); result.append('\n'); Gson gson = new Gson(); + // ArrayList arr2 = new ArrayList<>(); + // arr2.add(getJavaLibraryVersion()); + // hashMap.put(getExclusionString().toString(), arr2); + System.out.println(gson.toJson(hashMap)); return gson.toJson(result.toString()); } diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index d8d0402e6b..b48d0be7b1 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -28,11 +28,11 @@ public void toJsonTest() throws IOException { AnalysisScope scope = AnalysisScopeReader.instance.readJavaScope( TestConstants.WALA_TESTDATA, - new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), + // new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), + new FileProvider().getFile("/Users/aakgna/Documents/WALA-Research/WALA/core/src/test/java/com/ibm/wala/core/tests/cha/CodeDeletedTest.java"), AnalysisScopeTest.class.getClassLoader()); Gson gson = new Gson(); - String exp = gson.toJson(scope.toString()); - System.out.println(scope.toString()); + String exp = gson.toJson("scope.toString()"); assertEquals(exp, scope.toJson()); } diff --git a/z-out.java b/z-out.java new file mode 100644 index 0000000000..f4f67996fb --- /dev/null +++ b/z-out.java @@ -0,0 +1,35 @@ +// Example Code + +public class example { + public String convert_to_json(T dataStructure) throws IOException { + Gson gson = new Gson(); + System.out.println("gson"); + String json_format = gson.toJson(dataStructure); + FileWriter writer = new FileWriter("output2.json"); + writer.write(json_format); + writer.close(); + return json_format; + } + public String main() { + String out = convert_to_json("null"); + return out; + } + +} + +// example output + +{ + { + "Class_Name": "example", + "Functions": ["convert_to_json", "main"] + }, + { + "Class_Name": "convert_to_json", + "Functions": ["Gson", "toJson", "FileWriter", "write", "close"] + }, + { + "Class_Name": "main", + "Functions": ["convert_to_json"] + } +} From 163aa8e1272c42daa6e461cb947a1179c070dc0b Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Fri, 22 Dec 2023 23:07:28 -0800 Subject: [PATCH 04/40] implemented toJson functionality --- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 82750572bb..0e34e2e52f 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -51,6 +51,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.HashSet; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; @@ -351,26 +352,24 @@ public String toString() { public String toJson() { StringBuilder result = new StringBuilder(); + Set track = new HashSet<>(); HashMap> hashMap = new HashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { ArrayList arr = new ArrayList<>(); - result.append(loader.getName()); - result.append('\n'); for (Module m : getModules(loader)) { arr.add(m.toString()); - result.append(' '); - result.append(m); - result.append('\n'); } + if(!track.contains("Exclusions")) { + track.add("Exclusions"); + String newStr = getExclusionString().toString().substring(12); + ArrayList arr2 = new ArrayList<>(); + arr2.add(newStr); + hashMap.put("Exclusions", arr2); + } + track.add(loader.getName().toString()); hashMap.put(loader.getName().toString(), arr); } - result.append(getExclusionString()); - result.append('\n'); Gson gson = new Gson(); - // ArrayList arr2 = new ArrayList<>(); - // arr2.add(getJavaLibraryVersion()); - // hashMap.put(getExclusionString().toString(), arr2); - System.out.println(gson.toJson(hashMap)); return gson.toJson(result.toString()); } From 6f69ce9e0054e1a63263147a030fee54d0b9a159 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Fri, 22 Dec 2023 23:22:52 -0800 Subject: [PATCH 05/40] returned right value --- .../main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java | 4 ++-- .../java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 0e34e2e52f..d052515495 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -351,7 +351,7 @@ public String toString() { } public String toJson() { - StringBuilder result = new StringBuilder(); + // StringBuilder result = new StringBuilder(); Set track = new HashSet<>(); HashMap> hashMap = new HashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { @@ -370,7 +370,7 @@ public String toJson() { hashMap.put(loader.getName().toString(), arr); } Gson gson = new Gson(); - return gson.toJson(result.toString()); + return gson.toJson(hashMap); } /** diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index b48d0be7b1..9b95c0ffa4 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -29,10 +29,11 @@ public void toJsonTest() throws IOException { AnalysisScopeReader.instance.readJavaScope( TestConstants.WALA_TESTDATA, // new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), - new FileProvider().getFile("/Users/aakgna/Documents/WALA-Research/WALA/core/src/test/java/com/ibm/wala/core/tests/cha/CodeDeletedTest.java"), + new FileProvider().getFile("/Users/aakgna/Documents/WALA-Research/WALA/xvfb-gradle.sh"), AnalysisScopeTest.class.getClassLoader()); Gson gson = new Gson(); String exp = gson.toJson("scope.toString()"); + System.out.println(scope.toJson()); assertEquals(exp, scope.toJson()); } From 307607af349576b7c26954655d3698df1f60f6fc Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Wed, 3 Jan 2024 13:29:56 -0800 Subject: [PATCH 06/40] added changes to toJson --- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 20 ++++++++++++------- .../core/tests/cha/AnalysisScopeTest.java | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index d052515495..4997d74cb3 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -44,6 +44,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -353,22 +354,27 @@ public String toString() { public String toJson() { // StringBuilder result = new StringBuilder(); Set track = new HashSet<>(); + HashMap res = new HashMap<>(); HashMap> hashMap = new HashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { ArrayList arr = new ArrayList<>(); for (Module m : getModules(loader)) { arr.add(m.toString()); } - if(!track.contains("Exclusions")) { - track.add("Exclusions"); - String newStr = getExclusionString().toString().substring(12); - ArrayList arr2 = new ArrayList<>(); - arr2.add(newStr); - hashMap.put("Exclusions", arr2); - } track.add(loader.getName().toString()); hashMap.put(loader.getName().toString(), arr); } + res.put("Loaders", hashMap); + String[] exclusions = getExclusions().toString().split("\\|"); + ArrayList arr2 = new ArrayList<>(); + for(int i = 0; i < exclusions.length; i++){ + String word = exclusions[i]; + word = word.replace("(", ""); + word = word.replace(")", ""); + arr2.add(word); + } + res.put("Exclusions", arr2); + System.out.println(res); Gson gson = new Gson(); return gson.toJson(hashMap); } diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 9b95c0ffa4..a3d020a2e7 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -29,11 +29,11 @@ public void toJsonTest() throws IOException { AnalysisScopeReader.instance.readJavaScope( TestConstants.WALA_TESTDATA, // new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), - new FileProvider().getFile("/Users/aakgna/Documents/WALA-Research/WALA/xvfb-gradle.sh"), + new FileProvider().getFile("GUIExclusions.txt"), AnalysisScopeTest.class.getClassLoader()); Gson gson = new Gson(); String exp = gson.toJson("scope.toString()"); - System.out.println(scope.toJson()); + // System.out.println(scope.toJson()); assertEquals(exp, scope.toJson()); } From cb5dd7bc7a53350fe0ee4f7d8fc78d84030bc5e5 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Wed, 3 Jan 2024 16:46:34 -0800 Subject: [PATCH 07/40] returned correct value --- .../com/ibm/wala/ipa/callgraph/AnalysisScope.java | 11 ++++------- .../ibm/wala/core/tests/cha/AnalysisScopeTest.java | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 4997d74cb3..d07017869d 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -353,18 +353,16 @@ public String toString() { public String toJson() { // StringBuilder result = new StringBuilder(); - Set track = new HashSet<>(); HashMap res = new HashMap<>(); - HashMap> hashMap = new HashMap<>(); + HashMap> loaders = new HashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { ArrayList arr = new ArrayList<>(); for (Module m : getModules(loader)) { arr.add(m.toString()); } - track.add(loader.getName().toString()); - hashMap.put(loader.getName().toString(), arr); + loaders.put(loader.getName().toString(), arr); } - res.put("Loaders", hashMap); + res.put("Loaders", loaders); String[] exclusions = getExclusions().toString().split("\\|"); ArrayList arr2 = new ArrayList<>(); for(int i = 0; i < exclusions.length; i++){ @@ -374,9 +372,8 @@ public String toJson() { arr2.add(word); } res.put("Exclusions", arr2); - System.out.println(res); Gson gson = new Gson(); - return gson.toJson(hashMap); + return gson.toJson(res); } /** diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index a3d020a2e7..5a50500709 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -33,7 +33,7 @@ public void toJsonTest() throws IOException { AnalysisScopeTest.class.getClassLoader()); Gson gson = new Gson(); String exp = gson.toJson("scope.toString()"); - // System.out.println(scope.toJson()); + System.out.println(scope.toJson()); assertEquals(exp, scope.toJson()); } From b489343b88f43a17d94e3ee8b1c29907d01bbccb Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Sat, 13 Jan 2024 15:16:18 -0800 Subject: [PATCH 08/40] changes .settings --- cast/.settings/org.eclipse.jdt.core.prefs | 1 - cast/java/.settings/org.eclipse.jdt.core.prefs | 1 - cast/java/ecj/.settings/org.eclipse.jdt.core.prefs | 1 - cast/java/test/data/.settings/org.eclipse.jdt.core.prefs | 1 - cast/js/.settings/org.eclipse.jdt.core.prefs | 1 - cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs | 1 - cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs | 1 - cast/js/rhino/.settings/org.eclipse.jdt.core.prefs | 1 - core/.settings/org.eclipse.jdt.core.prefs | 2 +- dalvik/.settings/org.eclipse.jdt.core.prefs | 2 +- ide/.settings/org.eclipse.jdt.core.prefs | 1 - ide/jdt/.settings/org.eclipse.jdt.core.prefs | 1 - ide/jdt/test/.settings/org.eclipse.jdt.core.prefs | 1 - ide/jsdt/.settings/org.eclipse.jdt.core.prefs | 1 - ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs | 1 - ide/tests/.settings/org.eclipse.jdt.core.prefs | 1 - scandroid/.settings/org.eclipse.jdt.core.prefs | 1 - shrike/.settings/org.eclipse.jdt.core.prefs | 2 +- util/.settings/org.eclipse.jdt.core.prefs | 1 - 19 files changed, 3 insertions(+), 19 deletions(-) diff --git a/cast/.settings/org.eclipse.jdt.core.prefs b/cast/.settings/org.eclipse.jdt.core.prefs index 46dc8478d7..bf53eca489 100644 --- a/cast/.settings/org.eclipse.jdt.core.prefs +++ b/cast/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/java/.settings/org.eclipse.jdt.core.prefs b/cast/java/.settings/org.eclipse.jdt.core.prefs index cb7184c292..8f8e931c63 100644 --- a/cast/java/.settings/org.eclipse.jdt.core.prefs +++ b/cast/java/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs b/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs index bcfd2a8da2..5c12c8d1b0 100644 --- a/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs +++ b/cast/java/ecj/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,4 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs b/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs index 40411da3de..cf946c8de5 100644 --- a/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs +++ b/cast/java/test/data/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/.settings/org.eclipse.jdt.core.prefs b/cast/js/.settings/org.eclipse.jdt.core.prefs index 76347aee04..463e28aa37 100644 --- a/cast/js/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs b/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs index 4f191ef2ac..2b9d39c4ea 100644 --- a/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/html/nu_validator/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs b/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs index 9833c75b73..3ad950dfca 100644 --- a/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/nodejs/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs b/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs index 0d62206c7c..760d320e82 100644 --- a/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs +++ b/cast/js/rhino/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/core/.settings/org.eclipse.jdt.core.prefs b/core/.settings/org.eclipse.jdt.core.prefs index d7762182a3..9b009e559e 100644 --- a/core/.settings/org.eclipse.jdt.core.prefs +++ b/core/.settings/org.eclipse.jdt.core.prefs @@ -8,7 +8,7 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=,*.g org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/dalvik/.settings/org.eclipse.jdt.core.prefs b/dalvik/.settings/org.eclipse.jdt.core.prefs index b136978268..fff9860cf0 100644 --- a/dalvik/.settings/org.eclipse.jdt.core.prefs +++ b/dalvik/.settings/org.eclipse.jdt.core.prefs @@ -7,7 +7,7 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=,*.g org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/.settings/org.eclipse.jdt.core.prefs b/ide/.settings/org.eclipse.jdt.core.prefs index 1d033d1fa9..cd676248fe 100644 --- a/ide/.settings/org.eclipse.jdt.core.prefs +++ b/ide/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jdt/.settings/org.eclipse.jdt.core.prefs b/ide/jdt/.settings/org.eclipse.jdt.core.prefs index 2939d58ea7..55d5744105 100644 --- a/ide/jdt/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jdt/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs b/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs index 861143ac53..0d9a8a083e 100644 --- a/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jdt/test/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jsdt/.settings/org.eclipse.jdt.core.prefs b/ide/jsdt/.settings/org.eclipse.jdt.core.prefs index 2cbe9c1cdb..1e908e2c71 100644 --- a/ide/jsdt/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jsdt/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs b/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs index c7caafc691..fa9ef42774 100644 --- a/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs +++ b/ide/jsdt/tests/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/ide/tests/.settings/org.eclipse.jdt.core.prefs b/ide/tests/.settings/org.eclipse.jdt.core.prefs index a78ffab6a0..b9a5f6959b 100644 --- a/ide/tests/.settings/org.eclipse.jdt.core.prefs +++ b/ide/tests/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/scandroid/.settings/org.eclipse.jdt.core.prefs b/scandroid/.settings/org.eclipse.jdt.core.prefs index c225f50aa8..c9942e9779 100644 --- a/scandroid/.settings/org.eclipse.jdt.core.prefs +++ b/scandroid/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,4 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/shrike/.settings/org.eclipse.jdt.core.prefs b/shrike/.settings/org.eclipse.jdt.core.prefs index 74e011e600..3150e13e55 100644 --- a/shrike/.settings/org.eclipse.jdt.core.prefs +++ b/shrike/.settings/org.eclipse.jdt.core.prefs @@ -8,7 +8,7 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=,*.g org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore +org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull diff --git a/util/.settings/org.eclipse.jdt.core.prefs b/util/.settings/org.eclipse.jdt.core.prefs index 352ce4e43c..1ae6eb0923 100644 --- a/util/.settings/org.eclipse.jdt.core.prefs +++ b/util/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=ignore org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull From a38c5b7099ccd6b51b527a60b633bc72b2e580e7 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Mon, 22 Jan 2024 16:59:05 -0800 Subject: [PATCH 09/40] removed unnecessary changes --- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 1 - .../core/tests/callGraph/CallGraphTest.java | 4 +-- .../core/tests/cha/AnalysisScopeTest.java | 19 +--------- gradle/wrapper/gradle-wrapper.properties | 6 ++-- gradlew | 14 ++++---- z-out.java | 35 ------------------- 6 files changed, 13 insertions(+), 66 deletions(-) delete mode 100644 z-out.java diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index d07017869d..55f4b21af1 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -352,7 +352,6 @@ public String toString() { } public String toJson() { - // StringBuilder result = new StringBuilder(); HashMap res = new HashMap<>(); HashMap> loaders = new HashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { diff --git a/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java b/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java index 9dcf85eb39..cf60e65d01 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java @@ -302,7 +302,7 @@ public void testPrimordial() if (useShortProfile()) { return; } - + AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope( "primordial.txt", @@ -680,4 +680,4 @@ public boolean hasEdge(MethodReference src, MethodReference dst) { } }; } -} +} \ No newline at end of file diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 5a50500709..ad28a586e0 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -1,6 +1,5 @@ package com.ibm.wala.core.tests.cha; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -19,24 +18,8 @@ import java.nio.file.Paths; import org.junit.jupiter.api.Test; -import com.google.gson.Gson; - public class AnalysisScopeTest { - @Test - public void toJsonTest() throws IOException { - AnalysisScope scope = - AnalysisScopeReader.instance.readJavaScope( - TestConstants.WALA_TESTDATA, - // new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), - new FileProvider().getFile("GUIExclusions.txt"), - AnalysisScopeTest.class.getClassLoader()); - Gson gson = new Gson(); - String exp = gson.toJson("scope.toString()"); - System.out.println(scope.toJson()); - assertEquals(exp, scope.toJson()); - } - @Test public void testJarInputStream() throws IOException, ClassHierarchyException { AnalysisScope scope = @@ -72,4 +55,4 @@ public void testBaseScope() throws IOException, ClassHierarchyException { ClassLoaderReference.Application, "Ljava/awt/AlphaComposite")), "found unexpected class"); } -} +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41b59bedc4..e1b846c9d5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,8 +1,8 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=f2b9ed0faf8472cbe469255ae6c86eddb77076c75191741b4a462f33128dd419 -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionSha256Sum=c16d517b50dd28b3f5838f0e844b7520b8f1eb610f2f29de7e4e04a1b7c9c79b +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +zipStorePath=wrapper/dists \ No newline at end of file diff --git a/gradlew b/gradlew index 1aa94a4269..0adc8e1a53 100755 --- a/gradlew +++ b/gradlew @@ -145,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -153,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -202,11 +202,11 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, -# and any embedded shellness will be escaped. -# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be -# treated as '${Hostname}' itself on the command line. +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/z-out.java b/z-out.java deleted file mode 100644 index f4f67996fb..0000000000 --- a/z-out.java +++ /dev/null @@ -1,35 +0,0 @@ -// Example Code - -public class example { - public String convert_to_json(T dataStructure) throws IOException { - Gson gson = new Gson(); - System.out.println("gson"); - String json_format = gson.toJson(dataStructure); - FileWriter writer = new FileWriter("output2.json"); - writer.write(json_format); - writer.close(); - return json_format; - } - public String main() { - String out = convert_to_json("null"); - return out; - } - -} - -// example output - -{ - { - "Class_Name": "example", - "Functions": ["convert_to_json", "main"] - }, - { - "Class_Name": "convert_to_json", - "Functions": ["Gson", "toJson", "FileWriter", "write", "close"] - }, - { - "Class_Name": "main", - "Functions": ["convert_to_json"] - } -} From 6d15461d769b9767a26cb45b0ce36d2802d29c95 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 30 Jan 2024 10:06:50 -0800 Subject: [PATCH 10/40] added linkedHashmap to AnalysisScope and created test for toJson --- .../com/ibm/wala/ipa/callgraph/AnalysisScope.java | 5 +++-- .../ibm/wala/core/tests/cha/AnalysisScopeTest.java | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 55f4b21af1..345754cc9f 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -352,8 +352,9 @@ public String toString() { } public String toJson() { - HashMap res = new HashMap<>(); - HashMap> loaders = new HashMap<>(); + // make linked hashmap + LinkedHashMap res = new LinkedHashMap<>(); + LinkedHashMap> loaders = new LinkedHashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { ArrayList arr = new ArrayList<>(); for (Module m : getModules(loader)) { diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index ad28a586e0..8c4095c189 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -1,5 +1,6 @@ package com.ibm.wala.core.tests.cha; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -55,4 +56,16 @@ public void testBaseScope() throws IOException, ClassHierarchyException { ClassLoaderReference.Application, "Ljava/awt/AlphaComposite")), "found unexpected class"); } + + @Test + public void testToJson() throws IOException { + AnalysisScope scope = + AnalysisScopeReader.instance.readJavaScope( + TestConstants.WALA_TESTDATA, + // new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), + new FileProvider().getFile("GUIExclusions.txt"), + AnalysisScopeTest.class.getClassLoader()); + String exp = "{\"Loaders\":{\"Primordial\":[\"JarFileModule:/opt/homebrew/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home/jmods/java.base.jmod\",\"Nested Jar File:primordial.jar.model\"],\"Extension\":[],\"Application\":[\"JarFileModule:/Users/aakgna/Documents/WALA-Research/WALA/core/build/resources/test/com.ibm.wala.core.testdata_1.0.0.jar\"],\"Synthetic\":[]},\"Exclusions\":[\"java\\\\/awt\\\\/.*\",\"javax\\\\/swing\\\\/.*\",\"sun\\\\/awt\\\\/.*\",\"sun\\\\/swing\\\\/.*\"]}"; + assertEquals(exp, scope.toJson().toString()); + } } \ No newline at end of file From e57b590763bb8a19de97ae22c741ae45d3268c5a Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 30 Jan 2024 11:35:41 -0800 Subject: [PATCH 11/40] deleted unnecessary lines --- .../main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 345754cc9f..3b682d671c 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -58,9 +58,6 @@ import java.util.jar.Manifest; import com.google.gson.Gson; - -// import com.google.gson.Gson; - /** * Base class that represents a set of files to analyze. * @@ -352,7 +349,6 @@ public String toString() { } public String toJson() { - // make linked hashmap LinkedHashMap res = new LinkedHashMap<>(); LinkedHashMap> loaders = new LinkedHashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { From c237c76527032dd4da1090190f003b4ff5d84ea0 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Sun, 11 Feb 2024 20:03:11 -0800 Subject: [PATCH 12/40] implemented changes for toJson and added endlines --- .../core/tests/callGraph/CallGraphTest.java | 2 +- .../core/tests/cha/AnalysisScopeTest.java | 71 ++++++++++++++++++- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java b/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java index 193f0700c9..968e0b5462 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/callGraph/CallGraphTest.java @@ -723,4 +723,4 @@ public boolean hasEdge(MethodReference src, MethodReference dst) { } }; } -} \ No newline at end of file +} diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 8c4095c189..dedf08b929 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -17,7 +17,13 @@ import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.LinkedHashMap; + import org.junit.jupiter.api.Test; +import com.google.gson.Gson; +import java.lang.reflect.Type; +import com.google.gson.reflect.TypeToken; public class AnalysisScopeTest { @@ -65,7 +71,66 @@ public void testToJson() throws IOException { // new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), new FileProvider().getFile("GUIExclusions.txt"), AnalysisScopeTest.class.getClassLoader()); - String exp = "{\"Loaders\":{\"Primordial\":[\"JarFileModule:/opt/homebrew/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home/jmods/java.base.jmod\",\"Nested Jar File:primordial.jar.model\"],\"Extension\":[],\"Application\":[\"JarFileModule:/Users/aakgna/Documents/WALA-Research/WALA/core/build/resources/test/com.ibm.wala.core.testdata_1.0.0.jar\"],\"Synthetic\":[]},\"Exclusions\":[\"java\\\\/awt\\\\/.*\",\"javax\\\\/swing\\\\/.*\",\"sun\\\\/awt\\\\/.*\",\"sun\\\\/swing\\\\/.*\"]}"; - assertEquals(exp, scope.toJson().toString()); + Gson gson = new Gson(); + Type type = new TypeToken>(){}.getType(); + LinkedHashMap map = gson.fromJson(scope.toJson(), type); + System.out.println(map); + if(map.containsKey("Exclusions")) { + String[] exclusions = scope.getExclusions().toString().split("\\|"); + ArrayList arr2 = new ArrayList<>(); + for(int i = 0; i < exclusions.length; i++){ + String word = exclusions[i]; + word = word.replace("(", ""); + word = word.replace(")", ""); + arr2.add(word); + } + assertEquals(arr2, map.get("Exclusions")); + } + Type type2 = new TypeToken>>(){}.getType(); + LinkedHashMap> loaders = gson.fromJson(gson.toJson(map.get("Loaders")), type2); + if(loaders.containsKey("Primordial")) { + boolean flag = true; + for (int i = 0; i < scope.getModules(scope.getPrimordialLoader()).size(); i++) { + String s1 = scope.getModules(scope.getPrimordialLoader()).get(i).toString(); + if (!loaders.get("Primordial").contains(s1)) { + flag = false; + break; + } + } + assertEquals(true, flag); + } + if(loaders.containsKey("Extension")) { + boolean flag = true; + for (int i = 0; i < scope.getModules(scope.getExtensionLoader()).size(); i++) { + String s1 = scope.getModules(scope.getExtensionLoader()).get(i).toString(); + if (!loaders.get("Extension").contains(s1)) { + flag = false; + break; + } + } + assertEquals(true, flag); + } + if(loaders.containsKey("Application")) { + boolean flag = true; + for (int i = 0; i < scope.getModules(scope.getApplicationLoader()).size(); i++) { + String s1 = scope.getModules(scope.getApplicationLoader()).get(i).toString(); + if (!loaders.get("Application").contains(s1)) { + flag = false; + break; + } + } + assertEquals(true, flag); + } + if(loaders.containsKey("Synthetic")) { + boolean flag = true; + for (int i = 0; i < scope.getModules(scope.getSyntheticLoader()).size(); i++) { + String s1 = scope.getModules(scope.getSyntheticLoader()).get(i).toString(); + if (!loaders.get("Synthetic").contains(s1)) { + flag = false; + break; + } + } + assertEquals(true, flag); + } } -} \ No newline at end of file +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e1b846c9d5..a7a990ab2a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -5,4 +5,4 @@ distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists \ No newline at end of file +zipStorePath=wrapper/dists From fbe9c595baa34513250cc77bdca4f5567e5ffd47 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 13 Feb 2024 11:27:05 -0800 Subject: [PATCH 13/40] completed changes for AnalysisScopeTest and removed 1 import statement for AnalysisScope --- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 1 + .../core/tests/cha/AnalysisScopeTest.java | 76 ++++++------------- 2 files changed, 25 insertions(+), 52 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 3b682d671c..6931e9af9b 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -353,6 +353,7 @@ public String toJson() { LinkedHashMap> loaders = new LinkedHashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { ArrayList arr = new ArrayList<>(); + for (Module m : getModules(loader)) { arr.add(m.toString()); } diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index dedf08b929..1980907cff 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -13,12 +13,20 @@ import com.ibm.wala.ipa.cha.ClassHierarchyFactory; import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.types.TypeReference; +import com.ibm.wala.util.collections.Iterator2Collection; + import java.io.FileInputStream; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.junit.jupiter.api.Test; import com.google.gson.Gson; @@ -68,69 +76,33 @@ public void testToJson() throws IOException { AnalysisScope scope = AnalysisScopeReader.instance.readJavaScope( TestConstants.WALA_TESTDATA, - // new FileProvider().getFile("J2SEClassHierarchyExclusions.txt"), new FileProvider().getFile("GUIExclusions.txt"), AnalysisScopeTest.class.getClassLoader()); Gson gson = new Gson(); Type type = new TypeToken>(){}.getType(); LinkedHashMap map = gson.fromJson(scope.toJson(), type); - System.out.println(map); if(map.containsKey("Exclusions")) { - String[] exclusions = scope.getExclusions().toString().split("\\|"); - ArrayList arr2 = new ArrayList<>(); - for(int i = 0; i < exclusions.length; i++){ - String word = exclusions[i]; - word = word.replace("(", ""); - word = word.replace(")", ""); - arr2.add(word); - } - assertEquals(arr2, map.get("Exclusions")); + assertEquals(List.of("java\\/awt\\/.*", "javax\\/swing\\/.*", "sun\\/awt\\/.*", "sun\\/swing\\/.*"), map.get("Exclusions")); } - Type type2 = new TypeToken>>(){}.getType(); - LinkedHashMap> loaders = gson.fromJson(gson.toJson(map.get("Loaders")), type2); - if(loaders.containsKey("Primordial")) { - boolean flag = true; - for (int i = 0; i < scope.getModules(scope.getPrimordialLoader()).size(); i++) { - String s1 = scope.getModules(scope.getPrimordialLoader()).get(i).toString(); - if (!loaders.get("Primordial").contains(s1)) { - flag = false; - break; - } + + if (map.get("Loaders") instanceof Map) { + Map> loaders = (Map>) map.get("Loaders"); + Set loadKey = new HashSet<>(Arrays.asList("Primordial", "Extension", "Application", "Synthetic")); + assertEquals(loaders.keySet(), loadKey); + if(loaders.containsKey("Primordial")) { + assertEquals(2, loaders.get("Primordial").size()); + assertEquals(true, loaders.get("Primordial").contains("Nested Jar File:primordial.jar.model")); } - assertEquals(true, flag); - } - if(loaders.containsKey("Extension")) { - boolean flag = true; - for (int i = 0; i < scope.getModules(scope.getExtensionLoader()).size(); i++) { - String s1 = scope.getModules(scope.getExtensionLoader()).get(i).toString(); - if (!loaders.get("Extension").contains(s1)) { - flag = false; - break; - } + if(loaders.containsKey("Application")) { + assertEquals(1, loaders.get("Application").size()); + assertEquals(true, loaders.get("Application").get(0).contains("com.ibm.wala.core.testdata_1.0.0.jar")); } - assertEquals(true, flag); - } - if(loaders.containsKey("Application")) { - boolean flag = true; - for (int i = 0; i < scope.getModules(scope.getApplicationLoader()).size(); i++) { - String s1 = scope.getModules(scope.getApplicationLoader()).get(i).toString(); - if (!loaders.get("Application").contains(s1)) { - flag = false; - break; - } + if(loaders.containsKey("Extension")) { + assertEquals(0, loaders.get("Extension").size()); } - assertEquals(true, flag); - } - if(loaders.containsKey("Synthetic")) { - boolean flag = true; - for (int i = 0; i < scope.getModules(scope.getSyntheticLoader()).size(); i++) { - String s1 = scope.getModules(scope.getSyntheticLoader()).get(i).toString(); - if (!loaders.get("Synthetic").contains(s1)) { - flag = false; - break; - } + if(loaders.containsKey("Synthetic")) { + assertEquals(0, loaders.get("Synthetic").size()); } - assertEquals(true, flag); } } } From 3cfff82faf87828d7e0add6faeea693fc8a0b58a Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Tue, 13 Feb 2024 17:50:53 -0800 Subject: [PATCH 14/40] Tune up test and fix formatting --- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 6 +- .../core/tests/cha/AnalysisScopeTest.java | 73 ++++++++----------- 2 files changed, 33 insertions(+), 46 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 6931e9af9b..9450a38498 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -10,6 +10,7 @@ */ package com.ibm.wala.ipa.callgraph; +import com.google.gson.Gson; import com.ibm.wala.classLoader.ArrayClassLoader; import com.ibm.wala.classLoader.BinaryDirectoryTreeModule; import com.ibm.wala.classLoader.ClassFileModule; @@ -44,7 +45,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -52,11 +52,9 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.HashSet; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; -import com.google.gson.Gson; /** * Base class that represents a set of files to analyze. @@ -362,7 +360,7 @@ public String toJson() { res.put("Loaders", loaders); String[] exclusions = getExclusions().toString().split("\\|"); ArrayList arr2 = new ArrayList<>(); - for(int i = 0; i < exclusions.length; i++){ + for (int i = 0; i < exclusions.length; i++) { String word = exclusions[i]; word = word.replace("(", ""); word = word.replace(")", ""); diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 1980907cff..c860c0cace 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -1,9 +1,14 @@ package com.ibm.wala.core.tests.cha; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.ibm.wala.core.tests.util.TestConstants; import com.ibm.wala.core.util.config.AnalysisScopeReader; import com.ibm.wala.core.util.io.FileProvider; @@ -13,25 +18,17 @@ import com.ibm.wala.ipa.cha.ClassHierarchyFactory; import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.types.TypeReference; -import com.ibm.wala.util.collections.Iterator2Collection; - import java.io.FileInputStream; import java.io.IOException; +import java.lang.reflect.Type; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; - import org.junit.jupiter.api.Test; -import com.google.gson.Gson; -import java.lang.reflect.Type; -import com.google.gson.reflect.TypeToken; public class AnalysisScopeTest { @@ -72,37 +69,29 @@ public void testBaseScope() throws IOException, ClassHierarchyException { } @Test - public void testToJson() throws IOException { - AnalysisScope scope = - AnalysisScopeReader.instance.readJavaScope( - TestConstants.WALA_TESTDATA, - new FileProvider().getFile("GUIExclusions.txt"), - AnalysisScopeTest.class.getClassLoader()); - Gson gson = new Gson(); - Type type = new TypeToken>(){}.getType(); - LinkedHashMap map = gson.fromJson(scope.toJson(), type); - if(map.containsKey("Exclusions")) { - assertEquals(List.of("java\\/awt\\/.*", "javax\\/swing\\/.*", "sun\\/awt\\/.*", "sun\\/swing\\/.*"), map.get("Exclusions")); - } - - if (map.get("Loaders") instanceof Map) { - Map> loaders = (Map>) map.get("Loaders"); - Set loadKey = new HashSet<>(Arrays.asList("Primordial", "Extension", "Application", "Synthetic")); - assertEquals(loaders.keySet(), loadKey); - if(loaders.containsKey("Primordial")) { - assertEquals(2, loaders.get("Primordial").size()); - assertEquals(true, loaders.get("Primordial").contains("Nested Jar File:primordial.jar.model")); - } - if(loaders.containsKey("Application")) { - assertEquals(1, loaders.get("Application").size()); - assertEquals(true, loaders.get("Application").get(0).contains("com.ibm.wala.core.testdata_1.0.0.jar")); - } - if(loaders.containsKey("Extension")) { - assertEquals(0, loaders.get("Extension").size()); - } - if(loaders.containsKey("Synthetic")) { - assertEquals(0, loaders.get("Synthetic").size()); - } - } - } + public void testToJson() throws IOException { + AnalysisScope scope = + AnalysisScopeReader.instance.readJavaScope( + TestConstants.WALA_TESTDATA, + new FileProvider().getFile("GUIExclusions.txt"), + AnalysisScopeTest.class.getClassLoader()); + Gson gson = new Gson(); + Type type = new TypeToken>() {}.getType(); + LinkedHashMap map = gson.fromJson(scope.toJson(), type); + assertEquals( + List.of("java\\/awt\\/.*", "javax\\/swing\\/.*", "sun\\/awt\\/.*", "sun\\/swing\\/.*"), + map.get("Exclusions")); + + Map> loaders = (Map>) map.get("Loaders"); + Set loaderKeys = + new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); + assertEquals(loaders.keySet(), loaderKeys); + assertEquals(2, loaders.get("Primordial").size()); + assertThat(loaders.get("Primordial"), hasItem("Nested Jar File:primordial.jar.model")); + assertEquals(1, loaders.get("Application").size()); + assertThat( + loaders.get("Application").get(0), containsString("com.ibm.wala.core.testdata_1.0.0.jar")); + assertEquals(0, loaders.get("Extension").size()); + assertEquals(0, loaders.get("Synthetic").size()); + } } From ebd73aef3c06426074ab096e778380368a07ea79 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Tue, 13 Feb 2024 18:31:36 -0800 Subject: [PATCH 15/40] suppress a warning --- .../test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index c860c0cace..f7541dc3e3 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -82,6 +82,7 @@ public void testToJson() throws IOException { List.of("java\\/awt\\/.*", "javax\\/swing\\/.*", "sun\\/awt\\/.*", "sun\\/swing\\/.*"), map.get("Exclusions")); + @SuppressWarnings("unchecked") Map> loaders = (Map>) map.get("Loaders"); Set loaderKeys = new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); From 89359aa664fb95a4cc583922a5633d5da202e554 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 27 Feb 2024 15:45:22 -0800 Subject: [PATCH 16/40] added custom analysisScope test --- .../core/tests/cha/AnalysisScopeTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index f7541dc3e3..49b6fa1b6f 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -28,6 +28,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.jar.JarFile; +import com.ibm.wala.properties.WalaProperties; import org.junit.jupiter.api.Test; public class AnalysisScopeTest { @@ -95,4 +97,45 @@ public void testToJson() throws IOException { assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } + + @Test + public void testToJsonCustom() throws IOException { + AnalysisScope scope; + scope = AnalysisScope.createJavaAnalysisScope(); + AnalysisScope tempScope = + AnalysisScopeReader.instance.readJavaScope( + TestConstants.WALA_TESTDATA, + new FileProvider().getFile("GUIExclusions.txt"), + AnalysisScopeTest.class.getClassLoader()); + scope.setExclusions(tempScope.getExclusions()); + String[] stdlibs = WalaProperties.getJ2SEJarFiles(); + int cnt = 0; + for (String stdlib : stdlibs) { + scope.addToScope(ClassLoaderReference.Primordial, new JarFile(stdlib)); + scope.addToScope(ClassLoaderReference.Application, new JarFile(stdlib)); + cnt++; + if(cnt == 5) { + break; + } + } + Gson gson = new Gson(); + Type type = new TypeToken>() {}.getType(); + LinkedHashMap map = gson.fromJson(scope.toJson(), type); + assertEquals( + List.of("java\\/awt\\/.*", "javax\\/swing\\/.*", "sun\\/awt\\/.*", "sun\\/swing\\/.*"), + map.get("Exclusions")); + + @SuppressWarnings("unchecked") + Map> loaders = (Map>) map.get("Loaders"); + Set loaderKeys = + new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); + assertEquals(loaders.keySet(), loaderKeys); + assertEquals(5, loaders.get("Primordial").size()); + assertThat(loaders.get("Primordial"), hasItem("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.security.sasl.jmod")); + assertEquals(5, loaders.get("Application").size()); + assertThat( + loaders.get("Application").get(0), containsString("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.security.sasl.jmod")); + assertEquals(0, loaders.get("Extension").size()); + assertEquals(0, loaders.get("Synthetic").size()); + } } From ed5500c21b377ac05909635f9adda37afdb57b74 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 27 Feb 2024 16:08:19 -0800 Subject: [PATCH 17/40] sorted stdlib --- .../java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 49b6fa1b6f..2cf4db9e17 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -23,6 +23,7 @@ import java.lang.reflect.Type; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -109,6 +110,7 @@ public void testToJsonCustom() throws IOException { AnalysisScopeTest.class.getClassLoader()); scope.setExclusions(tempScope.getExclusions()); String[] stdlibs = WalaProperties.getJ2SEJarFiles(); + Arrays.sort(stdlibs); int cnt = 0; for (String stdlib : stdlibs) { scope.addToScope(ClassLoaderReference.Primordial, new JarFile(stdlib)); @@ -131,10 +133,10 @@ public void testToJsonCustom() throws IOException { new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); assertEquals(5, loaders.get("Primordial").size()); - assertThat(loaders.get("Primordial"), hasItem("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.security.sasl.jmod")); + assertThat(loaders.get("Primordial"), hasItem("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); assertEquals(5, loaders.get("Application").size()); assertThat( - loaders.get("Application").get(0), containsString("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.security.sasl.jmod")); + loaders.get("Application").get(0), containsString("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } From 7036d90b79ddcd45717d50b20e8019b65fb6164d Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Tue, 27 Feb 2024 18:06:59 -0800 Subject: [PATCH 18/40] formatting --- .../ibm/wala/core/tests/cha/AnalysisScopeTest.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 2cf4db9e17..15ac0e1a5e 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -16,6 +16,7 @@ import com.ibm.wala.ipa.cha.ClassHierarchy; import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.ClassHierarchyFactory; +import com.ibm.wala.properties.WalaProperties; import com.ibm.wala.types.ClassLoaderReference; import com.ibm.wala.types.TypeReference; import java.io.FileInputStream; @@ -30,7 +31,6 @@ import java.util.Map; import java.util.Set; import java.util.jar.JarFile; -import com.ibm.wala.properties.WalaProperties; import org.junit.jupiter.api.Test; public class AnalysisScopeTest { @@ -116,7 +116,7 @@ public void testToJsonCustom() throws IOException { scope.addToScope(ClassLoaderReference.Primordial, new JarFile(stdlib)); scope.addToScope(ClassLoaderReference.Application, new JarFile(stdlib)); cnt++; - if(cnt == 5) { + if (cnt == 5) { break; } } @@ -133,10 +133,15 @@ public void testToJsonCustom() throws IOException { new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); assertEquals(5, loaders.get("Primordial").size()); - assertThat(loaders.get("Primordial"), hasItem("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); + assertThat( + loaders.get("Primordial"), + hasItem( + "JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); assertEquals(5, loaders.get("Application").size()); assertThat( - loaders.get("Application").get(0), containsString("JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); + loaders.get("Application").get(0), + containsString( + "JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } From 9b7b7e91d966c970ba6cd792948efc666088cfe6 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Wed, 28 Feb 2024 00:21:59 -0800 Subject: [PATCH 19/40] updated toJson custom test and added onto toJson method --- .../ibm/wala/ipa/callgraph/AnalysisScope.java | 27 ++++++++---- .../core/tests/cha/AnalysisScopeTest.java | 41 ++++++++----------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java index 9450a38498..b3e740925f 100644 --- a/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java +++ b/core/src/main/java/com/ibm/wala/ipa/callgraph/AnalysisScope.java @@ -346,27 +346,38 @@ public String toString() { return result.toString(); } + /** + * An AnalysisScope is converted to a JSON formatted variable using the loaders and exclusions + * hierarchy using ToJson. (Loaders) Primordial, Extension, Application, and Synthetic are the + * loaders keys; each one contains an arraylist of Strings. The exclusions contains an arraylist + * of strings. + * + * @return json variable containing contents of the AnalysisScope + */ public String toJson() { LinkedHashMap res = new LinkedHashMap<>(); LinkedHashMap> loaders = new LinkedHashMap<>(); for (ClassLoaderReference loader : loadersByName.values()) { ArrayList arr = new ArrayList<>(); - for (Module m : getModules(loader)) { arr.add(m.toString()); } loaders.put(loader.getName().toString(), arr); } res.put("Loaders", loaders); - String[] exclusions = getExclusions().toString().split("\\|"); ArrayList arr2 = new ArrayList<>(); - for (int i = 0; i < exclusions.length; i++) { - String word = exclusions[i]; - word = word.replace("(", ""); - word = word.replace(")", ""); - arr2.add(word); + if (getExclusions() == null) { + res.put("Exclusions", arr2); + } else { + String[] exclusions = getExclusions().toString().split("\\|"); + for (int i = 0; i < exclusions.length; i++) { + String word = exclusions[i]; + word = word.replace("(", ""); + word = word.replace(")", ""); + arr2.add(word); + } + res.put("Exclusions", arr2); } - res.put("Exclusions", arr2); Gson gson = new Gson(); return gson.toJson(res); } diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 15ac0e1a5e..baefd5980c 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -6,6 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -103,45 +104,37 @@ public void testToJson() throws IOException { public void testToJsonCustom() throws IOException { AnalysisScope scope; scope = AnalysisScope.createJavaAnalysisScope(); - AnalysisScope tempScope = - AnalysisScopeReader.instance.readJavaScope( - TestConstants.WALA_TESTDATA, - new FileProvider().getFile("GUIExclusions.txt"), - AnalysisScopeTest.class.getClassLoader()); - scope.setExclusions(tempScope.getExclusions()); String[] stdlibs = WalaProperties.getJ2SEJarFiles(); Arrays.sort(stdlibs); - int cnt = 0; for (String stdlib : stdlibs) { scope.addToScope(ClassLoaderReference.Primordial, new JarFile(stdlib)); scope.addToScope(ClassLoaderReference.Application, new JarFile(stdlib)); - cnt++; - if (cnt == 5) { - break; - } } + scope.setExclusions(null); Gson gson = new Gson(); Type type = new TypeToken>() {}.getType(); LinkedHashMap map = gson.fromJson(scope.toJson(), type); - assertEquals( - List.of("java\\/awt\\/.*", "javax\\/swing\\/.*", "sun\\/awt\\/.*", "sun\\/swing\\/.*"), - map.get("Exclusions")); + assertEquals(List.of(), map.get("Exclusions")); @SuppressWarnings("unchecked") Map> loaders = (Map>) map.get("Loaders"); Set loaderKeys = new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); - assertEquals(5, loaders.get("Primordial").size()); - assertThat( - loaders.get("Primordial"), - hasItem( - "JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); - assertEquals(5, loaders.get("Application").size()); - assertThat( - loaders.get("Application").get(0), - containsString( - "JarFileModule:/Users/aakgna/Library/Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); + assertEquals(stdlibs.length, loaders.get("Primordial").size()); + assertTrue( + loaders + .get("Primordial") + .get(0) + .contains( + "Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); + assertEquals(stdlibs.length, loaders.get("Application").size()); + assertTrue( + loaders + .get("Application") + .get(0) + .contains( + "Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } From a41401a84fc21e770e10f01ff22864977a464104 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Fri, 1 Mar 2024 14:24:03 -0800 Subject: [PATCH 20/40] test out path for stdlibs --- .../test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index baefd5980c..65a68d884d 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -122,6 +122,7 @@ public void testToJsonCustom() throws IOException { new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); assertEquals(stdlibs.length, loaders.get("Primordial").size()); + assertEquals(loaders.get("Primordial").get(0), stdlibs[0]); assertTrue( loaders .get("Primordial") From 8b9c04dee4fdbf1bc1f5185dc8ab5777f96c45aa Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Sun, 3 Mar 2024 15:11:27 -0800 Subject: [PATCH 21/40] modified file path to match all machines --- .../java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 65a68d884d..ceaedd7694 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -122,20 +122,19 @@ public void testToJsonCustom() throws IOException { new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); assertEquals(stdlibs.length, loaders.get("Primordial").size()); - assertEquals(loaders.get("Primordial").get(0), stdlibs[0]); assertTrue( loaders .get("Primordial") .get(0) .contains( - "Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); + "/Contents/Home/jmods/java.base.jmod")); assertEquals(stdlibs.length, loaders.get("Application").size()); assertTrue( loaders .get("Application") .get(0) .contains( - "Java/JavaVirtualMachines/corretto-11.0.15/Contents/Home/jmods/java.base.jmod")); + "/Contents/Home/jmods/java.base.jmod")); assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } From 15a4a1e7d7f91793377d1c7bd49f7b03ed730e64 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 4 Mar 2024 11:34:35 -0800 Subject: [PATCH 22/40] formatting --- .../ibm/wala/core/tests/cha/AnalysisScopeTest.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index ceaedd7694..2d554dcc02 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -122,19 +122,9 @@ public void testToJsonCustom() throws IOException { new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); assertEquals(stdlibs.length, loaders.get("Primordial").size()); - assertTrue( - loaders - .get("Primordial") - .get(0) - .contains( - "/Contents/Home/jmods/java.base.jmod")); + assertTrue(loaders.get("Primordial").get(0).contains("/Contents/Home/jmods/java.base.jmod")); assertEquals(stdlibs.length, loaders.get("Application").size()); - assertTrue( - loaders - .get("Application") - .get(0) - .contains( - "/Contents/Home/jmods/java.base.jmod")); + assertTrue(loaders.get("Application").get(0).contains("/Contents/Home/jmods/java.base.jmod")); assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } From f777f668f67f7058578c017744497ef9876f862d Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Mon, 4 Mar 2024 13:52:50 -0800 Subject: [PATCH 23/40] changed assertion in testToJsonCustom --- .../java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 2d554dcc02..7901243804 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -6,7 +6,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -122,9 +121,9 @@ public void testToJsonCustom() throws IOException { new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); assertEquals(stdlibs.length, loaders.get("Primordial").size()); - assertTrue(loaders.get("Primordial").get(0).contains("/Contents/Home/jmods/java.base.jmod")); + assertThat(loaders.get("Primordial"), hasItem("JarFileModule:" + stdlibs[0])); assertEquals(stdlibs.length, loaders.get("Application").size()); - assertTrue(loaders.get("Application").get(0).contains("/Contents/Home/jmods/java.base.jmod")); + assertThat(loaders.get("Application"), hasItem("JarFileModule:" + stdlibs[0])); assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } From efad1433d8a2f77d5981937d750ab5ffca73e2e2 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 5 Mar 2024 12:23:52 -0800 Subject: [PATCH 24/40] added for loop in testToJsonCustom (stdlibs) --- .../java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java index 7901243804..8c008c1703 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/cha/AnalysisScopeTest.java @@ -121,9 +121,11 @@ public void testToJsonCustom() throws IOException { new HashSet<>(List.of("Primordial", "Extension", "Application", "Synthetic")); assertEquals(loaders.keySet(), loaderKeys); assertEquals(stdlibs.length, loaders.get("Primordial").size()); - assertThat(loaders.get("Primordial"), hasItem("JarFileModule:" + stdlibs[0])); assertEquals(stdlibs.length, loaders.get("Application").size()); - assertThat(loaders.get("Application"), hasItem("JarFileModule:" + stdlibs[0])); + for (int i = 0; i < stdlibs.length; i++) { + assertThat(loaders.get("Primordial"), hasItem("JarFileModule:" + stdlibs[i])); + assertThat(loaders.get("Application"), hasItem("JarFileModule:" + stdlibs[i])); + } assertEquals(0, loaders.get("Extension").size()); assertEquals(0, loaders.get("Synthetic").size()); } From 016896e107228dd6421f7139f30090f73e4a9f6a Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 12 Mar 2024 00:08:33 -0700 Subject: [PATCH 25/40] initial algorithm for JSON Serialization --- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 50 +++++++++++++++++++ .../tests/callGraph/ClassConstantTest.java | 10 ++++ 2 files changed, 60 insertions(+) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index d5dca66fc8..4cec579a2d 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -10,6 +10,7 @@ */ package com.ibm.wala.ipa.cha; +import com.google.gson.Gson; import com.ibm.wala.classLoader.ArrayClass; import com.ibm.wala.classLoader.BytecodeClass; import com.ibm.wala.classLoader.ClassLoaderFactory; @@ -43,6 +44,7 @@ import com.ibm.wala.util.debug.Assertions; import com.ibm.wala.util.debug.UnimplementedError; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.ConcurrentModificationException; @@ -706,6 +708,54 @@ private void recursiveStringify(Node n, StringBuilder buffer) { } } + public Object toJson() { + int cnt = 0; + HashMap serial = new HashMap<>(); + // serial.put(root.klass, root.children); + Iterator children = root.getChildren(); + ArrayList> dag = new ArrayList<>(); + while(children.hasNext()) { + Node temp = children.next(); + HashMap fin = helper_toJson(temp, serial); + dag.add(fin); + // added cnt (count) so that the test does not get skipped + if(cnt == 6) { + break; + } + cnt++; + } + return dag; + } + + public HashMap helper_toJson(Node n, HashMap hash) { + if(n.children.size() > 0) { + Iterator children = n.getChildren(); + while(children.hasNext()) { + Node temp = children.next(); + HashMap temp_hash = helper_toJson(temp, hash); + String key = temp.getJavaClass().toString(); + key = key.replace("", ""); + if(!hash.containsKey(key)) { + hash.put(key, temp.children); + } + System.out.println(temp_hash); + } + } + else { + String key = n.getJavaClass().toString(); + key = key.replace("", ""); + if(!hash.containsKey(key)) { + hash.put(key, n.children); + } + } + return hash; + } + + /** * Number the class hierarchy tree to support efficient subclass tests. After numbering the tree, * n1 is a child of n2 iff n2.left <= n1.left ^ n1.left <= n2.right. Described as "relative diff --git a/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java b/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java index c6d4b4cc9d..e2f2513562 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java @@ -10,6 +10,7 @@ */ package com.ibm.wala.core.tests.callGraph; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -79,4 +80,13 @@ public void testClassConstants() // make sure call to hashCode from main assertTrue(cg.hasEdge(mainMethodNode, hashCodeNodes.iterator().next())); } + + @Test + public void classHierarchyToJson() throws ClassHierarchyException, IOException { + AnalysisScope scope = + CallGraphTestUtil.makeJ2SEAnalysisScope( + TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS); + ClassHierarchy cha = ClassHierarchyFactory.make(scope); + assertEquals("", cha.toJson()); + } } From c050542072832491b8a401185f6a35767c116b7b Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 12 Mar 2024 01:58:12 -0700 Subject: [PATCH 26/40] merged all hashmaps into one --- .../java/com/ibm/wala/ipa/cha/ClassHierarchy.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index 4cec579a2d..a6035350ef 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -719,12 +719,20 @@ public Object toJson() { HashMap fin = helper_toJson(temp, serial); dag.add(fin); // added cnt (count) so that the test does not get skipped - if(cnt == 6) { + if(cnt == 2) { break; } cnt++; } - return dag; + for (int i = 1; i < dag.size(); i++) { + dag.get(0).putAll(dag.get(i)); + } + String key = root.getJavaClass().toString(); + key = key.replace("", ""); + dag.get(0).put(key, root.children); + return dag.get(0); } public HashMap helper_toJson(Node n, HashMap hash) { From ed87a3a791d86cec89e0b70515f5169966a58931 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Mon, 15 Apr 2024 14:45:07 -0700 Subject: [PATCH 27/40] comment out cnt variable, test seems to pass --- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 25 ++++++++----------- .../tests/callGraph/ClassConstantTest.java | 4 +-- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index a6035350ef..491680f1c2 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -10,7 +10,6 @@ */ package com.ibm.wala.ipa.cha; -import com.google.gson.Gson; import com.ibm.wala.classLoader.ArrayClass; import com.ibm.wala.classLoader.BytecodeClass; import com.ibm.wala.classLoader.ClassLoaderFactory; @@ -709,20 +708,20 @@ private void recursiveStringify(Node n, StringBuilder buffer) { } public Object toJson() { - int cnt = 0; + // int cnt = 0; HashMap serial = new HashMap<>(); // serial.put(root.klass, root.children); Iterator children = root.getChildren(); ArrayList> dag = new ArrayList<>(); - while(children.hasNext()) { + while (children.hasNext()) { Node temp = children.next(); HashMap fin = helper_toJson(temp, serial); dag.add(fin); // added cnt (count) so that the test does not get skipped - if(cnt == 2) { - break; - } - cnt++; + // if(cnt == 2) { + // break; + // } + // cnt++; } for (int i = 1; i < dag.size(); i++) { dag.get(0).putAll(dag.get(i)); @@ -736,34 +735,32 @@ public Object toJson() { } public HashMap helper_toJson(Node n, HashMap hash) { - if(n.children.size() > 0) { + if (n.children.size() > 0) { Iterator children = n.getChildren(); - while(children.hasNext()) { + while (children.hasNext()) { Node temp = children.next(); HashMap temp_hash = helper_toJson(temp, hash); String key = temp.getJavaClass().toString(); key = key.replace("", ""); - if(!hash.containsKey(key)) { + if (!hash.containsKey(key)) { hash.put(key, temp.children); } System.out.println(temp_hash); } - } - else { + } else { String key = n.getJavaClass().toString(); key = key.replace("", ""); - if(!hash.containsKey(key)) { + if (!hash.containsKey(key)) { hash.put(key, n.children); } } return hash; } - /** * Number the class hierarchy tree to support efficient subclass tests. After numbering the tree, * n1 is a child of n2 iff n2.left <= n1.left ^ n1.left <= n2.right. Described as "relative diff --git a/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java b/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java index e2f2513562..627b619645 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java @@ -10,7 +10,6 @@ */ package com.ibm.wala.core.tests.callGraph; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -87,6 +86,7 @@ public void classHierarchyToJson() throws ClassHierarchyException, IOException { CallGraphTestUtil.makeJ2SEAnalysisScope( TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS); ClassHierarchy cha = ClassHierarchyFactory.make(scope); - assertEquals("", cha.toJson()); + Object unused = cha.toJson(); + // assertEquals("", json); } } From 030e8b33dc96d738f45bb87ad04b1a6aa9edad77 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Mon, 15 Apr 2024 19:09:06 -0700 Subject: [PATCH 28/40] Removed Primordial and Application from Klass of a Node --- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index 491680f1c2..90553f1349 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -708,20 +708,13 @@ private void recursiveStringify(Node n, StringBuilder buffer) { } public Object toJson() { - // int cnt = 0; HashMap serial = new HashMap<>(); - // serial.put(root.klass, root.children); Iterator children = root.getChildren(); ArrayList> dag = new ArrayList<>(); while (children.hasNext()) { Node temp = children.next(); HashMap fin = helper_toJson(temp, serial); dag.add(fin); - // added cnt (count) so that the test does not get skipped - // if(cnt == 2) { - // break; - // } - // cnt++; } for (int i = 1; i < dag.size(); i++) { dag.get(0).putAll(dag.get(i)); @@ -730,7 +723,17 @@ public Object toJson() { key = key.replace("", ""); - dag.get(0).put(key, root.children); + Iterator root_children = root.getChildren(); + Set final_root_children = new HashSet<>(); + while(root_children.hasNext()) { + Node val = root_children.next(); + String child_name = val.getJavaClass().toString(); + child_name = child_name.replace("", ""); + final_root_children.add(child_name); + } + dag.get(0).put(key, final_root_children); return dag.get(0); } @@ -745,7 +748,17 @@ public HashMap helper_toJson(Node n, HashMap has key = key.replace("", ""); if (!hash.containsKey(key)) { - hash.put(key, temp.children); + Iterator val = temp.getChildren(); + Set root = new HashSet<>(); + while(val.hasNext()) { + Node temp_val = val.next(); + String new_val = temp_val.getJavaClass().toString(); + new_val = new_val.replace("", ""); + root.add(new_val); + } + hash.put(key, root); } System.out.println(temp_hash); } From d09462c704439ec8a7be6fdb7363c128ffbef534 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Mon, 15 Apr 2024 19:56:46 -0700 Subject: [PATCH 29/40] added comments on toJson --- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index 90553f1349..e5317bc0f2 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -707,22 +707,28 @@ private void recursiveStringify(Node n, StringBuilder buffer) { } } + // Puts ClassHierarchy into a JSON readable variable that maps the class to a list of its subclasses public Object toJson() { - HashMap serial = new HashMap<>(); + // lines 713-715: initialize variables (subclass and dag) to store important values like hashmap of each iteration and a list of all maps of class to subclasses + HashMap subclass = new HashMap<>(); Iterator children = root.getChildren(); ArrayList> dag = new ArrayList<>(); + // lines 717-721: Goes through all subclasses of the root class, and adds the subclass hashmap to the list of all subclass hashmaps while (children.hasNext()) { Node temp = children.next(); - HashMap fin = helper_toJson(temp, serial); + HashMap fin = helper_toJson(temp, subclass); dag.add(fin); } + // lines 723-725: Puts all hashmaps into one larger hashmap for (int i = 1; i < dag.size(); i++) { dag.get(0).putAll(dag.get(i)); } + // lines 727-730: Removes unnecesarry parts from name of the class String key = root.getJavaClass().toString(); key = key.replace("", ""); + // lines 732-742: inserting the root class to its subclasses into the main hashmap while removing unnecessary substrings from the class name Iterator root_children = root.getChildren(); Set final_root_children = new HashSet<>(); while(root_children.hasNext()) { @@ -736,18 +742,24 @@ public Object toJson() { dag.get(0).put(key, final_root_children); return dag.get(0); } - + // helper function to toJson that performs recursion to go through all of the DAG public HashMap helper_toJson(Node n, HashMap hash) { + // Base case of no subclasses allowing recursion to stop if (n.children.size() > 0) { + // line 750 + while loop: defines iterator to go through the class's subclasses Iterator children = n.getChildren(); while (children.hasNext()) { + // line 753-754: puts subclass variable into temp, and start recursion from that subclass until base case reaches Node temp = children.next(); - HashMap temp_hash = helper_toJson(temp, hash); + helper_toJson(temp, hash); + // line 756-759: remove unnecessary substrings from class name String key = temp.getJavaClass().toString(); key = key.replace("", ""); + // if statement: only adds the map from class to subclass if class name does not exist in the overall hashmap if (!hash.containsKey(key)) { + //lines 763-773: Iterates through the subclass list and removes unnecessary substrings from class name --> adds that new value into varibale, root, containig all it's subclasses Iterator val = temp.getChildren(); Set root = new HashSet<>(); while(val.hasNext()) { @@ -758,11 +770,12 @@ public HashMap helper_toJson(Node n, HashMap has new_val = new_val.replace(">", ""); root.add(new_val); } + // line 774: insert into hashmap containing all class to subclass pairs hash.put(key, root); } - System.out.println(temp_hash); } } else { + // line 780-787: remove unnecessary substring from class name and map that to an empty list to add into the hashmap String key = n.getJavaClass().toString(); key = key.replace(" Date: Mon, 15 Apr 2024 19:59:06 -0700 Subject: [PATCH 30/40] added spotlessApply --- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index e5317bc0f2..5fc9a41f44 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -707,13 +707,16 @@ private void recursiveStringify(Node n, StringBuilder buffer) { } } - // Puts ClassHierarchy into a JSON readable variable that maps the class to a list of its subclasses + // Puts ClassHierarchy into a JSON readable variable that maps the class to a list of its + // subclasses public Object toJson() { - // lines 713-715: initialize variables (subclass and dag) to store important values like hashmap of each iteration and a list of all maps of class to subclasses + // lines 713-715: initialize variables (subclass and dag) to store important values like hashmap + // of each iteration and a list of all maps of class to subclasses HashMap subclass = new HashMap<>(); Iterator children = root.getChildren(); ArrayList> dag = new ArrayList<>(); - // lines 717-721: Goes through all subclasses of the root class, and adds the subclass hashmap to the list of all subclass hashmaps + // lines 717-721: Goes through all subclasses of the root class, and adds the subclass hashmap + // to the list of all subclass hashmaps while (children.hasNext()) { Node temp = children.next(); HashMap fin = helper_toJson(temp, subclass); @@ -728,10 +731,11 @@ public Object toJson() { key = key.replace("", ""); - // lines 732-742: inserting the root class to its subclasses into the main hashmap while removing unnecessary substrings from the class name + // lines 732-742: inserting the root class to its subclasses into the main hashmap while + // removing unnecessary substrings from the class name Iterator root_children = root.getChildren(); Set final_root_children = new HashSet<>(); - while(root_children.hasNext()) { + while (root_children.hasNext()) { Node val = root_children.next(); String child_name = val.getJavaClass().toString(); child_name = child_name.replace(" helper_toJson(Node n, HashMap hash) { // Base case of no subclasses allowing recursion to stop @@ -749,7 +754,8 @@ public HashMap helper_toJson(Node n, HashMap has // line 750 + while loop: defines iterator to go through the class's subclasses Iterator children = n.getChildren(); while (children.hasNext()) { - // line 753-754: puts subclass variable into temp, and start recursion from that subclass until base case reaches + // line 753-754: puts subclass variable into temp, and start recursion from that subclass + // until base case reaches Node temp = children.next(); helper_toJson(temp, hash); // line 756-759: remove unnecessary substrings from class name @@ -757,12 +763,15 @@ public HashMap helper_toJson(Node n, HashMap has key = key.replace("", ""); - // if statement: only adds the map from class to subclass if class name does not exist in the overall hashmap + // if statement: only adds the map from class to subclass if class name does not exist in + // the overall hashmap if (!hash.containsKey(key)) { - //lines 763-773: Iterates through the subclass list and removes unnecessary substrings from class name --> adds that new value into varibale, root, containig all it's subclasses + // lines 763-773: Iterates through the subclass list and removes unnecessary substrings + // from class name --> adds that new value into varibale, root, containig all it's + // subclasses Iterator val = temp.getChildren(); Set root = new HashSet<>(); - while(val.hasNext()) { + while (val.hasNext()) { Node temp_val = val.next(); String new_val = temp_val.getJavaClass().toString(); new_val = new_val.replace(" helper_toJson(Node n, HashMap has } } } else { - // line 780-787: remove unnecessary substring from class name and map that to an empty list to add into the hashmap + // line 780-787: remove unnecessary substring from class name and map that to an empty list to + // add into the hashmap String key = n.getJavaClass().toString(); key = key.replace(" Date: Wed, 17 Apr 2024 09:22:22 -0700 Subject: [PATCH 31/40] implemented GSON --- core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index 5fc9a41f44..d1a99b4b7c 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -10,6 +10,7 @@ */ package com.ibm.wala.ipa.cha; +import com.google.gson.Gson; import com.ibm.wala.classLoader.ArrayClass; import com.ibm.wala.classLoader.BytecodeClass; import com.ibm.wala.classLoader.ClassLoaderFactory; @@ -744,7 +745,8 @@ public Object toJson() { final_root_children.add(child_name); } dag.get(0).put(key, final_root_children); - return dag.get(0); + Gson gson = new Gson(); + return gson.toJson(dag.get(0)); } // helper function to toJson that performs recursion to go through all of the DAG From 2ec38a99b9b73f13e08e416e07c1f65665b0c7ab Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 23 Apr 2024 18:05:05 -0700 Subject: [PATCH 32/40] addressed comments to simplify code --- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 64 ++++++++----------- 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index d1a99b4b7c..8de1951884 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -44,7 +44,6 @@ import com.ibm.wala.util.debug.Assertions; import com.ibm.wala.util.debug.UnimplementedError; import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.ConcurrentModificationException; @@ -708,49 +707,39 @@ private void recursiveStringify(Node n, StringBuilder buffer) { } } - // Puts ClassHierarchy into a JSON readable variable that maps the class to a list of its - // subclasses + /* + * Puts ClassHierarchy into a JSON readable variable that maps the class to a list of its + * subclasses + */ public Object toJson() { - // lines 713-715: initialize variables (subclass and dag) to store important values like hashmap + // initialize variables (subclass and dag) to store important values like hashmap // of each iteration and a list of all maps of class to subclasses - HashMap subclass = new HashMap<>(); + HashMap> subclass = new HashMap<>(); Iterator children = root.getChildren(); - ArrayList> dag = new ArrayList<>(); // lines 717-721: Goes through all subclasses of the root class, and adds the subclass hashmap // to the list of all subclass hashmaps while (children.hasNext()) { Node temp = children.next(); - HashMap fin = helper_toJson(temp, subclass); - dag.add(fin); - } - // lines 723-725: Puts all hashmaps into one larger hashmap - for (int i = 1; i < dag.size(); i++) { - dag.get(0).putAll(dag.get(i)); + helperToJson(temp, subclass); } // lines 727-730: Removes unnecesarry parts from name of the class - String key = root.getJavaClass().toString(); - key = key.replace("", ""); + String key = nodeToString(root); // lines 732-742: inserting the root class to its subclasses into the main hashmap while // removing unnecessary substrings from the class name Iterator root_children = root.getChildren(); Set final_root_children = new HashSet<>(); while (root_children.hasNext()) { Node val = root_children.next(); - String child_name = val.getJavaClass().toString(); - child_name = child_name.replace("", ""); + String child_name = nodeToString(val); final_root_children.add(child_name); } - dag.get(0).put(key, final_root_children); + subclass.put(key, final_root_children); Gson gson = new Gson(); - return gson.toJson(dag.get(0)); + return gson.toJson(subclass); } // helper function to toJson that performs recursion to go through all of the DAG - public HashMap helper_toJson(Node n, HashMap hash) { + public void helperToJson(Node n, HashMap> hash) { // Base case of no subclasses allowing recursion to stop if (n.children.size() > 0) { // line 750 + while loop: defines iterator to go through the class's subclasses @@ -759,12 +748,9 @@ public HashMap helper_toJson(Node n, HashMap has // line 753-754: puts subclass variable into temp, and start recursion from that subclass // until base case reaches Node temp = children.next(); - helper_toJson(temp, hash); + helperToJson(temp, hash); // line 756-759: remove unnecessary substrings from class name - String key = temp.getJavaClass().toString(); - key = key.replace("", ""); + String key = nodeToString(temp); // if statement: only adds the map from class to subclass if class name does not exist in // the overall hashmap if (!hash.containsKey(key)) { @@ -775,10 +761,7 @@ public HashMap helper_toJson(Node n, HashMap has Set root = new HashSet<>(); while (val.hasNext()) { Node temp_val = val.next(); - String new_val = temp_val.getJavaClass().toString(); - new_val = new_val.replace("", ""); + String new_val = nodeToString(temp_val); root.add(new_val); } // line 774: insert into hashmap containing all class to subclass pairs @@ -788,15 +771,20 @@ public HashMap helper_toJson(Node n, HashMap has } else { // line 780-787: remove unnecessary substring from class name and map that to an empty list to // add into the hashmap - String key = n.getJavaClass().toString(); - key = key.replace("", ""); + String key = nodeToString(n); if (!hash.containsKey(key)) { - hash.put(key, n.children); + Set root = new HashSet<>(); + hash.put(key, root); } } - return hash; + } + + public String nodeToString(Node n) { + String key = n.getJavaClass().toString(); + key = key.replace("", ""); + return key; } /** From 246e59a7e6aaf373f59fa7938c48457345ff739d Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Tue, 23 Apr 2024 18:11:32 -0700 Subject: [PATCH 33/40] cleaned up code --- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 67 +++++++++++++------ 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index 8de1951884..4609533cd3 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -712,20 +712,28 @@ private void recursiveStringify(Node n, StringBuilder buffer) { * subclasses */ public Object toJson() { - // initialize variables (subclass and dag) to store important values like hashmap - // of each iteration and a list of all maps of class to subclasses + /* + * initialize variables (subclass and dag) to store important values like hashmap of each + * iteration and a list of all maps of class to subclasses + */ HashMap> subclass = new HashMap<>(); Iterator children = root.getChildren(); - // lines 717-721: Goes through all subclasses of the root class, and adds the subclass hashmap - // to the list of all subclass hashmaps + /* + * Goes through all subclasses of the root class, and adds the subclass hashmap to the + * list of all subclass hashmaps + */ while (children.hasNext()) { Node temp = children.next(); helperToJson(temp, subclass); } - // lines 727-730: Removes unnecesarry parts from name of the class + /* + * Removes unnecesarry parts from name of the class + */ String key = nodeToString(root); - // lines 732-742: inserting the root class to its subclasses into the main hashmap while - // removing unnecessary substrings from the class name + /* + * inserting the root class to its subclasses into the main hashmap while removing + * unnecessary substrings from the class name + */ Iterator root_children = root.getChildren(); Set final_root_children = new HashSet<>(); while (root_children.hasNext()) { @@ -738,25 +746,35 @@ public Object toJson() { return gson.toJson(subclass); } - // helper function to toJson that performs recursion to go through all of the DAG + /* + * helper function to toJson that performs recursion to go through all of the DAG + */ public void helperToJson(Node n, HashMap> hash) { - // Base case of no subclasses allowing recursion to stop if (n.children.size() > 0) { - // line 750 + while loop: defines iterator to go through the class's subclasses + /* + * while loop: defines iterator to go through the class's subclasses + */ Iterator children = n.getChildren(); while (children.hasNext()) { - // line 753-754: puts subclass variable into temp, and start recursion from that subclass - // until base case reaches + /* + * puts subclass variable into temp, and start recursion from that subclass + * until base case reaches + */ Node temp = children.next(); helperToJson(temp, hash); - // line 756-759: remove unnecessary substrings from class name + /* + * remove unnecessary substrings from class name + */ String key = nodeToString(temp); - // if statement: only adds the map from class to subclass if class name does not exist in - // the overall hashmap + /* + * if statement: only adds the map from class to subclass if class name does + * not exist in the overall hashmap + */ if (!hash.containsKey(key)) { - // lines 763-773: Iterates through the subclass list and removes unnecessary substrings - // from class name --> adds that new value into varibale, root, containig all it's - // subclasses + /* + * Iterates through the subclass list and removes unnecessary substrings from + * class name --> adds that new value into varibale, root, containig all it's subclasses + */ Iterator val = temp.getChildren(); Set root = new HashSet<>(); while (val.hasNext()) { @@ -764,13 +782,17 @@ public void helperToJson(Node n, HashMap> hash) { String new_val = nodeToString(temp_val); root.add(new_val); } - // line 774: insert into hashmap containing all class to subclass pairs + /* + * insert into hashmap containing all class to subclass pairs + */ hash.put(key, root); } } } else { - // line 780-787: remove unnecessary substring from class name and map that to an empty list to - // add into the hashmap + /* + * remove unnecessary substring from class name and map that to an empty + * list to add into the hashmap + */ String key = nodeToString(n); if (!hash.containsKey(key)) { Set root = new HashSet<>(); @@ -779,6 +801,9 @@ public void helperToJson(Node n, HashMap> hash) { } } + /* + * Removed unnecessary part of Node by turning it into a String + */ public String nodeToString(Node n) { String key = n.getJavaClass().toString(); key = key.replace(" Date: Thu, 25 Apr 2024 14:24:12 -0700 Subject: [PATCH 34/40] addressed comments --- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 82 +++++++------------ 1 file changed, 30 insertions(+), 52 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index 4609533cd3..03b759ba52 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -711,37 +711,29 @@ private void recursiveStringify(Node n, StringBuilder buffer) { * Puts ClassHierarchy into a JSON readable variable that maps the class to a list of its * subclasses */ - public Object toJson() { - /* - * initialize variables (subclass and dag) to store important values like hashmap of each - * iteration and a list of all maps of class to subclasses - */ + public String toJson() { + // initialize variables (subclass and dag) to store important values like hashmap of each + // iteration and a list of all maps of class to subclasses HashMap> subclass = new HashMap<>(); Iterator children = root.getChildren(); - /* - * Goes through all subclasses of the root class, and adds the subclass hashmap to the - * list of all subclass hashmaps - */ + // Goes through all subclasses of the root class, and adds the subclass hashmap to the + // list of all subclass hashmaps while (children.hasNext()) { Node temp = children.next(); helperToJson(temp, subclass); } - /* - * Removes unnecesarry parts from name of the class - */ + // Removes unnecesarry parts from name of the class String key = nodeToString(root); - /* - * inserting the root class to its subclasses into the main hashmap while removing - * unnecessary substrings from the class name - */ - Iterator root_children = root.getChildren(); - Set final_root_children = new HashSet<>(); - while (root_children.hasNext()) { - Node val = root_children.next(); + // inserting the root class to its subclasses into the main hashmap while removing + // unnecessary substrings from the class name + Iterator rootChildren = root.getChildren(); + Set finalRootChildren = new HashSet<>(); + while (rootChildren.hasNext()) { + Node val = rootChildren.next(); String child_name = nodeToString(val); - final_root_children.add(child_name); + finalRootChildren.add(child_name); } - subclass.put(key, final_root_children); + subclass.put(key, finalRootChildren); Gson gson = new Gson(); return gson.toJson(subclass); } @@ -749,50 +741,36 @@ public Object toJson() { /* * helper function to toJson that performs recursion to go through all of the DAG */ - public void helperToJson(Node n, HashMap> hash) { + private void helperToJson(Node n, HashMap> hash) { if (n.children.size() > 0) { - /* - * while loop: defines iterator to go through the class's subclasses - */ + // while loop: defines iterator to go through the class's subclasses Iterator children = n.getChildren(); while (children.hasNext()) { - /* - * puts subclass variable into temp, and start recursion from that subclass - * until base case reaches - */ + // puts subclass variable into temp, and start recursion from that subclass + // until base case reaches Node temp = children.next(); helperToJson(temp, hash); - /* - * remove unnecessary substrings from class name - */ + // remove unnecessary substrings from class name String key = nodeToString(temp); - /* - * if statement: only adds the map from class to subclass if class name does - * not exist in the overall hashmap - */ + // if statement: only adds the map from class to subclass if class name does + // not exist in the overall hashmap if (!hash.containsKey(key)) { - /* - * Iterates through the subclass list and removes unnecessary substrings from - * class name --> adds that new value into varibale, root, containig all it's subclasses - */ + // Iterates through the subclass list and removes unnecessary substrings from + // class name --> adds that new value into varibale, root, containig all it's subclasses Iterator val = temp.getChildren(); Set root = new HashSet<>(); while (val.hasNext()) { - Node temp_val = val.next(); - String new_val = nodeToString(temp_val); - root.add(new_val); + Node tempVal = val.next(); + String newVal = nodeToString(tempVal); + root.add(newVal); } - /* - * insert into hashmap containing all class to subclass pairs - */ + // insert into hashmap containing all class to subclass pairs hash.put(key, root); } } } else { - /* - * remove unnecessary substring from class name and map that to an empty - * list to add into the hashmap - */ + // remove unnecessary substring from class name and map that to an empty + // list to add into the hashmap String key = nodeToString(n); if (!hash.containsKey(key)) { Set root = new HashSet<>(); @@ -804,7 +782,7 @@ public void helperToJson(Node n, HashMap> hash) { /* * Removed unnecessary part of Node by turning it into a String */ - public String nodeToString(Node n) { + private String nodeToString(Node n) { String key = n.getJavaClass().toString(); key = key.replace(" Date: Thu, 25 Apr 2024 15:30:14 -0700 Subject: [PATCH 35/40] combined some code together to simplify code --- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index 03b759ba52..a064000711 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -712,26 +712,23 @@ private void recursiveStringify(Node n, StringBuilder buffer) { * subclasses */ public String toJson() { - // initialize variables (subclass and dag) to store important values like hashmap of each - // iteration and a list of all maps of class to subclasses + // initialize variables (subclass and dag) to store important values like hashmap of each + // iteration and a list of all maps of class to subclasses HashMap> subclass = new HashMap<>(); Iterator children = root.getChildren(); - // Goes through all subclasses of the root class, and adds the subclass hashmap to the - // list of all subclass hashmaps + // Goes through all subclasses of the root class, and adds the subclass hashmap to the + // list of all subclass hashmaps while (children.hasNext()) { - Node temp = children.next(); - helperToJson(temp, subclass); + helperToJson(children.next(), subclass); } - // Removes unnecesarry parts from name of the class + // Removes unnecesarry parts from name of the class String key = nodeToString(root); - // inserting the root class to its subclasses into the main hashmap while removing - // unnecessary substrings from the class name + // inserting the root class to its subclasses into the main hashmap while removing + // unnecessary substrings from the class name Iterator rootChildren = root.getChildren(); Set finalRootChildren = new HashSet<>(); while (rootChildren.hasNext()) { - Node val = rootChildren.next(); - String child_name = nodeToString(val); - finalRootChildren.add(child_name); + finalRootChildren.add(nodeToString(rootChildren.next())); } subclass.put(key, finalRootChildren); Gson gson = new Gson(); @@ -743,20 +740,20 @@ public String toJson() { */ private void helperToJson(Node n, HashMap> hash) { if (n.children.size() > 0) { - // while loop: defines iterator to go through the class's subclasses + // while loop: defines iterator to go through the class's subclasses Iterator children = n.getChildren(); while (children.hasNext()) { - // puts subclass variable into temp, and start recursion from that subclass - // until base case reaches + // puts subclass variable into temp, and start recursion from that subclass + // until base case reaches Node temp = children.next(); helperToJson(temp, hash); - // remove unnecessary substrings from class name + // remove unnecessary substrings from class name String key = nodeToString(temp); - // if statement: only adds the map from class to subclass if class name does - // not exist in the overall hashmap + // if statement: only adds the map from class to subclass if class name does + // not exist in the overall hashmap if (!hash.containsKey(key)) { - // Iterates through the subclass list and removes unnecessary substrings from - // class name --> adds that new value into varibale, root, containig all it's subclasses + // Iterates through the subclass list and removes unnecessary substrings from + // class name --> adds that new value into varibale, root, containig all it's subclasses Iterator val = temp.getChildren(); Set root = new HashSet<>(); while (val.hasNext()) { @@ -764,13 +761,13 @@ private void helperToJson(Node n, HashMap> hash) { String newVal = nodeToString(tempVal); root.add(newVal); } - // insert into hashmap containing all class to subclass pairs + // insert into hashmap containing all class to subclass pairs hash.put(key, root); } } } else { - // remove unnecessary substring from class name and map that to an empty - // list to add into the hashmap + // remove unnecessary substring from class name and map that to an empty + // list to add into the hashmap String key = nodeToString(n); if (!hash.containsKey(key)) { Set root = new HashSet<>(); @@ -780,7 +777,7 @@ private void helperToJson(Node n, HashMap> hash) { } /* - * Removed unnecessary part of Node by turning it into a String + * 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(); From 731deed77005226911901cb6c55f89c70b244f9f Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Mon, 20 May 2024 17:48:16 -0700 Subject: [PATCH 36/40] simplified toJson and added base case to helperToJson --- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 58 +++++++------------ 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index a064000711..e78b8ce276 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -707,67 +707,51 @@ private void recursiveStringify(Node n, StringBuilder buffer) { } } - /* - * Puts ClassHierarchy into a JSON readable variable that maps the class to a list of its - * subclasses + /** + * Converts ClassHierarchy to a JSON String, mapping each class name to a list of subclass names */ public String toJson() { - // initialize variables (subclass and dag) to store important values like hashmap of each - // iteration and a list of all maps of class to subclasses - HashMap> subclass = new HashMap<>(); + // initialize variables classNameToSubclassNames to store the pair + HashMap> classNameToSubclassNames = new HashMap<>(); Iterator children = root.getChildren(); - // Goes through all subclasses of the root class, and adds the subclass hashmap to the - // list of all subclass hashmaps + Set subclassNames = new HashSet<>(); while (children.hasNext()) { - helperToJson(children.next(), subclass); + Node temp = children.next(); + subclassNames.add(nodeToString(temp)); + helperToJson(temp, classNameToSubclassNames); } // Removes unnecesarry parts from name of the class String key = nodeToString(root); - // inserting the root class to its subclasses into the main hashmap while removing - // unnecessary substrings from the class name - Iterator rootChildren = root.getChildren(); - Set finalRootChildren = new HashSet<>(); - while (rootChildren.hasNext()) { - finalRootChildren.add(nodeToString(rootChildren.next())); - } - subclass.put(key, finalRootChildren); + // inserting the root class to its subclasses into the main hashmap + classNameToSubclassNames.put(key, subclassNames); Gson gson = new Gson(); - return gson.toJson(subclass); + return gson.toJson(classNameToSubclassNames); } - /* + /** * helper function to toJson that performs recursion to go through all of the DAG */ private void helperToJson(Node n, HashMap> hash) { + if (hash.containsKey(nodeToString(n))) { + return; + } if (n.children.size() > 0) { - // while loop: defines iterator to go through the class's subclasses Iterator children = n.getChildren(); + Set subclassNames = new HashSet<>(); while (children.hasNext()) { // puts subclass variable into temp, and start recursion from that subclass - // until base case reaches + // until base cases reaches Node temp = children.next(); helperToJson(temp, hash); // remove unnecessary substrings from class name String key = nodeToString(temp); - // if statement: only adds the map from class to subclass if class name does - // not exist in the overall hashmap + subclassNames.add(key); + if (!hash.containsKey(key)) { - // Iterates through the subclass list and removes unnecessary substrings from - // class name --> adds that new value into varibale, root, containig all it's subclasses - Iterator val = temp.getChildren(); - Set root = new HashSet<>(); - while (val.hasNext()) { - Node tempVal = val.next(); - String newVal = nodeToString(tempVal); - root.add(newVal); - } - // insert into hashmap containing all class to subclass pairs - hash.put(key, root); + hash.put(key, subclassNames); } } } else { - // remove unnecessary substring from class name and map that to an empty - // list to add into the hashmap String key = nodeToString(n); if (!hash.containsKey(key)) { Set root = new HashSet<>(); @@ -776,7 +760,7 @@ private void helperToJson(Node n, HashMap> hash) { } } - /* + /** * Removed unnecessary part of Node by turning it into a String (Made for toJson and helperToJson) */ private String nodeToString(Node n) { From e6f43dd9f9ce24618dcd4d4f5ef5cb0a326f435a Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Sun, 26 May 2024 23:08:40 -0700 Subject: [PATCH 37/40] did ./gradlew spotlessapply --- .../main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index e78b8ce276..5827e3da21 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -711,7 +711,8 @@ private void recursiveStringify(Node n, StringBuilder buffer) { * Converts ClassHierarchy to a JSON String, mapping each class name to a list of subclass names */ public String toJson() { - // initialize variables classNameToSubclassNames to store the pair + // initialize variables classNameToSubclassNames to store the pair HashMap> classNameToSubclassNames = new HashMap<>(); Iterator children = root.getChildren(); Set subclassNames = new HashSet<>(); @@ -722,15 +723,13 @@ public String toJson() { } // Removes unnecesarry parts from name of the class String key = nodeToString(root); - // inserting the root class to its subclasses into the main hashmap + // inserting the root class to its subclasses into the main hashmap classNameToSubclassNames.put(key, subclassNames); Gson gson = new Gson(); return gson.toJson(classNameToSubclassNames); } - /** - * helper function to toJson that performs recursion to go through all of the DAG - */ + /** helper function to toJson that performs recursion to go through all of the DAG */ private void helperToJson(Node n, HashMap> hash) { if (hash.containsKey(nodeToString(n))) { return; From 8eb7723f478ba0481c884cbcd87493b2818906c0 Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Wed, 5 Jun 2024 22:00:09 -0700 Subject: [PATCH 38/40] test toJson --- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index 5827e3da21..142b0b5d69 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -714,17 +714,18 @@ public String toJson() { // initialize variables classNameToSubclassNames to store the pair HashMap> classNameToSubclassNames = new HashMap<>(); - Iterator children = root.getChildren(); - Set subclassNames = new HashSet<>(); - while (children.hasNext()) { - Node temp = children.next(); - subclassNames.add(nodeToString(temp)); - helperToJson(temp, classNameToSubclassNames); - } - // Removes unnecesarry parts from name of the class - String key = nodeToString(root); - // inserting the root class to its subclasses into the main hashmap - classNameToSubclassNames.put(key, subclassNames); + // Iterator children = root.getChildren(); + // Set subclassNames = new HashSet<>(); + // while (children.hasNext()) { + // Node temp = children.next(); + // subclassNames.add(nodeToString(temp)); + // helperToJson(temp, classNameToSubclassNames); + // } + // // Removes unnecesarry parts from name of the class + // String key = nodeToString(root); + // // inserting the root class to its subclasses into the main hashmap + // classNameToSubclassNames.put(key, subclassNames); + helperToJson(root, classNameToSubclassNames); Gson gson = new Gson(); return gson.toJson(classNameToSubclassNames); } From 1595369b70cbf54002398d8bbe267789e76caa0b Mon Sep 17 00:00:00 2001 From: Aakash Gnanakumar Date: Sat, 3 Aug 2024 14:53:07 -0700 Subject: [PATCH 39/40] made test and simplified toJson --- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 50 ++++++++----------- .../tests/callGraph/ClassConstantTest.java | 30 ++++++++++- 2 files changed, 49 insertions(+), 31 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index 142b0b5d69..68d98f3030 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -711,53 +711,43 @@ private void recursiveStringify(Node n, StringBuilder buffer) { * Converts ClassHierarchy to a JSON String, mapping each class name to a list of subclass names */ public String toJson() { - // initialize variables classNameToSubclassNames to store the pair + // Initialize the map to store the pairs HashMap> classNameToSubclassNames = new HashMap<>(); - // Iterator children = root.getChildren(); - // Set subclassNames = new HashSet<>(); - // while (children.hasNext()) { - // Node temp = children.next(); - // subclassNames.add(nodeToString(temp)); - // helperToJson(temp, classNameToSubclassNames); - // } - // // Removes unnecesarry parts from name of the class - // String key = nodeToString(root); - // // inserting the root class to its subclasses into the main hashmap - // classNameToSubclassNames.put(key, subclassNames); + + // Start the recursive function from the root node helperToJson(root, classNameToSubclassNames); + + // Use Gson to convert the map to a JSON string Gson gson = new Gson(); return gson.toJson(classNameToSubclassNames); } /** helper function to toJson that performs recursion to go through all of the DAG */ private void helperToJson(Node n, HashMap> hash) { - if (hash.containsKey(nodeToString(n))) { + String key = nodeToString(n); + + // If the node is already processed, return to avoid infinite recursion + if (hash.containsKey(key)) { return; } + + // Initialize a set to store the names of the subclasses + Set subclassNames = new HashSet<>(); + + // Process all children of the current node if (n.children.size() > 0) { Iterator children = n.getChildren(); - Set subclassNames = new HashSet<>(); while (children.hasNext()) { - // puts subclass variable into temp, and start recursion from that subclass - // until base cases reaches Node temp = children.next(); helperToJson(temp, hash); - // remove unnecessary substrings from class name - String key = nodeToString(temp); - subclassNames.add(key); - if (!hash.containsKey(key)) { - hash.put(key, subclassNames); - } - } - } else { - String key = nodeToString(n); - if (!hash.containsKey(key)) { - Set root = new HashSet<>(); - hash.put(key, root); + String childKey = nodeToString(temp); + subclassNames.add(childKey); } } + + // Put the current node and its subclasses in the map + hash.put(key, subclassNames); } /** @@ -767,6 +757,8 @@ private String nodeToString(Node n) { String key = n.getJavaClass().toString(); key = key.replace("", ""); return key; } diff --git a/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java b/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java index 627b619645..4de1fd46f8 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java @@ -14,6 +14,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +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.ipa.callgraph.AnalysisCacheImpl; @@ -31,6 +34,10 @@ import com.ibm.wala.types.TypeReference; import com.ibm.wala.util.CancelException; import java.io.IOException; +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import org.junit.jupiter.api.Test; @@ -86,7 +93,26 @@ public void classHierarchyToJson() throws ClassHierarchyException, IOException { CallGraphTestUtil.makeJ2SEAnalysisScope( TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS); ClassHierarchy cha = ClassHierarchyFactory.make(scope); - Object unused = cha.toJson(); - // assertEquals("", json); + Gson gson = new Gson(); + Type type = new TypeToken>>() {}.getType(); + HashMap> list = gson.fromJson(cha.toJson(), type); + assertTrue(list.containsKey(nodeToString(cha.getRootClass().toString()))); + + Set subclassNames = new HashSet<>(); + Iterator children = cha.computeSubClasses(cha.getRootClass().getReference()).iterator(); + while (children.hasNext()) { + String temp = nodeToString(children.next().toString()); + subclassNames.add(temp); + } + assertTrue(subclassNames.containsAll(list.get(nodeToString(cha.getRootClass().toString())))); + } + + private String nodeToString(String key) { + key = key.replace("", ""); + return key; } } From b430981fadb89d963d34bb56e61e9179a255cca6 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Wed, 14 Aug 2024 22:11:04 -0700 Subject: [PATCH 40/40] better string formatting --- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 9 ++------- .../tests/callGraph/ClassConstantTest.java | 20 +++++++++---------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index 68d98f3030..efeb3670eb 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -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; @@ -754,13 +755,7 @@ private void helperToJson(Node n, HashMap> 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("", ""); - return key; + return StringStuff.jvmToBinaryName(n.getJavaClass().getName().toString()); } /** diff --git a/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java b/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java index 4de1fd46f8..6c876d1610 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java @@ -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; @@ -95,24 +96,21 @@ public void classHierarchyToJson() throws ClassHierarchyException, IOException { ClassHierarchy cha = ClassHierarchyFactory.make(scope); Gson gson = new Gson(); Type type = new TypeToken>>() {}.getType(); - HashMap> list = gson.fromJson(cha.toJson(), type); - assertTrue(list.containsKey(nodeToString(cha.getRootClass().toString()))); + String json = cha.toJson(); + System.err.println(json); + HashMap> list = gson.fromJson(json, type); + assertTrue(list.containsKey(nodeToString(cha.getRootClass()))); Set subclassNames = new HashSet<>(); Iterator 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("", ""); - return key; + private String nodeToString(IClass klass) { + return StringStuff.jvmToBinaryName(klass.getName().toString()); } }