Skip to content

Commit

Permalink
fix some ecj warnings:
Browse files Browse the repository at this point in the history
set discouragedReference=ignore in snippets
set UTF-8 encoding
use try-with-resource
enable explicitlyClosedAutoCloseable=warning
  • Loading branch information
EcljpseB0T authored and jukzi committed Nov 29, 2023
1 parent 1190e3c commit 2e7eaa5
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 89 deletions.
6 changes: 6 additions & 0 deletions bundles/org.eclipse.swt/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
Expand All @@ -17,6 +18,8 @@ org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.problem.APILeak=warning
org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
Expand Down Expand Up @@ -91,8 +94,10 @@ org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
Expand All @@ -105,6 +110,7 @@ org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,13 @@ public void save(OutputStream stream, int format) {
* </ul>
*/
public void save(String filename, int format) {
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
OutputStream stream = null;
try {
stream = new FileOutputStream(filename);
if (filename == null)
SWT.error(SWT.ERROR_NULL_ARGUMENT);
try (OutputStream stream = new FileOutputStream(filename)) {
save(stream, format);
} catch (IOException e) {
SWT.error(SWT.ERROR_IO, e);
}
save(stream, format);
try {
stream.close();
} catch (IOException e) {
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,14 @@ public static void freeResources() {
* @return the image, or null if not found
*/
private static Image getImageFromPlugin(Bundle bundle, String iconPath) {
InputStream is = null;
try {
URL installUrl = bundle.getEntry("/");
URL url = new URL(installUrl, iconPath);
is = url.openConnection().getInputStream();
URL installUrl = bundle.getEntry("/");
try (InputStream is = new URL(installUrl, iconPath).openConnection().getInputStream()) {
ImageData source = new ImageData(is);
ImageData mask = source.getTransparencyMask();
Image image = new Image(null, source, mask);
return image;
} catch (Throwable ex) {
return null;
} finally {
try {
if (is != null) is.close();
} catch (IOException e) {
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,15 @@ void initResources() {
throw new RuntimeException(error);
}

public static void main(String [] args) {
public static void main(String [] args) throws IOException {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setText(getResourceString("window.title"));
InputStream stream = BrowserExample.class.getResourceAsStream(iconLocation);
Image icon = new Image(display, stream);
shell.setImage(icon);
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
Image icon;
try (InputStream stream = BrowserExample.class.getResourceAsStream(iconLocation)) {
icon = new Image(display, stream);
shell.setImage(icon);
}
BrowserExample app = new BrowserExample(shell, true);
app.setShellDecoration(icon, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,16 @@ class StyledTextTab extends ScrollableTab {
/**
* Creates a bitmap image.
*/
Image createBitmapImage (Display display, String name) {
InputStream sourceStream = ControlExample.class.getResourceAsStream (name + ".bmp");
InputStream maskStream = ControlExample.class.getResourceAsStream (name + "_mask.bmp");
ImageData source = new ImageData (sourceStream);
ImageData mask = new ImageData (maskStream);
Image result = new Image (display, source, mask);
try {
sourceStream.close ();
maskStream.close ();
Image createBitmapImage(Display display, String name) {
try (InputStream sourceStream = ControlExample.class.getResourceAsStream(name + ".bmp");
InputStream maskStream = ControlExample.class.getResourceAsStream(name + "_mask.bmp")) {
ImageData source = new ImageData(sourceStream);
ImageData mask = new ImageData(maskStream);
Image result = new Image(display, source, mask);
return result;
} catch (IOException e) {
e.printStackTrace ();
throw new RuntimeException(e);
}
return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,14 @@ public void freeResources() {
* @param path the relative path to the icon
*/
private Image createStockImage(Display display, String path) {
InputStream stream = IconCache.class.getResourceAsStream (path);
ImageData imageData = new ImageData (stream);
ImageData mask = imageData.getTransparencyMask ();
Image result = new Image (display, imageData, mask);
try {
stream.close ();
try (InputStream stream = IconCache.class.getResourceAsStream (path)) {
ImageData imageData = new ImageData (stream);
ImageData mask = imageData.getTransparencyMask ();
Image result = new Image (display, imageData, mask);
return result;
} catch (IOException e) {
e.printStackTrace ();
throw new RuntimeException(e);
}
return result;
}
/**
* Gets an image for a file associated with a given program
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,16 @@ public class AdvancedGraphics {

private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle("examples_graphics");

static Image loadImage (Device device, Class<AdvancedGraphics> clazz, String string) {
InputStream stream = clazz.getResourceAsStream (string);
if (stream == null) return null;
Image image = null;
try {
image = new Image (device, stream);
static Image loadImage(Device device, Class<AdvancedGraphics> clazz, String string) {
try (InputStream stream = clazz.getResourceAsStream(string)) {
if (stream == null)
return null;
Image image = new Image(device, stream);
return image;
} catch (SWTException ex) {
} finally {
try {
stream.close ();
} catch (IOException ex) {}
} catch (IOException ex) {
}
return image;
return null;
}

public Shell open(final Display display) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,19 +521,15 @@ static String getResourceString(String key) {
}
}

static Image loadImage (Device device, Class<GraphicsExample> clazz, String string) {
InputStream stream = clazz.getResourceAsStream (string);
if (stream == null) return null;
Image image = null;
try {
image = new Image (device, stream);
static Image loadImage(Device device, Class<GraphicsExample> clazz, String string) {
try (InputStream stream = clazz.getResourceAsStream(string)) {
if (stream == null)
return null;
return new Image(device, stream);
} catch (SWTException ex) {
} finally {
try {
stream.close ();
} catch (IOException ex) {}
} catch (IOException ex) {
}
return image;
return null;
}

Image loadImage(Device device, String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
Expand Down Expand Up @@ -26,7 +27,7 @@ org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public class Snippet373 {
return path;
};

@SuppressWarnings("restriction")
public static void main(String[] args) {
System.setProperty("swt.autoScale", "quarter");
Display display = new Display();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@
*******************************************************************************/
package org.eclipse.swt.tests.win32.snippets;

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import java.lang.reflect.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Scrollable;
import org.eclipse.swt.widgets.Shell;

public class Bug565426_SmoothScrolling {
static void simulateScroll(Scrollable control, boolean vertical, int wheelDelta) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
*******************************************************************************/
package org.eclipse.swt.tests.win32.snippets;

import org.eclipse.swt.*;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Shell;

public class Bug565613_ScrollbarThumbJumps {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,30 @@
*******************************************************************************/
package org.eclipse.swt.tests.win32.snippets;

import org.eclipse.swt.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.CoolBar;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Decorations;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;

public class Bug565679_WS_BORDER {
public static void main(String[] args) {
Expand Down

0 comments on commit 2e7eaa5

Please sign in to comment.