Skip to content

Commit bb2e7df

Browse files
Perform clean code of runtime/bundles/org.eclipse.core.contenttype
1 parent 2d1c1e2 commit bb2e7df

20 files changed

+513
-267
lines changed

runtime/bundles/org.eclipse.core.contenttype/src/org/eclipse/core/internal/content/ContentDescription.java

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,78 +35,95 @@ public ContentDescription(QualifiedName[] requested, IContentTypeInfo contentTyp
3535
if (requested.length > 1) {
3636
keys = requested;
3737
values = new Object[requested.length];
38-
} else if (requested.length == 1)
38+
} else if (requested.length == 1) {
3939
keys = requested[0];
4040
// if requested.length == 0 then keys == null (no options to describe!)
41+
}
4142
}
4243

4344
private void assertMutable() {
44-
if ((flags & FLAG_IMMUTABLE) != 0)
45+
if ((flags & FLAG_IMMUTABLE) != 0) {
4546
throw new IllegalStateException("Content description is immutable"); //$NON-NLS-1$
47+
}
4648
}
4749

4850
@Override
4951
public String getCharset() {
5052
byte[] bom = (byte[]) getProperty(BYTE_ORDER_MARK);
51-
if (bom == BOM_UTF_8)
53+
if (bom == BOM_UTF_8) {
5254
return CHARSET_UTF_8;
53-
else if (bom == BOM_UTF_16BE || bom == BOM_UTF_16LE)
55+
} else if (bom == BOM_UTF_16BE || bom == BOM_UTF_16LE) {
5456
// UTF-16 will properly recognize the BOM
5557
return CHARSET_UTF_16;
58+
}
5659
return (String) getProperty(CHARSET);
5760
}
5861

5962
private Object getDescribedProperty(QualifiedName key) {
6063
// no values have been set
61-
if (values == null)
64+
if (values == null) {
6265
return null;
66+
}
6367
// a single property may have been set
64-
if (keys instanceof QualifiedName)
68+
if (keys instanceof QualifiedName) {
6569
return keys.equals(key) ? values : null;
70+
}
6671
// multiple properties may have been set
6772
QualifiedName[] tmpKeys = (QualifiedName[]) this.keys;
68-
for (int i = 0; i < tmpKeys.length; i++)
69-
if (tmpKeys[i].equals(key))
73+
for (int i = 0; i < tmpKeys.length; i++) {
74+
if (tmpKeys[i].equals(key)) {
7075
return ((Object[]) values)[i];
76+
}
77+
}
7178
return null;
7279
}
7380

7481
@Override
7582
public Object getProperty(QualifiedName key) {
7683
Object describedProperty = getDescribedProperty(key);
77-
if (describedProperty != null)
84+
if (describedProperty != null) {
7885
return describedProperty;
86+
}
7987
return contentTypeInfo.getDefaultProperty(key);
8088
}
8189

8290
@Override
8391
public boolean isRequested(QualifiedName propertyKey) {
8492
// all options requested
85-
if ((flags & FLAG_ALL_OPTIONS) != 0)
93+
if ((flags & FLAG_ALL_OPTIONS) != 0) {
8694
return true;
95+
}
8796
// no options requested
88-
if (keys == null)
97+
if (keys == null) {
8998
return false;
99+
}
90100
// a single option requested
91-
if (keys instanceof QualifiedName)
101+
if (keys instanceof QualifiedName) {
92102
return keys.equals(propertyKey);
103+
}
93104
// some (but not all) options requested
94105
QualifiedName[] tmpKeys = (QualifiedName[]) this.keys;
95-
for (QualifiedName tmpKey : tmpKeys)
96-
if (tmpKey.equals(propertyKey))
106+
for (QualifiedName tmpKey : tmpKeys) {
107+
if (tmpKey.equals(propertyKey)) {
97108
return true;
109+
}
110+
}
98111
return false;
99112
}
100113

101114
boolean isSet() {
102-
if (keys == null || values == null)
115+
if (keys == null || values == null) {
103116
return false;
104-
if (keys instanceof QualifiedName)
117+
}
118+
if (keys instanceof QualifiedName) {
105119
return true;
120+
}
106121
Object[] tmpValues = (Object[]) this.values;
107-
for (Object tmpValue : tmpValues)
108-
if (tmpValue != null)
122+
for (Object tmpValue : tmpValues) {
123+
if (tmpValue != null) {
109124
return true;
125+
}
126+
}
110127
return false;
111128
}
112129

@@ -142,13 +159,15 @@ public void setProperty(QualifiedName newKey, Object newValue) {
142159
return;
143160
}
144161
QualifiedName[] tmpKeys = (QualifiedName[]) this.keys;
145-
for (int i = 0; i < tmpKeys.length; i++)
162+
for (int i = 0; i < tmpKeys.length; i++) {
146163
if (tmpKeys[i].equals(newKey)) {
147164
((Object[]) values)[i] = newValue;
148165
return;
149166
}
150-
if ((flags & FLAG_ALL_OPTIONS) == 0)
167+
}
168+
if ((flags & FLAG_ALL_OPTIONS) == 0) {
151169
return;
170+
}
152171
// need to resize arrays
153172
int currentSize = tmpKeys.length;
154173
tmpKeys = new QualifiedName[currentSize + 1];
@@ -164,22 +183,26 @@ public void setProperty(QualifiedName newKey, Object newValue) {
164183
@Override
165184
public String toString() {
166185
StringBuilder result = new StringBuilder("{"); //$NON-NLS-1$
167-
if (keys != null)
186+
if (keys != null) {
168187
if (keys instanceof QualifiedName) {
169-
if (values != null)
188+
if (values != null) {
170189
result.append(keys + "=" + values); //$NON-NLS-1$
190+
}
171191
} else {
172192
QualifiedName[] tmpKeys = (QualifiedName[]) keys;
173193
Object[] tmpValues = (Object[]) values;
174194
boolean any = false;
175-
for (int i = 0; i < tmpKeys.length; i++)
195+
for (int i = 0; i < tmpKeys.length; i++) {
176196
if (tmpValues[i] != null) {
177197
result.append(tmpKeys[i] + "=" + tmpValues[i] + ","); //$NON-NLS-1$ //$NON-NLS-2$
178198
any = true;
179199
}
180-
if (any)
200+
}
201+
if (any) {
181202
result.deleteCharAt(result.length() - 1);
203+
}
182204
}
205+
}
183206
result.append("} : "); //$NON-NLS-1$
184207
result.append(contentTypeInfo.getContentType());
185208
return result.toString();

0 commit comments

Comments
 (0)