Source Code Cross Referenced for AnnotationTypeLookup.java in  » IDE-Eclipse » ui » org » eclipse » ui » texteditor » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » ui » org.eclipse.ui.texteditor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2005 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.texteditor;
011:
012:        import java.util.ArrayList;
013:        import java.util.HashMap;
014:        import java.util.List;
015:        import java.util.Map;
016:
017:        import org.eclipse.core.resources.IMarker;
018:        import org.eclipse.core.runtime.IConfigurationElement;
019:        import org.eclipse.core.runtime.IExtensionPoint;
020:        import org.eclipse.core.runtime.Platform;
021:
022:        import org.eclipse.jface.resource.StringConverter;
023:
024:        import org.eclipse.ui.editors.text.EditorsUI;
025:
026:        /**
027:         * Provides the strategy for determining annotation types for given markers.
028:         *
029:         * @since 3.0
030:         */
031:        public final class AnnotationTypeLookup {
032:
033:            /**
034:             * Record representing an annotation type mapping.
035:             */
036:            private static class AnnotationTypeMapping {
037:
038:                final static int UNDEFINED = -1;
039:
040:                String fAnnotationType;
041:                String fMarkerType;
042:                int fMarkerSeverity = UNDEFINED;
043:
044:                boolean isMarkerSeverityDefined() {
045:                    return fMarkerSeverity != UNDEFINED;
046:                }
047:            }
048:
049:            /** The lookup table for marker to annotation type mappings. */
050:            private Map fMapping;
051:
052:            /**
053:             * Creates a new annotation lookup object.
054:             */
055:            public AnnotationTypeLookup() {
056:            }
057:
058:            /**
059:             * Computes the annotation type that corresponds to the state of
060:             * the given marker.
061:             *
062:             * @param marker the marker
063:             * @return the annotation type or <code>null</code>
064:             */
065:            public String getAnnotationType(IMarker marker) {
066:                String markerType = MarkerUtilities.getMarkerType(marker);
067:                if (markerType != null) {
068:                    int severity = MarkerUtilities.getSeverity(marker);
069:                    return getAnnotationType(markerType, severity);
070:                }
071:                return null;
072:            }
073:
074:            /**
075:             * Computes the annotation type that corresponds to the given marker type and
076:             * the given marker severity.
077:             *
078:             * @param markerType the marker type
079:             * @param markerSeverity the marker severity
080:             * @return the annotation type or <code>null</code>
081:             */
082:            public String getAnnotationType(String markerType,
083:                    int markerSeverity) {
084:                String annotationType = lookupAnnotationType(markerType,
085:                        markerSeverity);
086:                if (annotationType != null)
087:                    return annotationType;
088:                String[] super Types = MarkerUtilities.getSuperTypes(markerType);
089:                for (int i = 0; i < super Types.length; i++) {
090:                    annotationType = lookupAnnotationType(super Types[i],
091:                            markerSeverity);
092:                    if (annotationType != null)
093:                        return annotationType;
094:                }
095:                return null;
096:            }
097:
098:            /**
099:             * Returns the annotation type for the given marker type and the given
100:             * marker severity.
101:             *
102:             * @param markerType the marker type
103:             * @param severity the marker severity
104:             * @return the annotation type
105:             */
106:            private String lookupAnnotationType(String markerType, int severity) {
107:                if (fMapping == null)
108:                    initializeMapping();
109:
110:                Object value = fMapping.get(markerType);
111:
112:                if (value instanceof  String)
113:                    return (String) value;
114:
115:                if (value instanceof  Map) {
116:                    Map severityMap = (Map) value;
117:                    return (String) severityMap.get(new Integer(severity));
118:                }
119:
120:                return null;
121:            }
122:
123:            /**
124:             * Initializes the mapping between markers and their property values and
125:             * annotation types.
126:             */
127:            private void initializeMapping() {
128:                fMapping = new HashMap();
129:                List mappings = getAnnotationTypeMappings();
130:                for (int i = 0, l = mappings.size(); i < l; i++) {
131:                    AnnotationTypeMapping atm = (AnnotationTypeMapping) mappings
132:                            .get(i);
133:                    if (atm.isMarkerSeverityDefined()) {
134:                        Object severityMap = fMapping.get(atm.fMarkerType);
135:                        if (!(severityMap instanceof  Map)) {
136:                            severityMap = new HashMap();
137:                            fMapping.put(atm.fMarkerType, severityMap);
138:                        }
139:                        Map map = (Map) severityMap;
140:                        map.put(new Integer(atm.fMarkerSeverity),
141:                                atm.fAnnotationType);
142:                    } else {
143:                        fMapping.put(atm.fMarkerType, atm.fAnnotationType);
144:                    }
145:                }
146:            }
147:
148:            /**
149:             * Returns the list of annotation type mappings generated from the
150:             * extensions provided for the annotation type extension point.
151:             *
152:             * @return a list of annotation type mappings
153:             */
154:            private List getAnnotationTypeMappings() {
155:                List annotationTypeMappings = new ArrayList();
156:                // read compatibility mode
157:                readExtensionPoint(annotationTypeMappings,
158:                        "markerAnnotationSpecification", "annotationType"); //$NON-NLS-1$ //$NON-NLS-2$
159:                // read new extension point
160:                readExtensionPoint(annotationTypeMappings,
161:                        "annotationTypes", "name"); //$NON-NLS-1$ //$NON-NLS-2$
162:                return annotationTypeMappings;
163:            }
164:
165:            /**
166:             * Reads the extensions provided for the given extension point name. Uses
167:             * the given type attribute name to create annotation type mappings that
168:             * are appended to the given list.
169:             *
170:             * @param annotationTypeMappings the list to be populated
171:             * @param extensionPointName the name of the extension point to read
172:             * @param typeAttributeName the name of attribute specifying the annotation
173:             *            type
174:             */
175:            private void readExtensionPoint(List annotationTypeMappings,
176:                    String extensionPointName, String typeAttributeName) {
177:                IExtensionPoint extensionPoint = Platform
178:                        .getExtensionRegistry().getExtensionPoint(
179:                                EditorsUI.PLUGIN_ID, extensionPointName);
180:                if (extensionPoint != null) {
181:                    IConfigurationElement[] elements = extensionPoint
182:                            .getConfigurationElements();
183:                    for (int i = 0; i < elements.length; i++) {
184:                        AnnotationTypeMapping mapping = createMapping(
185:                                elements[i], typeAttributeName);
186:                        if (mapping != null)
187:                            annotationTypeMappings.add(mapping);
188:                    }
189:                }
190:            }
191:
192:            /**
193:             * Creates an annotation type mapping from the given configuration element.
194:             *
195:             * @param element the configuration element
196:             * @param typeAttributeName the name of the attribute specifying the
197:             *            annotation type
198:             * @return the annotation type mapping or <code>null</code>
199:             */
200:            private AnnotationTypeMapping createMapping(
201:                    IConfigurationElement element, String typeAttributeName) {
202:
203:                AnnotationTypeMapping mapping = new AnnotationTypeMapping();
204:
205:                String s = element.getAttribute(typeAttributeName);
206:                if (s == null || s.trim().length() == 0)
207:                    return null;
208:                mapping.fAnnotationType = s;
209:
210:                s = element.getAttribute("markerType"); //$NON-NLS-1$
211:                if (s == null || s.trim().length() == 0)
212:                    return null;
213:                mapping.fMarkerType = s;
214:
215:                s = element.getAttribute("markerSeverity"); //$NON-NLS-1$
216:                if (s != null && s.trim().length() > 0)
217:                    mapping.fMarkerSeverity = StringConverter.asInt(s,
218:                            AnnotationTypeMapping.UNDEFINED);
219:
220:                return mapping;
221:            }
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.