Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Medeiros2016-02-11 16:00:28 +0000
committerBruno Medeiros2016-09-23 14:38:27 +0000
commit8871738e5b595e7715499161b04980d9f16df820 (patch)
treea5b07d520998f79003f5f170279f77667eeabc59 /org.eclipse.core.filebuffers
parent938ab5d592348f65249ed9cc454013850d035d32 (diff)
downloadeclipse.platform.text-8871738e5b595e7715499161b04980d9f16df820.tar.gz
eclipse.platform.text-8871738e5b595e7715499161b04980d9f16df820.tar.xz
eclipse.platform.text-8871738e5b595e7715499161b04980d9f16df820.zip
Bug 500153: Cleanup warnings in file buffer classesI20160927-0800
Change-Id: I17d70791969dcdf77ecda462a154ee8b430ed98c Signed-off-by: Bruno Medeiros <bruno.do.medeiros@gmail.com>
Diffstat (limited to 'org.eclipse.core.filebuffers')
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java1
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/DocumentReader.java2
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileStoreTextFileBuffer.java66
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java6
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java20
-rw-r--r--org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java13
6 files changed, 27 insertions, 81 deletions
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java
index 756883a18..d4adc9dce 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/AbstractFileBuffer.java
@@ -67,6 +67,7 @@ public abstract class AbstractFileBuffer implements IFileBuffer, IStateValidatio
* @since 3.1
*/
protected void dispose() {
+ // do nothing
}
@Override
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/DocumentReader.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/DocumentReader.java
index 9b96627a8..f85c5bf5e 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/DocumentReader.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/DocumentReader.java
@@ -121,7 +121,7 @@ class DocumentReader extends Reader {
}
@Override
- public void close() throws IOException {
+ public void close() {
synchronized (this) {
fCharSequence= null;
}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileStoreTextFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileStoreTextFileBuffer.java
index 19bee7bf2..6ac8b9de7 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileStoreTextFileBuffer.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileStoreTextFileBuffer.java
@@ -67,6 +67,7 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
@Override
public void documentAboutToBeChanged(DocumentEvent event) {
+ // do nothing
}
@Override
@@ -182,8 +183,7 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
}
private void setFileContents(InputStream stream, IProgressMonitor monitor) throws CoreException {
- OutputStream out= fFileStore.openOutputStream(EFS.NONE, null);
- try {
+ try(OutputStream out= fFileStore.openOutputStream(EFS.NONE, null)) {
byte[] buffer= new byte[8192];
while (true) {
int bytesRead= -1;
@@ -204,11 +204,7 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
try {
stream.close();
} catch (IOException e) {
- } finally {
- try {
- out.close();
- } catch (IOException e) {
- }
+ // ignore
}
}
}
@@ -283,34 +279,24 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
*/
@Override
public IContentType getContentType () throws CoreException {
- InputStream stream= null;
try {
if (isDirty()) {
- Reader reader= new DocumentReader(getDocument());
- try {
+ try(Reader reader= new DocumentReader(getDocument())) {
IContentDescription desc= Platform.getContentTypeManager().getDescriptionFor(reader, fFileStore.getName(), NO_PROPERTIES);
if (desc != null && desc.getContentType() != null)
return desc.getContentType();
- } finally {
- try {
- reader.close();
- } catch (IOException ex) {
- }
}
}
- stream= fFileStore.openInputStream(EFS.NONE, null);
- IContentDescription desc= Platform.getContentTypeManager().getDescriptionFor(stream, fFileStore.getName(), NO_PROPERTIES);
- if (desc != null && desc.getContentType() != null)
- return desc.getContentType();
- return null;
+
+ try(InputStream stream= fFileStore.openInputStream(EFS.NONE, null)) {
+ IContentDescription desc= Platform.getContentTypeManager().getDescriptionFor(stream, fFileStore.getName(), NO_PROPERTIES);
+ if (desc != null && desc.getContentType() != null)
+ return desc.getContentType();
+ return null;
+ }
+
} catch (IOException x) {
throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, NLSUtility.format(FileBuffersMessages.FileBuffer_error_queryContentDescription, fFileStore.toString()), x));
- } finally {
- try {
- if (stream != null)
- stream.close();
- } catch (IOException x) {
- }
}
}
@@ -357,9 +343,7 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
fHasBOM= false;
fIsCacheUpdated= true;
- InputStream stream= null;
- try {
- stream= getFileContents(fFileStore);
+ try(InputStream stream= getFileContents(fFileStore)) {
if (stream == null)
return;
@@ -374,13 +358,6 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
// do nothing
} catch (IOException e) {
// do nothing
- } finally {
- try {
- if (stream != null)
- stream.close();
- } catch (IOException ex) {
- FileBuffersPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.JavaTextFileBuffer_error_closeStream, ex));
- }
}
// Use global default
@@ -464,8 +441,8 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
} else {
fFileStore.getParent().mkdir(EFS.NONE, null);
- OutputStream out= fFileStore.openOutputStream(EFS.NONE, null);
- try {
+
+ try(OutputStream out= fFileStore.openOutputStream(EFS.NONE, null)) {
/*
* XXX:
* This is a workaround for a corresponding bug in Java readers and writer,
@@ -480,11 +457,6 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
} catch (IOException x) {
IStatus s= new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, x.getLocalizedMessage(), x);
throw new CoreException(s);
- } finally {
- try {
- out.close();
- } catch (IOException x) {
- }
}
// set synchronization stamp to know whether the file synchronizer must become active
@@ -503,8 +475,7 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
return fExplicitEncoding;
// Probe content
- Reader reader= new DocumentReader(fDocument);
- try {
+ try(Reader reader= new DocumentReader(fDocument)) {
QualifiedName[] options= new QualifiedName[] { IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK };
IContentDescription description= Platform.getContentTypeManager().getDescriptionFor(reader, fFileStore.getName(), options);
if (description != null) {
@@ -514,11 +485,6 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
}
} catch (IOException ex) {
// Try next strategy
- } finally {
- try {
- reader.close();
- } catch (IOException x) {
- }
}
// Use file's encoding if the file has a BOM
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java
index 6c1c78125..351bd4139 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceFileBuffer.java
@@ -48,7 +48,7 @@ public abstract class ResourceFileBuffer extends AbstractFileBuffer {
* that a element change failed message is sent out to the element state
* listeners in case an exception occurred.
*/
- private class SafeFileChange implements Runnable {
+ private abstract class SafeFileChange implements Runnable {
/**
* Creates a new safe runnable for the given file.
@@ -62,8 +62,7 @@ public abstract class ResourceFileBuffer extends AbstractFileBuffer {
*
* @exception Exception in case of error
*/
- protected void execute() throws Exception {
- }
+ protected abstract void execute() throws Exception;
/**
* Does everything necessary prior to execution.
@@ -439,6 +438,7 @@ public abstract class ResourceFileBuffer extends AbstractFileBuffer {
try {
fFile.refreshLocal(IResource.DEPTH_INFINITE, monitor);
} catch (OperationCanceledException x) {
+ // Ignore
} catch (CoreException x) {
handleCoreException(x);
}
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
index 27926a476..d09ea9261 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ResourceTextFileBuffer.java
@@ -63,6 +63,7 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
@Override
public void documentAboutToBeChanged(DocumentEvent event) {
+ // do nothing
}
@Override
@@ -199,18 +200,10 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
public IContentType getContentType() throws CoreException {
try {
if (isDirty()) {
- Reader reader= null;
- try {
- reader= new DocumentReader(getDocument());
+ try(Reader reader = new DocumentReader(getDocument())) {
IContentDescription desc= Platform.getContentTypeManager().getDescriptionFor(reader, fFile.getName(), NO_PROPERTIES);
if (desc != null && desc.getContentType() != null)
return desc.getContentType();
- } finally {
- try {
- if (reader != null)
- reader.close();
- } catch (IOException x) {
- }
}
}
IContentDescription desc= fFile.getContentDescription();
@@ -406,8 +399,8 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
return fExplicitEncoding;
// Probe content
- Reader reader= new DocumentReader(fDocument);
- try {
+
+ try(Reader reader= new DocumentReader(fDocument)) {
QualifiedName[] options= new QualifiedName[] { IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK };
IContentDescription description= Platform.getContentTypeManager().getDescriptionFor(reader, fFile.getName(), options);
if (description != null) {
@@ -417,11 +410,6 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
}
} catch (IOException ex) {
// try next strategy
- } finally {
- try {
- reader.close();
- } catch (IOException x) {
- }
}
// Use file's encoding if the file has a BOM
diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java
index 25aba768c..89c446b73 100644
--- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java
+++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/TextFileBufferManager.java
@@ -265,9 +265,8 @@ public class TextFileBufferManager implements ITextFileBufferManager {
IContentTypeManager manager= Platform.getContentTypeManager();
IFileInfo fileInfo= fileStore.fetchInfo();
if (fileInfo.exists()) {
- InputStream is= null;
- try {
- is= fileStore.openInputStream(EFS.NONE, null);
+
+ try(InputStream is= fileStore.openInputStream(EFS.NONE, null)) {
IContentDescription description= manager.getDescriptionFor(is, fileStore.getName(), IContentDescription.ALL);
if (description != null) {
IContentType type= description.getContentType();
@@ -278,14 +277,6 @@ public class TextFileBufferManager implements ITextFileBufferManager {
// ignore: API specification tells return true if content type can't be determined
} catch (IOException ex) {
// ignore: API specification tells return true if content type can't be determined
- } finally {
- if (is != null ) {
- try {
- is.close();
- } catch (IOException e) {
- // ignore: API specification tells to return true if content type can't be determined
- }
- }
}
return !strict;

Back to the top