Skip to content

Commit

Permalink
clean up warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vladdu committed Jun 22, 2015
1 parent 40b2878 commit d1a421b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/*******************************************************************************
* Copyright (c) 2005 Vlad Dumitrescu and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* Copyright (c) 2005 Vlad Dumitrescu and others. All rights reserved. This program and
* the accompanying materials are made available under the terms of the Eclipse Public
* License v1.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Vlad Dumitrescu
* Contributors: Vlad Dumitrescu
*******************************************************************************/
package org.erlide.engine.internal.model.erlang;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -104,8 +103,8 @@ private ErlModule(final IParent parent, final String name, final IFile file,
if (ModelConfig.verbose) {
final IErlElement element = (IErlElement) parent;
final String parentName = element.getName();
ErlLogger.debug("...creating " + parentName + "/" + getName() + " "
+ moduleKind);
ErlLogger.debug(
"...creating " + parentName + "/" + getName() + " " + moduleKind);
}
}

Expand Down Expand Up @@ -141,8 +140,16 @@ private String getInitialText() {
charset = modelUtilService.getProject(this).getWorkspaceProject()
.getDefaultCharset();
}
initialText = Util.getInputStreamAsString(new FileInputStream(
new File(path)), charset);
final FileInputStream is = new FileInputStream(new File(path));
try {
initialText = Util.getInputStreamAsString(is, charset);
} finally {
try {
is.close();
} catch (final IOException e) {
// ignore
}
}
} catch (final CoreException e) {
ErlLogger.warn(e);
} catch (final FileNotFoundException e) {
Expand Down Expand Up @@ -179,8 +186,8 @@ public String getFilePath() {

@Override
public IErlElement getElementAt(final int position) throws ErlModelException {
return ErlangEngine.getInstance().getModel()
.innermostThat(this, new Predicate<IErlElement>() {
return ErlangEngine.getInstance().getModel().innermostThat(this,
new Predicate<IErlElement>() {
@Override
public boolean apply(final IErlElement e) {
if (e instanceof ISourceReference) {
Expand All @@ -198,8 +205,8 @@ public boolean apply(final IErlElement e) {

@Override
public IErlMember getElementAtLine(final int lineNumber) {
return (IErlMember) ErlangEngine.getInstance().getModel()
.innermostThat(this, new Predicate<IErlElement>() {
return (IErlMember) ErlangEngine.getInstance().getModel().innermostThat(this,
new Predicate<IErlElement>() {
@Override
public boolean apply(final IErlElement e) {
if (e instanceof ISourceReference) {
Expand Down Expand Up @@ -513,7 +520,8 @@ private ScannerService getNewScanner() {
}

@Override
public Collection<IErlPreprocessorDef> getPreprocessorDefs(final ErlElementKind kind) {
public Collection<IErlPreprocessorDef> getPreprocessorDefs(
final ErlElementKind kind) {
final List<IErlPreprocessorDef> result = Lists.newArrayList();
synchronized (getModelLock()) {
for (final IErlElement e : internalGetChildren()) {
Expand All @@ -535,7 +543,8 @@ public boolean isOnSourcePath() {
final IErlFolder folder = (IErlFolder) parent;
return folder.isOnSourcePath();
}
if (checkPath(modelUtilService.getProject(this).getProperties().getSourceDirs())) {
if (checkPath(
modelUtilService.getProject(this).getProperties().getSourceDirs())) {
return true;
}
return false;
Expand All @@ -548,7 +557,8 @@ public boolean isOnIncludePath() {
final IErlFolder folder = (IErlFolder) parent;
return folder.isOnIncludePath();
}
if (checkPath(modelUtilService.getProject(this).getProperties().getIncludeDirs())) {
if (checkPath(
modelUtilService.getProject(this).getProperties().getIncludeDirs())) {
return true;
}
return false;
Expand Down
20 changes: 14 additions & 6 deletions org.erlide.runtime/src/org/erlide/runtime/rpc/RpcMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import com.google.common.collect.Maps;

public class RpcMonitor {
private static final boolean DISABLED = System.getProperty("erlide.rpcmonitor") == null;
private static final int COUNT = Integer.parseInt(System.getProperty(
"erlide.rpcmonitor.count", "50"));
private static final boolean FULL = System.getProperty("erlide.rpcmonitor.full") != null;
private static final boolean DISABLED = System
.getProperty("erlide.rpcmonitor") == null;
private static final int COUNT = Integer
.parseInt(System.getProperty("erlide.rpcmonitor.count", "50"));
private static final boolean FULL = System
.getProperty("erlide.rpcmonitor.full") != null;

private static class RpcData {
public final long startTime;
Expand Down Expand Up @@ -168,7 +170,12 @@ public static void dump(final String file, final boolean full) {

public static void dump(final String fileName, final int n, final boolean full) {
try {
dump(new PrintStream(fileName), n, full);
final PrintStream os = new PrintStream(fileName);
try {
dump(os, n, full);
} finally {
os.close();
}
} catch (final FileNotFoundException e) {
ErlLogger.error(e);
}
Expand All @@ -178,7 +185,8 @@ public static synchronized void dump(final PrintStream out, final int n,
final boolean full) {
out.format("*** RpcMonitor statistics%n - %d calls%n", callCount);
if (DISABLED) {
out.println("\nRpcMonitor was not enabled.\n\nUse -Derlide.rpcmonitor to enable it.");
out.println(
"\nRpcMonitor was not enabled.\n\nUse -Derlide.rpcmonitor to enable it.");
return;
}
final String delim = "----------------------------------------------------------------------------------------";
Expand Down
84 changes: 38 additions & 46 deletions org.erlide.ui/src/org/eclipse/wb/swt/SWTResourceManager.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* Copyright (c) 2011 Google, Inc. All rights reserved. This program and the accompanying
* materials are made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Google, Inc. - initial API and implementation
* Contributors: Google, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.swt;

Expand All @@ -29,13 +27,12 @@
import org.eclipse.swt.widgets.Display;

/**
* Utility class for managing OS resources associated with SWT controls such as
* colors, fonts, images, etc.
* Utility class for managing OS resources associated with SWT controls such as colors,
* fonts, images, etc.
* <p>
* !!! IMPORTANT !!! Application code must explicitly invoke the
* <code>dispose()</code> method to release the operating system resources
* managed by cached objects when those objects and OS resources are no longer
* needed (e.g. on application shutdown)
* !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code>
* method to release the operating system resources managed by cached objects when those
* objects and OS resources are no longer needed (e.g. on application shutdown)
* <p>
* This class may be freely distributed as part of any application or plugin.
* <p>
Expand Down Expand Up @@ -72,8 +69,7 @@ public static Color getColor(final int systemColorID) {
* the green component of the color
* @param b
* the blue component of the color
* @return the {@link Color} matching the given red, green and blue
* component values
* @return the {@link Color} matching the given red, green and blue component values
*/
public static Color getColor(final int r, final int g, final int b) {
return getColor(new RGB(r, g, b));
Expand Down Expand Up @@ -147,7 +143,12 @@ public static Image getImage(final String path) {
Image image = m_imageMap.get(path);
if (image == null) {
try {
image = getImage(new FileInputStream(path));
final FileInputStream is = new FileInputStream(path);
try {
image = getImage(is);
} finally {
is.close();
}
m_imageMap.put(path, image);
} catch (final Exception e) {
image = getMissingImage();
Expand All @@ -158,8 +159,8 @@ public static Image getImage(final String path) {
}

/**
* Returns an {@link Image} stored in the file at the specified path
* relative to the specified class.
* Returns an {@link Image} stored in the file at the specified path relative to the
* specified class.
*
* @param clazz
* the {@link Class} relative to which to find the image
Expand All @@ -185,8 +186,7 @@ public static Image getImage(final Class<?> clazz, final String path) {
private static final int MISSING_IMAGE_SIZE = 10;

/**
* @return the small {@link Image} that can be used as placeholder for
* missing image.
* @return the small {@link Image} that can be used as placeholder for missing image.
*/
private static Image getMissingImage() {
final Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE,
Expand All @@ -201,23 +201,19 @@ private static Image getMissingImage() {
}

/**
* Style constant for placing decorator image in top left corner of base
* image.
* Style constant for placing decorator image in top left corner of base image.
*/
public static final int TOP_LEFT = 1;
/**
* Style constant for placing decorator image in top right corner of base
* image.
* Style constant for placing decorator image in top right corner of base image.
*/
public static final int TOP_RIGHT = 2;
/**
* Style constant for placing decorator image in bottom left corner of base
* image.
* Style constant for placing decorator image in bottom left corner of base image.
*/
public static final int BOTTOM_LEFT = 3;
/**
* Style constant for placing decorator image in bottom right corner of base
* image.
* Style constant for placing decorator image in bottom right corner of base image.
*/
public static final int BOTTOM_RIGHT = 4;
/**
Expand All @@ -231,8 +227,7 @@ private static Image getMissingImage() {
private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY];

/**
* Returns an {@link Image} composed of a base image decorated by another
* image.
* Returns an {@link Image} composed of a base image decorated by another image.
*
* @param baseImage
* the base {@link Image} that should be decorated
Expand All @@ -245,8 +240,7 @@ public static Image decorateImage(final Image baseImage, final Image decorator)
}

/**
* Returns an {@link Image} composed of a base image decorated by another
* image.
* Returns an {@link Image} composed of a base image decorated by another image.
*
* @param baseImage
* the base {@link Image} that should be decorated
Expand Down Expand Up @@ -309,8 +303,7 @@ public static void disposeImages() {
m_imageMap.clear();
}
// dispose decorated images
for (int i = 0; i < m_decoratedImageMap.length; i++) {
final Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i];
for (final Map<Image, Map<Image, Image>> cornerDecoratedImageMap : m_decoratedImageMap) {
if (cornerDecoratedImageMap != null) {
for (final Map<Image, Image> decoratedMap : cornerDecoratedImageMap
.values()) {
Expand Down Expand Up @@ -354,8 +347,8 @@ public static Font getFont(final String name, final int height, final int style)
}

/**
* Returns a {@link Font} based on its name, height and style.
* Windows-specific strikeout and underline flags are also supported.
* Returns a {@link Font} based on its name, height and style. Windows-specific
* strikeout and underline flags are also supported.
*
* @param name
* the name of the font
Expand All @@ -367,8 +360,8 @@ public static Font getFont(final String name, final int height, final int style)
* the strikeout flag (warning: Windows only)
* @param underline
* the underline flag (warning: Windows only)
* @return {@link Font} The font matching the name, height, style, strikeout
* and underline
* @return {@link Font} The font matching the name, height, style, strikeout and
* underline
*/
public static Font getFont(final String name, final int size, final int style,
final boolean strikeout, final boolean underline) {
Expand All @@ -384,17 +377,17 @@ public static Font getFont(final String name, final int size, final int style,
final Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$
if (logFont != null && logFontClass != null) {
if (strikeout) {
logFontClass
.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$
logFontClass.getField("lfStrikeOut").set(logFont, //$NON-NLS-1$
Byte.valueOf((byte) 1));
}
if (underline) {
logFontClass
.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$
logFontClass.getField("lfUnderline").set(logFont, //$NON-NLS-1$
Byte.valueOf((byte) 1));
}
}
} catch (final Throwable e) {
System.err
.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$
System.err.println("Unable to set underline or strikeout" //$NON-NLS-1$
+ " (probably on a non-Windows platform). " + e); //$NON-NLS-1$
}
}
font = new Font(Display.getCurrent(), fontData);
Expand Down Expand Up @@ -481,9 +474,8 @@ public static void disposeCursors() {
//
// //////////////////////////////////////////////////////////////////////////
/**
* Dispose of cached objects and their underlying OS resources. This should
* only be called when the cached objects are no longer needed (e.g. on
* application shutdown).
* Dispose of cached objects and their underlying OS resources. This should only be
* called when the cached objects are no longer needed (e.g. on application shutdown).
*/
public static void dispose() {
disposeColors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
import org.erlide.ui.internal.ErlideUIPlugin;
import org.erlide.ui.templates.ErlangSourceContextTypeModule;
import org.erlide.ui.templates.ModuleVariableResolver;
import org.erlide.ui.wizards.templates.ExportedFunctionsVariableResolver;
import org.erlide.ui.wizards.templates.LocalFunctionsVariableResolver;
import org.erlide.util.ErlLogger;
import org.erlide.util.SystemConfiguration;

Expand Down Expand Up @@ -153,7 +151,7 @@ public void widgetSelected(final SelectionEvent e) {
lblskeleton.setText("&Skeleton:");

skeleton = new Combo(filePanel, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
GridData gd_skeleton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
final GridData gd_skeleton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_skeleton.widthHint = 139;
skeleton.setLayoutData(gd_skeleton);
// skeleton.add("None");
Expand Down

0 comments on commit d1a421b

Please sign in to comment.