EMMA Coverage Report (generated Mon Sep 29 15:05:28 EDT 2008)
[all classes][org.eclipse.ui.internal.tweaklets]

COVERAGE SUMMARY FOR SOURCE FILE [Tweaklets.java]

nameclass, %method, %block, %line, %
Tweaklets.java100% (2/2)78%  (7/9)49%  (78/160)53%  (26.5/50)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Tweaklets$TweakKey100% (1/1)67%  (2/3)37%  (23/62)37%  (7.9/21)
equals (Object): boolean 0%   (0/1)0%   (0/37)0%   (0/13)
hashCode (): int 100% (1/1)89%  (17/19)97%  (4.9/5)
Tweaklets$TweakKey (Class): void 100% (1/1)100% (6/6)100% (3/3)
     
class Tweaklets100% (1/1)83%  (5/6)56%  (55/98)64%  (18.7/29)
Tweaklets (): void 0%   (0/1)0%   (0/3)0%   (0/1)
createTweaklet (Tweaklets$TweakKey): Object 100% (1/1)25%  (13/53)33%  (4.9/15)
<static initializer> 100% (1/1)100% (9/9)100% (3/3)
get (Tweaklets$TweakKey): Object 100% (1/1)100% (23/23)100% (8/8)
getDefault (Tweaklets$TweakKey): Object 100% (1/1)100% (4/4)100% (1/1)
setDefault (Tweaklets$TweakKey, Object): void 100% (1/1)100% (6/6)100% (2/2)

1/*******************************************************************************
2 * Copyright (c) 2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *     IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 
12package org.eclipse.ui.internal.tweaklets;
13 
14import java.util.HashMap;
15import java.util.Map;
16 
17import org.eclipse.core.runtime.Assert;
18import org.eclipse.core.runtime.CoreException;
19import org.eclipse.core.runtime.IConfigurationElement;
20import org.eclipse.core.runtime.IStatus;
21import org.eclipse.core.runtime.Platform;
22import org.eclipse.ui.internal.misc.StatusUtil;
23import org.eclipse.ui.statushandlers.StatusManager;
24 
25/**
26 * @since 3.3
27 * 
28 */
29public class Tweaklets {
30        
31        public static class TweakKey {
32                Class tweakClass;
33 
34                /**
35                 * @param tweakClass
36                 */
37                public TweakKey(Class tweakClass) {
38                        this.tweakClass = tweakClass;
39                }
40 
41                /* (non-Javadoc)
42                 * @see java.lang.Object#hashCode()
43                 */
44                public int hashCode() {
45                        final int prime = 31;
46                        int result = 1;
47                        result = prime * result
48                                        + ((tweakClass == null) ? 0 : tweakClass.hashCode());
49                        return result;
50                }
51 
52                /* (non-Javadoc)
53                 * @see java.lang.Object#equals(java.lang.Object)
54                 */
55                public boolean equals(Object obj) {
56                        if (this == obj)
57                                return true;
58                        if (obj == null)
59                                return false;
60                        if (getClass() != obj.getClass())
61                                return false;
62                        final TweakKey other = (TweakKey) obj;
63                        if (tweakClass == null) {
64                                if (other.tweakClass != null)
65                                        return false;
66                        } else if (!tweakClass.equals(other.tweakClass))
67                                return false;
68                        return true;
69                }
70        }
71 
72        private static Map defaults = new HashMap();
73        private static Map tweaklets = new HashMap();
74 
75        public static void setDefault(TweakKey definition, Object implementation) {
76                defaults.put(definition, implementation);
77        }
78        
79        public static Object get(TweakKey definition) {
80                Object result = tweaklets.get(definition);
81                if (result == null) {
82                        result = createTweaklet(definition);
83                        if (result == null) {
84                                result = getDefault(definition);
85                        }
86                        Assert.isNotNull(result);
87                        tweaklets.put(definition, result);
88                }
89                return result;
90        }
91 
92        /**
93         * @param definition
94         * @return
95         */
96        private static Object getDefault(TweakKey definition) {
97                return defaults.get(definition);
98        }
99 
100        /**
101         * @param definition
102         * @return
103         */
104        private static Object createTweaklet(TweakKey definition) {
105                IConfigurationElement[] elements = Platform
106                                .getExtensionRegistry()
107                                .getConfigurationElementsFor("org.eclipse.ui.internalTweaklets"); //$NON-NLS-1$
108                for (int i = 0; i < elements.length; i++) {
109                        if (definition.tweakClass.getName().equals(
110                                        elements[i].getAttribute("definition"))) { //$NON-NLS-1$
111                                try {
112                                        Object tweaklet = elements[i].createExecutableExtension("implementation"); //$NON-NLS-1$
113                                        tweaklets.put(definition, tweaklet);
114                                        return tweaklet;
115                                } catch (CoreException e) {
116                                        StatusManager.getManager().handle(
117                                                        StatusUtil.newStatus(IStatus.ERROR,
118                                                                        "Error with extension " + elements[i], e), //$NON-NLS-1$
119                                                        StatusManager.LOG);
120                                }
121                        }
122                }
123                return null;
124        }
125 
126}

[all classes][org.eclipse.ui.internal.tweaklets]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov