Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SourceUnit |
|
| 1.25;1.25 |
1 | /* $Id: SourceUnit.java 17868 2010-01-12 20:47:51Z linus $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * tfmorris | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 2005-2006 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.uml.generator; | |
40 | ||
41 | /** | |
42 | * Information about a source unit and its content, whether | |
43 | * it exists only in memory or it's stored in a file. | |
44 | * | |
45 | * TODO: Making this an interface instead of a class would allow | |
46 | * more flexibility in dealing with non-file-based resources. - tfm | |
47 | * | |
48 | * @author aslo | |
49 | */ | |
50 | public class SourceUnit { | |
51 | /** | |
52 | * The file seperator for this operating system. | |
53 | */ | |
54 | 0 | public static final String FILE_SEPARATOR = |
55 | System.getProperty("file.separator"); | |
56 | ||
57 | private Language language; | |
58 | private String name; | |
59 | private String basePath; | |
60 | private String content; | |
61 | ||
62 | /** | |
63 | * @param theName Name of the unit. | |
64 | * @param path The path relative to the project source path. | |
65 | * @param theContent The source code of the unit. | |
66 | */ | |
67 | 0 | public SourceUnit(String theName, String path, String theContent) { |
68 | 0 | setName(theName); |
69 | 0 | setBasePath(path); |
70 | 0 | this.content = theContent; |
71 | 0 | } |
72 | ||
73 | /** | |
74 | * @param fullName Name with path relative to the project source path. | |
75 | * @param theContent The source code of the unit. | |
76 | */ | |
77 | 0 | public SourceUnit(String fullName, String theContent) { |
78 | 0 | setFullName(fullName); |
79 | 0 | content = theContent; |
80 | 0 | } |
81 | ||
82 | /** | |
83 | * @return Returns the source code of the unit. | |
84 | */ | |
85 | public String getContent() { | |
86 | 0 | return content; |
87 | } | |
88 | ||
89 | /** | |
90 | * @param theContent The source code for this unit. | |
91 | */ | |
92 | public void setContent(String theContent) { | |
93 | 0 | this.content = theContent; |
94 | 0 | } |
95 | ||
96 | /** | |
97 | * @return Returns the file name of this unit, without path. | |
98 | */ | |
99 | public String getName() { | |
100 | 0 | return name; |
101 | } | |
102 | ||
103 | /** | |
104 | * @param filename The file name of this unit, without path. | |
105 | */ | |
106 | public void setName(String filename) { | |
107 | 0 | int sep = filename.lastIndexOf(FILE_SEPARATOR); |
108 | 0 | if (sep >= 0) { |
109 | 0 | name = filename.substring(sep + FILE_SEPARATOR.length()); |
110 | } else { | |
111 | 0 | name = filename; |
112 | } | |
113 | 0 | } |
114 | ||
115 | /** | |
116 | * @return Returns The base path of the unit (relative to the | |
117 | * project source path). | |
118 | */ | |
119 | public String getBasePath() { | |
120 | 0 | return basePath; |
121 | } | |
122 | ||
123 | /** | |
124 | * @param path The base path of the unit (relative to the | |
125 | * project source path). | |
126 | */ | |
127 | public void setBasePath(String path) { | |
128 | 0 | if (path.endsWith(FILE_SEPARATOR)) { |
129 | 0 | basePath = |
130 | path.substring(0, path.length() - FILE_SEPARATOR.length()); | |
131 | } else { | |
132 | 0 | basePath = path; |
133 | } | |
134 | 0 | } |
135 | ||
136 | /** | |
137 | * @return Returns The name with path of the unit (relative to the | |
138 | * project source path). | |
139 | */ | |
140 | public String getFullName() { | |
141 | 0 | return basePath + System.getProperty("file.separator") + name; |
142 | } | |
143 | ||
144 | /** | |
145 | * @param path The full name (with path) of the unit, relative to the | |
146 | * project source path. | |
147 | */ | |
148 | public void setFullName(String path) { | |
149 | 0 | int sep = path.lastIndexOf(FILE_SEPARATOR); |
150 | 0 | if (sep >= 0) { |
151 | 0 | basePath = path.substring(0, sep); |
152 | 0 | name = path.substring(sep + FILE_SEPARATOR.length()); |
153 | } else { | |
154 | 0 | basePath = ""; |
155 | 0 | name = path; |
156 | } | |
157 | 0 | } |
158 | ||
159 | /** | |
160 | * @return Returns the language. | |
161 | */ | |
162 | public Language getLanguage() { | |
163 | 0 | return language; |
164 | } | |
165 | ||
166 | /** | |
167 | * @param lang The language to set. | |
168 | */ | |
169 | public void setLanguage(Language lang) { | |
170 | 0 | this.language = lang; |
171 | 0 | } |
172 | ||
173 | } |