summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/automatedtests/util/DebugId.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/vaadin/automatedtests/util/DebugId.java')
-rw-r--r--src/com/vaadin/automatedtests/util/DebugId.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/com/vaadin/automatedtests/util/DebugId.java b/src/com/vaadin/automatedtests/util/DebugId.java
new file mode 100644
index 0000000000..8f2390933b
--- /dev/null
+++ b/src/com/vaadin/automatedtests/util/DebugId.java
@@ -0,0 +1,50 @@
+/*
+@ITMillApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.automatedtests.util;
+
+import java.io.Serializable;
+import java.util.HashMap;
+
+import com.vaadin.ui.Component;
+
+public class DebugId implements Serializable {
+
+ private static HashMap debugIds = new HashMap();
+
+ /**
+ * Generate static debug id based on package and component type. If
+ * duplicate package, component type then number of instances count is
+ * appended to debugId.
+ *
+ * @param c
+ */
+ public static void set(Component c, String description) {
+ String debugId = "";
+
+ // add package name
+ StackTraceElement[] st = new Throwable().fillInStackTrace()
+ .getStackTrace();
+ try {
+ debugId += st[3].getClassName();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // add component type
+ debugId += c.getClass();
+
+ // add given description
+ debugId += description;
+
+ if (debugIds.containsKey(debugId)) {
+ int count = ((Integer) debugIds.get(debugId)).intValue();
+ count++;
+ debugIds.put(debugId, new Integer(count));
+ debugId = debugId + "-" + count;
+ }
+
+ c.setDebugId(debugId);
+ }
+}