Skip to content

Commit

Permalink
Compare two objects in Variable View #531
Browse files Browse the repository at this point in the history
This commit provides a new feature to compare elements of commonly used
objects of similar types like Map, HashMap, LinkedHashMap,
ConcurrentHashMap, Hashtable , IdentityHashMap, WeakHashMap, TreeMap,
List, ArrayList, Stack, Vector, LinkedList, HashSet, LinkedHashSet,
TreeSet, CopyOnWriteArraySet, Arrays, Wrappers and custom objects from
Variables view and display differences of both in either diff viewer or
dialog box.

Fixes eclipse-platform/eclipse.platform#531
  • Loading branch information
SougandhS committed Jan 6, 2025
1 parent 8a20637 commit 07e4a83
Show file tree
Hide file tree
Showing 17 changed files with 2,884 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package compare;
import java.util.*;
public class CompareArrayObjects {
public static void main(String[] ecs) {
String[] args2 = {"asdasd","asdasd"};
String[] args1 = {"asdasd","asdasd"};

Integer[] args11 = {1,2};
Integer[] args12 = {2,3};
int p = 100;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package compare;

import java.util.*;

public class CompareListObjects {
public static void main(String[] ecs) {
List<String> s1 = new ArrayList<>(Arrays.asList("apple", "banana"));
List<String> s2 = new ArrayList<>(Arrays.asList("banana", "apple"));
List<String> s3 = new ArrayList<>(Arrays.asList("apple", "banana"));
List<String> s4 = new ArrayList<>(Arrays.asList("apple1", "banana"));

List<Integer> linkedList1 = new LinkedList<>();
linkedList1.add(22);
linkedList1.add(12);
List<Integer> linkedList2 = new LinkedList<>();
linkedList2.add(12);
linkedList2.add(221);

List<String> Stack = new Stack<>();
Stack.add("Cherry");
Stack.add("Banana");
Stack.add("Apple");
List<String> ArrayList = new ArrayList<>();
ArrayList.add("Apple");
ArrayList.add("Banana");
ArrayList.add("Cherry");
List<String> Vector = new Vector<>();
Vector.add("Banana");
Vector.add("Cherry");
Vector.add("Apple");
List<String> LinkedList = new LinkedList<>();
LinkedList.add("Apple");
LinkedList.add("Cherry");

int p = 100;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package compare;
import java.util.*;
public class CompareMapObjects {
public static void main(String[] ecs) {
Map<Integer, Integer> map8 = new TreeMap<>();
map8.put(1, 4);
Map<Integer, Integer> map9 = new TreeMap<>();
map9.put(12, 4);
Map<Integer, Integer> map2 = new HashMap<>();
map2.put(1, 7);
Map<Integer, Integer> map1 = new HashMap<>();
map1.put(1, 7);

Map<String, Double> map4 = new WeakHashMap<>();
map4.put("key1", 17d);
Map<String, Double> map5 = new WeakHashMap<>();
map5.put("key1", 7d);

Map<String, Double> map6 = new IdentityHashMap<>();
map6.put("key1", 7d);
Map<String, Double> map7 = new IdentityHashMap<>();
map7.put("key2", 8d);
int p = 100;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package compare;
import java.util.*;

class A {
public int custom;
public A(int custom) {
this.custom = custom;
}
}
public class CompareNormalObjects {
public static void main(String[] ecs) {
A a1 = new A(1);
A a2 = new A(2);
A a3 = a1;
Integer i1 = Integer.valueOf(10);
Integer i2 = Integer.valueOf(10);
Float f1 = Float.valueOf(12f);
Float f2 = Float.valueOf(112f);
int p = 100;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package compare;

public class CompareObjectsStringTest {
public static void main(String[] ecs) {
String s1 = new String("eclipse");
String s2 = new String("eclipse");

String s3 = "false1";
String s4 = "false";

StringBuffer s5 = new StringBuffer("SDK");
StringBuffer s6 = new StringBuffer("SDK");

StringBuilder s7 = new StringBuilder("Java");
StringBuffer s8 = new StringBuffer("Java");

StringBuilder s9 = new StringBuilder("Java1");
int p = 100;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package compare;
import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet;
public class CompareSetObjects {
public static void main(String[] ecs) {
TreeSet<Integer> xx11 = new TreeSet<>();
xx11.add(1);
xx11.add(2);
TreeSet<Integer> xx22 = new TreeSet<>();
xx22.add(1);
xx22.add(21);
Set<Integer> hashS1 = new HashSet<>();
Set<Integer> hashS2 = new HashSet<>();
hashS1.add(1);
hashS1.add(21);
hashS2.add(1);
hashS2.add(21);

Set<Integer> linkedHashS1 = new LinkedHashSet<>();
Set<Integer> linkedHashS2 = new LinkedHashSet<>();
linkedHashS1.add(1);
linkedHashS1.add(21);
linkedHashS2.add(1);
linkedHashS2.add(2);

Set<String> xx1 = new CopyOnWriteArraySet<>();
xx1.add("one");
xx1.add("two");
Set<String> xx2 = new CopyOnWriteArraySet<>();
xx2.add("two");
xx2.add("one");
int p = 100;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2024 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -204,7 +204,8 @@ public abstract class AbstractDebugTest extends TestCase implements IEvaluation
"StepResult2", "StepResult3", "StepUncaught", "TriggerPoint_01", "BulkThreadCreationTest", "MethodExitAndException",
"Bug534319earlyStart", "Bug534319lateStart", "Bug534319singleThread", "Bug534319startBetwen", "MethodCall", "Bug538303", "Bug540243",
"OutSync", "OutSync2", "ConsoleOutputUmlaut", "ErrorRecurrence", "ModelPresentationTests", "Bug565982",
"SuspendVMConditionalBreakpointsTestSnippet", "FileConditionSnippet2" };
"SuspendVMConditionalBreakpointsTestSnippet", "FileConditionSnippet2", "compare.CompareObjectsStringTest", "compare.CompareListObjects",
"compare.CompareMapObjects", "compare.CompareSetObjects", "compare.CompareNormalObjects", "compare.CompareArrayObjects" };

/**
* the default timeout
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2024 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -153,6 +153,7 @@
import org.eclipse.jdt.debug.tests.ui.VirtualThreadsDebugViewTests;
import org.eclipse.jdt.debug.tests.ui.presentation.ModelPresentationTests;
import org.eclipse.jdt.debug.tests.ui.presentation.ModelPresentationTests18;
import org.eclipse.jdt.debug.tests.variables.CompareObjectsTest;
import org.eclipse.jdt.debug.tests.variables.DetailFormatterTests;
import org.eclipse.jdt.debug.tests.variables.TestAnonymousInspect;
import org.eclipse.jdt.debug.tests.variables.TestInstanceRetrieval;
Expand Down Expand Up @@ -397,6 +398,7 @@ public AutomatedSuite() {
addTest(new TestSuite(TriggerPointBreakpointsTests.class));
addTest(new TestSuite(JavaThreadEventHandlerTests.class));
addTest(new TestSuite(ConditionalBreakpointsWithFileClass.class));
addTest(new TestSuite(CompareObjectsTest.class));

if (JavaProjectHelper.isJava8Compatible()) {
addTest(new TestSuite(TestToggleBreakpointsTarget8.class));
Expand Down
Loading

0 comments on commit 07e4a83

Please sign in to comment.