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

COVERAGE SUMMARY FOR SOURCE FILE [MarkerTypesModel.java]

nameclass, %method, %block, %line, %
MarkerTypesModel.java100% (1/1)100% (6/6)96%  (145/151)93%  (40/43)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MarkerTypesModel100% (1/1)100% (6/6)96%  (145/151)93%  (40/43)
getWellKnownLabel (String): String 100% (1/1)70%  (14/20)57%  (4/7)
MarkerTypesModel (): void 100% (1/1)100% (7/7)100% (3/3)
getInstance (): MarkerTypesModel 100% (1/1)100% (8/8)100% (3/3)
getType (String): MarkerType 100% (1/1)100% (6/6)100% (1/1)
getTypes (): MarkerType [] 100% (1/1)100% (13/13)100% (3/3)
readTypes (): HashMap 100% (1/1)100% (97/97)100% (26/26)

1/*******************************************************************************
2 * Copyright (c) 2000, 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.views.markers.internal;
13 
14import java.util.ArrayList;
15import java.util.HashMap;
16 
17import org.eclipse.core.resources.IMarker;
18import org.eclipse.core.resources.ResourcesPlugin;
19import org.eclipse.core.runtime.IConfigurationElement;
20import org.eclipse.core.runtime.IExtension;
21import org.eclipse.core.runtime.IExtensionPoint;
22import org.eclipse.core.runtime.Platform;
23 
24/**
25 * Maintains a model of all known marker types. Accessed statically as
26 * the list does not change frequently.
27 */
28public class MarkerTypesModel {
29        
30        /**
31         * Return the singleton implementation.
32         * @return MarkerTypesModel
33         */
34        public static MarkerTypesModel getInstance(){
35                if(instance == null) {
36                        instance = new MarkerTypesModel();
37                }
38                return instance;
39        }
40 
41        static MarkerTypesModel instance;
42 
43        /**
44         * Maps from marker type id to MarkerType.
45         */
46        private HashMap types;
47 
48        /**
49         * Creates a new marker types model.
50         */
51        private MarkerTypesModel() {
52                types = readTypes();
53        }
54 
55        /**
56         * Returns the marker type with the given id, or <code>null</code> if
57         * there is no such marker type.
58         */
59        public MarkerType getType(String id) {
60                return (MarkerType) types.get(id);
61        }
62 
63        /**
64         * Returns all known marker types.
65         */
66        public MarkerType[] getTypes() {
67                MarkerType[] result = new MarkerType[types.size()];
68                types.values().toArray(result);
69                return result;
70        }
71 
72        /**
73         * Returns the label for the given marker type. Workaround until we have
74         * labels in XML.
75         */
76        private String getWellKnownLabel(String type) {
77                if (type.equals(IMarker.PROBLEM)) {
78                        return "Problem";//$NON-NLS-1$
79                }
80                if (type.equals(IMarker.TASK)) {
81                        return "Task";//$NON-NLS-1$
82                }
83                if (type.equals("org.eclipse.jdt.core.problem")) { //$NON-NLS-1$
84                        return "Java Problem";//$NON-NLS-1$
85                }
86                return type;
87        }
88 
89        /**
90         * Reads the marker types from the registry.
91         */
92        private HashMap readTypes() {
93                HashMap types = new HashMap();
94 
95                IExtensionPoint point = Platform.getExtensionRegistry()
96                                .getExtensionPoint(ResourcesPlugin.PI_RESOURCES,
97                                                ResourcesPlugin.PT_MARKERS);
98                if (point != null) {
99                        // Gather all registered marker types.
100                        IExtension[] extensions = point.getExtensions();
101                        for (int i = 0; i < extensions.length; ++i) {
102                                IExtension ext = extensions[i];
103                                String id = ext.getUniqueIdentifier();
104                                String label = ext.getLabel();
105                                if (label.equals("")) {//$NON-NLS-1$
106                                        label = getWellKnownLabel(id);
107                                }
108                                ArrayList supersList = new ArrayList();
109                                IConfigurationElement[] configElements = ext
110                                                .getConfigurationElements();
111                                for (int j = 0; j < configElements.length; ++j) {
112                                        IConfigurationElement elt = configElements[j];
113                                        if (elt.getName().equalsIgnoreCase("super")) {//$NON-NLS-1$
114                                                String sup = elt.getAttribute("type");//$NON-NLS-1$
115                                                if (sup != null) {
116                                                        supersList.add(sup);
117                                                }
118                                        }
119                                }
120                                String[] superTypes = new String[supersList.size()];
121                                supersList.toArray(superTypes);
122                                MarkerType type = new MarkerType(this, id, label, superTypes);
123                                types.put(id, type);
124                        }
125                }
126                return types;
127        }
128}

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