ProjectClassesInstanceFilter implements CaptureObjectInstanceFilter { @Override public Set<InstanceObject> filter(@NotNull Set<InstanceObject> instances, @NotNull ClassDb classDatabase) { Set<String> projectClasses = myIdeProfilerServices.getAllProjectClasses(); return instances.stream().filter(instance -> { String className = instance.getClassEntry().getClassName(); int innerClassStartIndex = className.indexOf("$"); if (innerClassStartIndex != -1) { className = className.substring(0, innerClassStartIndex); } return projectClasses.contains(className); }).collect(Collectors.toSet()); } ProjectClassesInstanceFilter(@NotNull IdeProfilerServices profilerServices); @NotNull @Override String getDisplayName(); @NotNull @Override String getSummaryDescription(); @Nullable @Override String getDetailedDescription(); @Nullable @Override String getDocumentationLink(); @Override Set<InstanceObject> filter(@NotNull Set<InstanceObject> instances, @NotNull ClassDb classDatabase);  }
@Test public void testFilter() { FakeIdeProfilerServices ideServices = new FakeIdeProfilerServices(); ideServices.addProjectClasses("my.foo.bar", "your.bar.foo"); String matchedClass = "my.foo.bar"; String matchedInnerClass = "your.bar.foo$1"; String mismatchedClass = "my.bar"; String mismatchedInnerClass = "your.foo$1"; FakeCaptureObject capture = new FakeCaptureObject.Builder().build(); FakeInstanceObject matchedClassInstance = new FakeInstanceObject.Builder(capture, 1, matchedClass).build(); FakeInstanceObject matchedInnerClassInstance = new FakeInstanceObject.Builder(capture, 2, matchedInnerClass).build(); FakeInstanceObject mismatchedClassInstance = new FakeInstanceObject.Builder(capture, 3, mismatchedClass).build(); FakeInstanceObject mismatchedInnerClassInstance = new FakeInstanceObject.Builder(capture, 4, mismatchedInnerClass).build(); Set<InstanceObject> instances = ImmutableSet.of(matchedClassInstance, matchedInnerClassInstance, mismatchedClassInstance, mismatchedInnerClassInstance); ProjectClassesInstanceFilter filter = new ProjectClassesInstanceFilter(ideServices); Set<InstanceObject> result = filter.filter(instances, capture.getClassDatabase()); assertThat(result).containsExactly(matchedClassInstance, matchedInnerClassInstance); }