Skip to content

Commit 67d3b85

Browse files
eclipse-platform-botakurtakov
authored andcommitted
Perform clean code of resources/bundles/org.eclipse.core.filesystem
1 parent 1be0f85 commit 67d3b85

File tree

14 files changed

+212
-110
lines changed

14 files changed

+212
-110
lines changed

resources/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/filesystem/URIUtil.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,23 @@ public static boolean equals(URI one, URI two) {
6464
public static IPath toPath(URI uri) {
6565
Assert.isNotNull(uri);
6666
// Special treatment for LocalFileSystem. For performance only.
67-
if (EFS.SCHEME_FILE.equals(uri.getScheme()))
67+
if (EFS.SCHEME_FILE.equals(uri.getScheme())) {
6868
return IPath.fromOSString(uri.getSchemeSpecificPart());
69+
}
6970
// Relative path
70-
if (uri.getScheme() == null)
71+
if (uri.getScheme() == null) {
7172
return IPath.fromOSString(uri.getPath());
73+
}
7274
// General case
7375
try {
7476
IFileStore store = EFS.getStore(uri);
75-
if (store == null)
77+
if (store == null) {
7678
return null;
79+
}
7780
File file = store.toLocalFile(EFS.NONE, null);
78-
if (file == null)
81+
if (file == null) {
7982
return null;
83+
}
8084
return IPath.fromOSString(file.getAbsolutePath());
8185
} catch (CoreException e) {
8286
// Fall through to return null.
@@ -91,10 +95,12 @@ public static IPath toPath(URI uri) {
9195
* @return The URI representing the provided path
9296
*/
9397
public static URI toURI(IPath path) {
94-
if (path == null)
98+
if (path == null) {
9599
return null;
96-
if (path.isAbsolute())
100+
}
101+
if (path.isAbsolute()) {
97102
return toURI(path.toFile().getAbsolutePath(), true);
103+
}
98104
//Must use the relativize method to properly construct a relative URI
99105
URI base = toURI(IPath.ROOT.setDevice(path.getDevice()));
100106
return base.relativize(toURI(path.makeAbsolute()));
@@ -132,17 +138,19 @@ public static URI toURI(String pathString) {
132138
* @since org.eclipse.core.filesystem 1.2
133139
*/
134140
public static URI toURI(String pathString, boolean forceAbsolute) {
135-
if (File.separatorChar != '/')
141+
if (File.separatorChar != '/') {
136142
pathString = pathString.replace(File.separatorChar, '/');
143+
}
137144
final int length = pathString.length();
138145
StringBuilder pathBuf = new StringBuilder(length + 1);
139146
//mark if path is relative
140147
if (length > 0 && (pathString.charAt(0) != '/') && forceAbsolute) {
141148
pathBuf.append('/');
142149
}
143150
//additional double-slash for UNC paths to distinguish from host separator
144-
if (pathString.startsWith("//")) //$NON-NLS-1$
151+
if (pathString.startsWith("//")) { //$NON-NLS-1$
145152
pathBuf.append('/').append('/');
153+
}
146154
pathBuf.append(pathString);
147155
try {
148156
String scheme = null;
@@ -171,8 +179,9 @@ public static URI toURI(String pathString, boolean forceAbsolute) {
171179
public static String toDecodedString(URI uri) {
172180
String scheme = uri.getScheme();
173181
String part = uri.getSchemeSpecificPart();
174-
if (scheme == null)
182+
if (scheme == null) {
175183
return part;
184+
}
176185
return scheme + ':' + part;
177186
}
178187

resources/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/filesystem/provider/FileInfo.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,20 @@ public int getError() {
123123

124124
@Override
125125
public boolean getAttribute(int attribute) {
126-
if (attribute == EFS.ATTRIBUTE_READ_ONLY && isAttributeSuported(EFS.ATTRIBUTE_OWNER_WRITE))
126+
if (attribute == EFS.ATTRIBUTE_READ_ONLY && isAttributeSuported(EFS.ATTRIBUTE_OWNER_WRITE)) {
127127
return (!isSet(EFS.ATTRIBUTE_OWNER_WRITE)) || isSet(EFS.ATTRIBUTE_IMMUTABLE);
128-
else if (attribute == EFS.ATTRIBUTE_EXECUTABLE && isAttributeSuported(EFS.ATTRIBUTE_OWNER_EXECUTE))
128+
} else if (attribute == EFS.ATTRIBUTE_EXECUTABLE && isAttributeSuported(EFS.ATTRIBUTE_OWNER_EXECUTE)) {
129129
return isSet(EFS.ATTRIBUTE_OWNER_EXECUTE);
130-
else
130+
} else {
131131
return isSet(attribute);
132+
}
132133
}
133134

134135
@Override
135136
public String getStringAttribute(int attribute) {
136-
if (attribute == EFS.ATTRIBUTE_LINK_TARGET)
137+
if (attribute == EFS.ATTRIBUTE_LINK_TARGET) {
137138
return this.linkTarget;
139+
}
138140
return null;
139141
}
140142

@@ -177,15 +179,17 @@ public void setAttribute(int attribute, boolean value) {
177179
clear(EFS.ATTRIBUTE_IMMUTABLE);
178180
}
179181
} else if (attribute == EFS.ATTRIBUTE_EXECUTABLE && isAttributeSuported(EFS.ATTRIBUTE_OWNER_EXECUTE)) {
180-
if (value)
182+
if (value) {
181183
set(EFS.ATTRIBUTE_OWNER_EXECUTE);
182-
else
184+
} else {
183185
clear(EFS.ATTRIBUTE_OWNER_EXECUTE | EFS.ATTRIBUTE_GROUP_EXECUTE | EFS.ATTRIBUTE_OTHER_EXECUTE);
186+
}
184187
} else {
185-
if (value)
188+
if (value) {
186189
set(attribute);
187-
else
190+
} else {
188191
clear(attribute);
192+
}
189193
}
190194
}
191195

@@ -200,10 +204,11 @@ private static boolean isAttributeSuported(int value) {
200204
* if this is a file.
201205
*/
202206
public void setDirectory(boolean value) {
203-
if (value)
207+
if (value) {
204208
set(ATTRIBUTE_DIRECTORY);
205-
else
209+
} else {
206210
clear(ATTRIBUTE_DIRECTORY);
211+
}
207212
}
208213

209214
/**
@@ -213,10 +218,11 @@ public void setDirectory(boolean value) {
213218
* otherwise.
214219
*/
215220
public void setExists(boolean value) {
216-
if (value)
221+
if (value) {
217222
set(ATTRIBUTE_EXISTS);
218-
else
223+
} else {
219224
clear(ATTRIBUTE_EXISTS);
225+
}
220226
}
221227

222228
/**
@@ -251,8 +257,9 @@ public void setLength(long value) {
251257
* @param name The file name
252258
*/
253259
public void setName(String name) {
254-
if (name == null)
260+
if (name == null) {
255261
throw new IllegalArgumentException();
262+
}
256263
this.name = name;
257264
}
258265

@@ -266,8 +273,9 @@ public void setName(String name) {
266273
* @since org.eclipse.core.filesystem 1.1
267274
*/
268275
public void setStringAttribute(int attribute, String value) {
269-
if (attribute == EFS.ATTRIBUTE_LINK_TARGET)
276+
if (attribute == EFS.ATTRIBUTE_LINK_TARGET) {
270277
this.linkTarget = value;
278+
}
271279
}
272280

273281
@Override

resources/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/filesystem/provider/FileStore.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws Core
8282
public IFileStore[] childStores(int options, IProgressMonitor monitor) throws CoreException {
8383
String[] children = childNames(options, monitor);
8484
IFileStore[] wrapped = new IFileStore[children.length];
85-
for (int i = 0; i < wrapped.length; i++)
85+
for (int i = 0; i < wrapped.length; i++) {
8686
wrapped[i] = getChild(children[i]);
87+
}
8788
return wrapped;
8889
}
8990

@@ -132,8 +133,9 @@ protected void copyDirectory(IFileInfo sourceInfo, IFileStore destination, int o
132133
// copy attributes
133134
LocalFile.transferAttributes(sourceInfo, destination);
134135

135-
if (children == null)
136+
if (children == null) {
136137
return;
138+
}
137139
// copy children
138140
for (IFileStore c : children) {
139141
c.copy(destination.getChild(c.getName()), options, subMonitor.newChild(1));
@@ -176,8 +178,9 @@ protected void copyFile(IFileInfo sourceInfo, IFileStore destination, int option
176178
Policy.error(EFS.ERROR_WRITE, NLS.bind(Messages.failedCopy, sourcePath), e);
177179
} catch (CoreException e) {
178180
//if we failed to write, try to cleanup the half written file
179-
if (!destination.fetchInfo(0, null).exists())
181+
if (!destination.fetchInfo(0, null).exists()) {
180182
destination.delete(EFS.NONE, null);
183+
}
181184
throw e;
182185
}
183186
}
@@ -213,10 +216,12 @@ public void delete(int options, IProgressMonitor monitor) throws CoreException {
213216
*/
214217
@Override
215218
public boolean equals(Object obj) {
216-
if (this == obj)
219+
if (this == obj) {
217220
return true;
218-
if (!(obj instanceof FileStore))
221+
}
222+
if (!(obj instanceof FileStore)) {
219223
return false;
224+
}
220225
return toURI().equals(((FileStore) obj).toURI());
221226
}
222227

@@ -247,8 +252,9 @@ public IFileInfo fetchInfo() {
247252
@Override
248253
public IFileStore getChild(IPath path) {
249254
IFileStore result = this;
250-
for (int i = 0, imax = path.segmentCount(); i < imax; i++)
255+
for (int i = 0, imax = path.segmentCount(); i < imax; i++) {
251256
result = result.getChild(path.segment(i));
257+
}
252258
return result;
253259
}
254260

@@ -264,12 +270,13 @@ public IFileStore getFileStore(IPath path) {
264270
String segment = null;
265271
for (int i = 0, imax = path.segmentCount(); i < imax; i++) {
266272
segment = path.segment(i);
267-
if (segment.equals(".")) //$NON-NLS-1$
273+
if (segment.equals(".")) { //$NON-NLS-1$
268274
continue;
269-
else if (segment.equals("..") && result.getParent() != null) //$NON-NLS-1$
275+
} else if (segment.equals("..") && result.getParent() != null) { //$NON-NLS-1$
270276
result = result.getParent();
271-
else
277+
} else {
272278
result = result.getChild(segment);
279+
}
273280
}
274281
return result;
275282
}
@@ -324,10 +331,12 @@ public int hashCode() {
324331
public boolean isParentOf(IFileStore other) {
325332
while (true) {
326333
other = other.getParent();
327-
if (other == null)
334+
if (other == null) {
328335
return false;
329-
if (this.equals(other))
336+
}
337+
if (this.equals(other)) {
330338
return true;
339+
}
331340
}
332341
}
333342

@@ -412,8 +421,9 @@ public void putInfo(IFileInfo info, int options, IProgressMonitor monitor) throw
412421
@Override
413422
public java.io.File toLocalFile(int options, IProgressMonitor monitor) throws CoreException {
414423
//caching is the only recognized option
415-
if (options != EFS.CACHE)
424+
if (options != EFS.CACHE) {
416425
return null;
426+
}
417427
return FileCache.getCache().cache(this, monitor);
418428
}
419429

resources/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/filesystem/provider/FileSystem.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,13 @@ public IFileStore fromLocalFile(java.io.File file) {
157157
* @param aScheme The scheme of the file system.
158158
*/
159159
public final void initialize(String aScheme) {
160-
if (aScheme == null)
160+
if (aScheme == null) {
161161
throw new NullPointerException();
162+
}
162163
//scheme cannot be changed after creation
163-
if (this.scheme != null)
164+
if (this.scheme != null) {
164165
throw new IllegalStateException("File system already initialized"); //$NON-NLS-1$
166+
}
165167
this.scheme = aScheme;
166168
}
167169

resources/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/FileCache.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ private static FileCache createFileCache() {
6262
*/
6363
public static FileCache getCache() throws CoreException {
6464
FileCache instance = FileCacheHolder.instance;
65-
if (instance == null)
65+
if (instance == null) {
6666
throw FileCacheHolder.ce;
67+
}
6768
return instance;
6869
}
6970

@@ -93,8 +94,9 @@ public java.io.File cache(IFileStore source, IProgressMonitor monitor) throws Co
9394
try {
9495
SubMonitor subMonitor = SubMonitor.convert(monitor, NLS.bind(Messages.copying, toString()), 3);
9596
IFileInfo myInfo = source.fetchInfo(EFS.NONE, subMonitor.newChild(1));
96-
if (!myInfo.exists())
97+
if (!myInfo.exists()) {
9798
return new File(cacheDir, "Non-Existent-" + System.currentTimeMillis()); //$NON-NLS-1$
99+
}
98100
File result;
99101
if (myInfo.isDirectory()) {
100102
result = getUniqueDirectory(cacheDir, false);
@@ -172,8 +174,9 @@ private File getUniqueDirectory(File parent, boolean create) {
172174
do {
173175
dir = new File(parent, Long.toString(System.currentTimeMillis() + i++));
174176
} while (dir.exists());
175-
if (create)
177+
if (create) {
176178
dir.mkdir();
179+
}
177180
return dir;
178181
}
179182
}

0 commit comments

Comments
 (0)