diff options
author | Alexander Kurtakov | 2017-04-27 07:18:40 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2017-04-27 07:18:40 +0000 |
commit | f3426794060b2eb88ef98d21b3ad61cdb6bd929d (patch) | |
tree | 41ee5bfa36e0844af3b1278abf402dcdaed09a25 | |
parent | 6c8a0381f72e093c114af4da2593afd3dd618e52 (diff) | |
download | org.eclipse.dltk.core-f3426794060b2eb88ef98d21b3ad61cdb6bd929d.tar.gz org.eclipse.dltk.core-f3426794060b2eb88ef98d21b3ad61cdb6bd929d.tar.xz org.eclipse.dltk.core-f3426794060b2eb88ef98d21b3ad61cdb6bd929d.zip |
Fix warnings in dltk.formatter.
Change-Id: I8a455e28049e577ce24d09186b352481972348cf
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
10 files changed, 117 insertions, 148 deletions
diff --git a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/AbstractFormatterNodeBuilder.java b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/AbstractFormatterNodeBuilder.java index f9e38b054..3484b613a 100644 --- a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/AbstractFormatterNodeBuilder.java +++ b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/AbstractFormatterNodeBuilder.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 xored software, Inc. + * Copyright (c) 2008, 2017 xored software, Inc. and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -15,7 +15,7 @@ import java.util.Stack; public class AbstractFormatterNodeBuilder { - private final Stack<IFormatterContainerNode> stack = new Stack<IFormatterContainerNode>(); + private final Stack<IFormatterContainerNode> stack = new Stack<>(); protected void start(IFormatterContainerNode root) { stack.clear(); @@ -40,7 +40,8 @@ public class AbstractFormatterNodeBuilder { return node; } - private void advanceParent(IFormatterContainerNode parentNode, final int pos) { + private void advanceParent(IFormatterContainerNode parentNode, + final int pos) { if (parentNode.getEndOffset() < pos) { parentNode.addChild(createTextNode(parentNode.getDocument(), parentNode.getEndOffset(), pos)); @@ -60,8 +61,8 @@ public class AbstractFormatterNodeBuilder { throw new IllegalStateException(); } if (bodyEnd > 0 && expected.getEndOffset() < bodyEnd) { - expected.addChild(createTextNode(expected.getDocument(), expected - .getEndOffset(), bodyEnd)); + expected.addChild(createTextNode(expected.getDocument(), + expected.getEndOffset(), bodyEnd)); } } diff --git a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/AbstractScriptFormatterFactory.java b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/AbstractScriptFormatterFactory.java index 19f64dcf4..1240da08b 100644 --- a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/AbstractScriptFormatterFactory.java +++ b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/AbstractScriptFormatterFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2016 xored software, Inc. and others. + * Copyright (c) 2008, 2017 xored software, Inc. and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -51,8 +51,8 @@ import org.eclipse.dltk.ui.preferences.PreferenceKey; /** * Abstract base class for the {@link IScriptFormatterFactory} implementations. */ -public abstract class AbstractScriptFormatterFactory extends - DLTKContributedExtension implements IScriptFormatterFactory { +public abstract class AbstractScriptFormatterFactory + extends DLTKContributedExtension implements IScriptFormatterFactory { protected IProfileVersioner versioner; @@ -76,59 +76,51 @@ public abstract class AbstractScriptFormatterFactory extends @Override public List<IProfile> getBuiltInProfiles() { - final List<IProfile> profiles = new ArrayList<IProfile>(); + final List<IProfile> profiles = new ArrayList<>(); final IProfileVersioner versioner = getProfileVersioner(); final Map<String, String> defaults = loadDefaultSettings(); profiles.addAll(loadContributedProfiles(versioner, defaults)); - final BuiltInProfile profile = new BuiltInProfile( - getDefaultProfileID(), getDefaultProfileName(), defaults, 1000, - getId(), versioner.getCurrentVersion()); + final BuiltInProfile profile = new BuiltInProfile(getDefaultProfileID(), + getDefaultProfileName(), defaults, 1000, getId(), + versioner.getCurrentVersion()); profiles.add(profile); return profiles; } private Collection<? extends IProfile> loadContributedProfiles( IProfileVersioner versioner, Map<String, String> defaults) { - final IConfigurationElement[] elements = Platform - .getExtensionRegistry().getConfigurationElementsFor( - ScriptFormatterManager.EXTPOINT); + final IConfigurationElement[] elements = Platform.getExtensionRegistry() + .getConfigurationElementsFor(ScriptFormatterManager.EXTPOINT); final ProfileStore profileStore = new ProfileStore(versioner, defaults); - final List<IProfile> profiles = new ArrayList<IProfile>(); + final List<IProfile> profiles = new ArrayList<>(); for (IConfigurationElement element : elements) { if ("profiles".equals(element.getName())) { - final URL url = Platform.getBundle( - element.getContributor().getName()).getEntry( - element.getAttribute("resource")); + final URL url = Platform + .getBundle(element.getContributor().getName()) + .getEntry(element.getAttribute("resource")); if (url == null) { // TODO log continue; } int priority; try { - priority = Integer.parseInt(element - .getAttribute("priority")); + priority = Integer + .parseInt(element.getAttribute("priority")); } catch (NumberFormatException e) { priority = 0; } try { - final InputStream stream = url.openStream(); - try { + try (final InputStream stream = url.openStream()) { final List<IProfile> loaded = profileStore .readProfilesFromStream(stream); for (IProfile profile : loaded) { if (getId().equals(profile.getFormatterId())) - profiles.add(new BuiltInProfile( - profile.getID(), profile.getName(), + profiles.add(new BuiltInProfile(profile.getID(), + profile.getName(), profile.getSettings(), priority, - profile.getFormatterId(), profile - .getVersion())); - } - } finally { - try { - stream.close(); - } catch (IOException e) { - // ignore + profile.getFormatterId(), + profile.getVersion())); } } } catch (IOException e) { @@ -179,7 +171,7 @@ public abstract class AbstractScriptFormatterFactory extends } public Map<String, String> loadDefaultSettings() { - Map<String, String> settings = new HashMap<String, String>(); + Map<String, String> settings = new HashMap<>(); PreferenceKey[] keys = getPreferenceKeys(); if (keys != null) { for (int i = 0; i < keys.length; i++) { @@ -200,9 +192,9 @@ public abstract class AbstractScriptFormatterFactory extends IPreferencesLookupDelegate delegate) { final PreferenceKey activeProfileKey = getActiveProfileKey(); if (activeProfileKey != null) { - final String profileId = delegate - .getString(activeProfileKey.getQualifier(), - activeProfileKey.getName()); + final String profileId = delegate.getString( + activeProfileKey.getQualifier(), + activeProfileKey.getName()); if (profileId != null && profileId.length() != 0) { for (IProfile profile : getBuiltInProfiles()) { if (profileId.equals(profile.getID())) { @@ -216,13 +208,14 @@ public abstract class AbstractScriptFormatterFactory extends } } } - final Map<String, String> result = new HashMap<String, String>(); + final Map<String, String> result = new HashMap<>(); final PreferenceKey[] keys = getPreferenceKeys(); if (keys != null) { for (int i = 0; i < keys.length; ++i) { final PreferenceKey prefKey = keys[i]; final String key = prefKey.getName(); - result.put(key, delegate.getString(prefKey.getQualifier(), key)); + result.put(key, + delegate.getString(prefKey.getQualifier(), key)); } } return result; diff --git a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterBlockNode.java b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterBlockNode.java index aab84df43..54c0d70eb 100644 --- a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterBlockNode.java +++ b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterBlockNode.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2016 xored software, Inc. and others. + * Copyright (c) 2008, 2017 xored software, Inc. and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -15,8 +15,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -public class FormatterBlockNode extends AbstractFormatterNode implements - IFormatterContainerNode { +public class FormatterBlockNode extends AbstractFormatterNode + implements IFormatterContainerNode { /** * @param document @@ -25,7 +25,7 @@ public class FormatterBlockNode extends AbstractFormatterNode implements super(document); } - private final List<IFormatterNode> body = new ArrayList<IFormatterNode>(); + private final List<IFormatterNode> body = new ArrayList<>(); protected void acceptNodes(final List<IFormatterNode> nodes, IFormatterContext context, IFormatterWriter visitor) diff --git a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterContext.java b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterContext.java index d4bb5e5d6..66916c747 100644 --- a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterContext.java +++ b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterContext.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2016 xored software, Inc. and others. + * Copyright (c) 2008, 2017 xored software, Inc. and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -36,7 +36,7 @@ public class FormatterContext implements IFormatterContext, Cloneable { private boolean comment = false; private boolean wrapping = false; private int blankLines = 0; - private final List<PathEntry> path = new ArrayList<PathEntry>(); + private final List<PathEntry> path = new ArrayList<>(); public FormatterContext(int indent) { this.indent = indent; diff --git a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterNodeRewriter.java b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterNodeRewriter.java index 7866f997c..33976acfb 100644 --- a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterNodeRewriter.java +++ b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterNodeRewriter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 xored software, Inc. + * Copyright (c) 2009, 2017 xored software, Inc. and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -18,8 +18,8 @@ public abstract class FormatterNodeRewriter { protected void mergeTextNodes(IFormatterContainerNode root) { final List<IFormatterNode> body = root.getBody(); - final List<IFormatterNode> newBody = new ArrayList<IFormatterNode>(); - final List<IFormatterNode> texts = new ArrayList<IFormatterNode>(); + final List<IFormatterNode> newBody = new ArrayList<>(); + final List<IFormatterNode> texts = new ArrayList<>(); for (final IFormatterNode node : body) { if (isPlainTextNode(node)) { if (!texts.isEmpty() @@ -54,8 +54,8 @@ public abstract class FormatterNodeRewriter { if (texts.size() > 1) { final IFormatterNode first = texts.get(0); final IFormatterNode last = texts.get(texts.size() - 1); - newBody.add(new FormatterTextNode(first.getDocument(), first - .getStartOffset(), last.getEndOffset())); + newBody.add(new FormatterTextNode(first.getDocument(), + first.getStartOffset(), last.getEndOffset())); } else { newBody.addAll(texts); } @@ -79,7 +79,7 @@ public abstract class FormatterNodeRewriter { } - private final List<CommentInfo> comments = new ArrayList<CommentInfo>(); + private final List<CommentInfo> comments = new ArrayList<>(); protected void addComment(int startOffset, int endOffset, Object object) { comments.add(new CommentInfo(startOffset, endOffset, object)); @@ -87,13 +87,13 @@ public abstract class FormatterNodeRewriter { protected void insertComments(IFormatterContainerNode root) { final List<IFormatterNode> body = root.getBody(); - final List<IFormatterNode> newBody = new ArrayList<IFormatterNode>(); + final List<IFormatterNode> newBody = new ArrayList<>(); boolean changes = false; for (final IFormatterNode node : body) { if (isPlainTextNode(node)) { if (hasComments(node.getStartOffset(), node.getEndOffset())) { - selectValidRanges(root.getDocument(), - node.getStartOffset(), node.getEndOffset(), newBody); + selectValidRanges(root.getDocument(), node.getStartOffset(), + node.getEndOffset(), newBody); changes = true; } else { newBody.add(node); @@ -129,13 +129,12 @@ public abstract class FormatterNodeRewriter { if (start <= comment.endOffset && comment.startOffset <= end) { if (start < comment.startOffset) { int validEnd = Math.min(end, comment.startOffset); - result - .add(new FormatterTextNode(document, start, - validEnd)); + result.add( + new FormatterTextNode(document, start, validEnd)); start = comment.startOffset; } - result.add(createCommentNode(document, start, Math.min( - comment.endOffset, end), comment.object)); + result.add(createCommentNode(document, start, + Math.min(comment.endOffset, end), comment.object)); start = comment.endOffset; if (start > end) { break; diff --git a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterWriter.java b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterWriter.java index f66099137..8a0f91cf4 100644 --- a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterWriter.java +++ b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/FormatterWriter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2016 xored software, Inc. and others. + * Copyright (c) 2008, 2017 xored software, Inc. and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -32,7 +32,7 @@ public class FormatterWriter implements IFormatterWriter { private boolean lineStarted = false; private char lastChar = 0; private int lineNumber = 0; - private final List<IFormatterCallback> newLineCallbacks = new ArrayList<IFormatterCallback>(); + private final List<IFormatterCallback> newLineCallbacks = new ArrayList<>(); private final String lineDelimiter; private final IFormatterDocument document; @@ -65,7 +65,8 @@ public class FormatterWriter implements IFormatterWriter { } @Override - public void write(IFormatterContext context, int startOffset, int endOffset) { + public void write(IFormatterContext context, int startOffset, + int endOffset) { if (!excludes.isExcluded(startOffset, endOffset)) { if (endOffset > startOffset) { write(context, document.get(startOffset, endOffset)); @@ -92,7 +93,8 @@ public class FormatterWriter implements IFormatterWriter { private void trimTrailingSpaces(boolean keepTrimmed) { int length = writer.length(); - while (length > 0 && FormatterUtils.isSpace(writer.charAt(length - 1))) { + while (length > 0 + && FormatterUtils.isSpace(writer.charAt(length - 1))) { --length; } if (keepTrimmed) { @@ -182,28 +184,26 @@ public class FormatterWriter implements IFormatterWriter { } if (wrapLength > 0 && offset > wrapLength) { int begin = start; - while (begin < writer.length() - && FormatterUtils.isSpace(writer.charAt(begin))) { + while (begin < writer.length() && FormatterUtils + .isSpace(writer.charAt(begin))) { ++begin; } if (begin < writer.length() && writer.charAt(begin) == '#') { ++begin; } - while (begin < writer.length() - && FormatterUtils.isSpace(writer.charAt(begin))) { + while (begin < writer.length() && FormatterUtils + .isSpace(writer.charAt(begin))) { ++begin; } int wordBegin = writer.length(); - while (wordBegin > begin - && !FormatterUtils.isSpace(writer - .charAt(wordBegin - 1))) { + while (wordBegin > begin && !FormatterUtils + .isSpace(writer.charAt(wordBegin - 1))) { --wordBegin; } int prevWordEnd = wordBegin; - while (prevWordEnd > begin - && FormatterUtils.isSpace(writer - .charAt(prevWordEnd - 1))) { + while (prevWordEnd > begin && FormatterUtils + .isSpace(writer.charAt(prevWordEnd - 1))) { --prevWordEnd; } if (prevWordEnd > begin) { @@ -281,8 +281,8 @@ public class FormatterWriter implements IFormatterWriter { writer.append(ch); } } else { - if (!preserveSpaces && context.isIndenting() - && !context.isComment() && FormatterUtils.isSpace(ch)) { + if (!preserveSpaces && context.isIndenting() && !context.isComment() + && FormatterUtils.isSpace(ch)) { if (writer.charAt(writer.length() - 1) != ' ') { writer.append(' '); } @@ -376,7 +376,8 @@ public class FormatterWriter implements IFormatterWriter { /** * @since 2.0 */ - protected void writeIndent(IFormatterContext context, StringBuilder buffer) { + protected void writeIndent(IFormatterContext context, + StringBuilder buffer) { indentGenerator.generateIndent(context.getIndent(), buffer); } diff --git a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/internal/ExcludeRegionList.java b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/internal/ExcludeRegionList.java index aeed7fc9d..caec90328 100644 --- a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/internal/ExcludeRegionList.java +++ b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/internal/ExcludeRegionList.java @@ -22,7 +22,7 @@ import org.eclipse.jface.text.Region; public class ExcludeRegionList { - private final List<IRegion> excludes = new ArrayList<IRegion>(); + private final List<IRegion> excludes = new ArrayList<>(); public boolean isExcluded(int start, int end) { if (!excludes.isEmpty()) { @@ -37,7 +37,7 @@ public class ExcludeRegionList { } public IRegion[] selectValidRanges(int start, int end) { - final List<Region> result = new ArrayList<Region>(); + final List<Region> result = new ArrayList<>(); for (final IRegion region : excludes) { final int regionEnd = region.getOffset() + region.getLength(); if (start <= regionEnd && region.getOffset() <= end) { @@ -70,7 +70,8 @@ public class ExcludeRegionList { final int rEnd = r.getOffset() + r.getLength(); if (r.getOffset() <= end && start <= rEnd) { if (region.getOffset() >= r.getOffset() - && region.getOffset() + region.getLength() <= rEnd) { + && region.getOffset() + + region.getLength() <= rEnd) { // new region is inside one of the old regions return; } @@ -95,6 +96,7 @@ public class ExcludeRegionList { Collections.sort(excludes, REGION_COMPARATOR); } - private static final Comparator<IRegion> REGION_COMPARATOR = (o1, o2) -> o1.getOffset() - o2.getOffset(); + private static final Comparator<IRegion> REGION_COMPARATOR = (o1, + o2) -> o1.getOffset() - o2.getOffset(); } diff --git a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/profile/CustomProfile.java b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/profile/CustomProfile.java index 89bc037db..e5676afdf 100644 --- a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/profile/CustomProfile.java +++ b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/profile/CustomProfile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation 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 @@ -7,7 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation - * xored software, Inc. - initial API and Implementation (Yuri Strot) + * xored software, Inc. - initial API and Implementation (Yuri Strot) *******************************************************************************/ package org.eclipse.dltk.formatter.profile; @@ -37,7 +37,7 @@ public class CustomProfile extends Profile implements IProfile.ICustomProfile { @Override public Map<String, String> getSettings() { - return new HashMap<String, String>(fSettings); + return new HashMap<>(fSettings); } @Override @@ -52,14 +52,6 @@ public class CustomProfile extends Profile implements IProfile.ICustomProfile { return fName; } - // public void setManager(ProfileManager profileManager) { - // fManager = profileManager; - // } - // - // public ProfileManager getManager() { - // return fManager; - // } - @Override public int getVersion() { return fVersion; diff --git a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/profile/ProfileManager.java b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/profile/ProfileManager.java index 2d4169dde..8a90bc615 100644 --- a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/profile/ProfileManager.java +++ b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/profile/ProfileManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. + * Copyright (c) 2000, 2017 IBM Corporation 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 @@ -7,7 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation - * xored software, Inc. - initial API and Implementation (Yuri Strot) + * xored software, Inc. - initial API and Implementation (Yuri Strot) *******************************************************************************/ package org.eclipse.dltk.formatter.profile; @@ -45,15 +45,15 @@ public class ProfileManager implements IProfileManager { /** * Create and initialize a new profile manager. - * + * * @param profiles * Initial custom profiles (List of type * <code>CustomProfile</code>) * @param profileVersioner */ public ProfileManager(List<IProfile> profiles) { - fProfiles = new HashMap<String, IProfile>(); - fProfilesByName = new ArrayList<IProfile>(); + fProfiles = new HashMap<>(); + fProfilesByName = new ArrayList<>(); for (final IProfile profile : profiles) { fProfiles.put(profile.getID(), profile); fProfilesByName.add(profile); @@ -69,9 +69,9 @@ public class ProfileManager implements IProfileManager { * Unless the set of profiles has been modified between the two calls, the * sequence is guaranteed to correspond to the one returned by * <code>getSortedNames</code>. - * + * * @return a list of elements of type <code>Profile</code> - * + * * @see #getSortedDisplayNames() */ @Override @@ -84,7 +84,7 @@ public class ProfileManager implements IProfileManager { * alphabetically. Unless the set of profiles has been modified between the * two calls, the sequence is guaranteed to correspond to the one returned * by <code>getSortedProfiles</code>. - * + * * @return All names, sorted alphabetically * @see #getSortedProfiles() */ @@ -100,7 +100,7 @@ public class ProfileManager implements IProfileManager { /** * Get the profile for this profile id. - * + * * @param ID * The profile ID * @return The profile with the given ID or <code>null</code> @@ -185,9 +185,9 @@ public class ProfileManager implements IProfileManager { if (trimmed.equals(profile.getName())) return profile; if (profile.isBuiltInProfile()) { - CustomProfile newProfile = new CustomProfile(trimmed, profile - .getSettings(), profile.getFormatterId(), profile - .getVersion()); + CustomProfile newProfile = new CustomProfile(trimmed, + profile.getSettings(), profile.getFormatterId(), + profile.getVersion()); addProfile(newProfile); fDirty = true; return newProfile; diff --git a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/profile/ProfileStore.java b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/profile/ProfileStore.java index 2ea61d88e..133442f5e 100644 --- a/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/profile/ProfileStore.java +++ b/core/plugins/org.eclipse.dltk.formatter/src/org/eclipse/dltk/formatter/profile/ProfileStore.java @@ -7,7 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation - * xored software, Inc. - initial API and Implementation (Yuri Strot) + * xored software, Inc. - initial API and Implementation (Yuri Strot) *******************************************************************************/ package org.eclipse.dltk.formatter.profile; @@ -91,16 +91,16 @@ public class ProfileStore implements IProfileStore { fFormatter = attributes .getValue(XML_ATTRIBUTE_PROFILE_FORMATTER); try { - fVersion = Integer.parseInt(attributes - .getValue(XML_ATTRIBUTE_VERSION)); + fVersion = Integer.parseInt( + attributes.getValue(XML_ATTRIBUTE_VERSION)); } catch (NumberFormatException ex) { throw new SAXException(ex); } - fSettings = new HashMap<String, String>(200); + fSettings = new HashMap<>(200); } else if (qName.equals(XML_NODE_ROOT)) { - fProfiles = new ArrayList<IProfile>(); + fProfiles = new ArrayList<>(); } } @@ -179,8 +179,8 @@ public class ProfileStore implements IProfileStore { throws CoreException { if (profiles != null && profiles.length() > 0) { byte[] bytes = profiles.getBytes(StandardCharsets.UTF_8); - InputStream is = new ByteArrayInputStream(bytes); - try { + + try (InputStream is = new ByteArrayInputStream(bytes)) { List<IProfile> res = readProfilesFromStream(is); if (res != null) { for (int i = 0; i < res.size(); i++) { @@ -188,11 +188,7 @@ public class ProfileStore implements IProfileStore { } } return res; - } finally { - try { - is.close(); - } catch (IOException e) { /* ignore */ - } + } catch (IOException e) { } } return null; @@ -207,7 +203,7 @@ public class ProfileStore implements IProfileStore { /** * Read the available profiles from the internal XML file and return them as * collection or <code>null</code> if the file is not a profile file. - * + * * @param file * The file to read from * @return returns a list of <code>CustomProfile</code> or <code>null</code> @@ -215,16 +211,8 @@ public class ProfileStore implements IProfileStore { */ @Override public List<IProfile> readProfilesFromFile(File file) throws CoreException { - try { - final FileInputStream reader = new FileInputStream(file); - try { - return readProfilesFromStream(reader); - } finally { - try { - reader.close(); - } catch (IOException e) { /* ignore */ - } - } + try (final FileInputStream reader = new FileInputStream(file)) { + return readProfilesFromStream(reader); } catch (IOException e) { throw createException(e, ProfilesMessages.ProfileStore_readingProblems); @@ -234,7 +222,7 @@ public class ProfileStore implements IProfileStore { /** * Load profiles from a XML stream and add them to a map or * <code>null</code> if the source is not a profile store. - * + * * @param inputSource * The input stream * @return returns a list of <code>CustomProfile</code> or <code>null</code> @@ -263,7 +251,7 @@ public class ProfileStore implements IProfileStore { /** * Write the available profiles to the internal XML file. - * + * * @param profiles * List of <code>CustomProfile</code> * @param file @@ -275,17 +263,8 @@ public class ProfileStore implements IProfileStore { @Override public void writeProfilesToFile(Collection<IProfile> profiles, File file) throws CoreException { - final OutputStream stream; - try { - stream = new FileOutputStream(file); - try { - writeProfilesToStream(profiles, stream, ENCODING, versioner); - } finally { - try { - stream.close(); - } catch (IOException e) { /* ignore */ - } - } + try (final OutputStream stream = new FileOutputStream(file)) { + writeProfilesToStream(profiles, stream, ENCODING, versioner); } catch (IOException e) { throw createException(e, ProfilesMessages.ProfileStore_serializingProblems); @@ -294,7 +273,7 @@ public class ProfileStore implements IProfileStore { /** * Save profiles to an XML stream - * + * * @param profiles * the list of <code>CustomProfile</code> * @param stream @@ -318,8 +297,8 @@ public class ProfileStore implements IProfileStore { for (final IProfile profile : profiles) { if (!profile.isBuiltInProfile()) { - final Element profileElement = createProfileElement( - profile, document, versioner); + final Element profileElement = createProfileElement(profile, + document, versioner); rootElement.appendChild(profileElement); } } @@ -329,8 +308,8 @@ public class ProfileStore implements IProfileStore { transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ transformer.setOutputProperty(OutputKeys.ENCODING, encoding); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ - transformer.transform(new DOMSource(document), new StreamResult( - stream)); + transformer.transform(new DOMSource(document), + new StreamResult(stream)); } catch (TransformerException e) { throw createException(e, ProfilesMessages.ProfileStore_serializingProblems); @@ -353,7 +332,8 @@ public class ProfileStore implements IProfileStore { element.setAttribute(XML_ATTRIBUTE_VERSION, Integer.toString(profile.getVersion())); - for (Map.Entry<String, String> entry : profile.getSettings().entrySet()) { + for (Map.Entry<String, String> entry : profile.getSettings() + .entrySet()) { final String key = entry.getKey(); final String value = entry.getValue(); if (value != null) { @@ -375,8 +355,9 @@ public class ProfileStore implements IProfileStore { /* * Creates a UI exception for logging purposes */ - private static DLTKUIException createException(Throwable t, String message) { - return new DLTKUIException(new Status(IStatus.ERROR, - DLTKUIPlugin.PLUGIN_ID, message, t)); + private static DLTKUIException createException(Throwable t, + String message) { + return new DLTKUIException( + new Status(IStatus.ERROR, DLTKUIPlugin.PLUGIN_ID, message, t)); } } |