Clover coverage report - PMD - 3.9 Coverage timestamp: Tue Dec 19 2006 09:38:44 EST FRAMES NO FRAMES |
file stats: | LOC: | 82 |  | Methods: | 6
| NCLOC: | 35 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
SourceTypeDiscoverer.java | 100% | 100% | 100% | 100% |

1 |  | package net.sourceforge.pmd;
2 |  |
3 |  | import java.io.File;
4 |  | import java.util.HashMap;
5 |  | import java.util.Map;
6 |  |
7 |  | /**
8 |  | * This class can give the SourceType of a source file.
9 |  | *
10 |  | * @author pieter_van_raemdonck - Application Engineers NV/SA - www.ae.be
11 |  | */
12 |  | public class SourceTypeDiscoverer {
13 |  |
14 |  | /**
15 |  | * Map of (upper-case) file name extensions on the appropriate SourceType
16 |  | * object.
17 |  | */
18 |  | private Map mapExtensionOnSourceType = new HashMap();
19 |  |
20 |  | /**
21 |  | * Public constructor.
22 |  | */
23 | 1263 | public SourceTypeDiscoverer() {
24 | 1263 | initialize();
25 |  | }
26 |  |
27 |  | /**
28 |  | * Initialization of mapExtensionOnSourceType.
29 |  | */
30 | 1263 | private void initialize() {
31 | 1263 | mapExtensionOnSourceType.put(SourceFileConstants.JSP_EXTENSION_UPPERCASE, SourceType.JSP);
32 | 1263 | mapExtensionOnSourceType.put(SourceFileConstants.JSPX_EXTENSION_UPPERCASE, SourceType.JSP);
33 |  |
34 |  | // TODO: Do we want a default ??
35 | 1263 | mapExtensionOnSourceType.put(SourceFileConstants.JAVA_EXTENSION_UPPERCASE, SourceType.JAVA_14);
36 |  | }
37 |  |
38 |  | /**
39 |  | * Get the SourceType of a given source file.
40 |  | *
41 |  | * @param sourceFile The File
42 |  | * @return a SourceType
43 |  | */
44 | 3 | public SourceType getSourceTypeOfFile(File sourceFile) {
45 | 3 | String fileName = sourceFile.getName();
46 | 3 | return getSourceTypeOfFile(fileName);
47 |  | }
48 |  |
49 |  | /**
50 |  | * Get the SourceType of a source file with given name.
51 |  | *
52 |  | * @param fileName The File
53 |  | * @return a SourceType ; null if the fileName is not recognized as a supported source type.
54 |  | */
55 | 6 | public SourceType getSourceTypeOfFile(String fileName) {
56 | 6 | SourceType sourceType = null;
57 |  |
58 | 6 | int extensionIndex = 1 + fileName.lastIndexOf('.');
59 | 6 | if (extensionIndex > 0) {
60 | 3 | String extensionUppercase = fileName.substring(extensionIndex).toUpperCase();
61 |  |
62 | 3 | sourceType = (SourceType) mapExtensionOnSourceType
63 |  | .get(extensionUppercase);
64 |  | }
65 |  |
66 | 6 | return sourceType;
67 |  | }
68 |  |
69 |  | /**
70 |  | * Set the SourceType of files with ".java" extension. This chooses the Java
71 |  | * version.
72 |  | *
73 |  | * @param sourceType the wanted SourceType
74 |  | */
75 | 1257 | public void setSourceTypeOfJavaFiles(SourceType sourceType) {
76 | 1257 | mapExtensionOnSourceType.put(SourceFileConstants.JAVA_EXTENSION_UPPERCASE, sourceType);
77 |  | }
78 |  |
79 | 3 | public SourceType getSourceTypeOfJavaFiles() {
80 | 3 | return (SourceType) mapExtensionOnSourceType.get(SourceFileConstants.JAVA_EXTENSION_UPPERCASE);
81 |  | }
82 |  | }