Skip to content

Commit 4f85198

Browse files
EcljpseB0Tjukzi
authored andcommitted
Replace "UTF-8" with StandardCharsets.UTF_8
Avoids NON-NLS and possible UnsupportedEncodingException
1 parent f97233b commit 4f85198

File tree

8 files changed

+72
-63
lines changed

8 files changed

+72
-63
lines changed

ant/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditorCompletionProcessor.java

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/*******************************************************************************
22
* Copyright (c) 2002, 2021 GEBIT Gesellschaft fuer EDV-Beratung
3-
* und Informatik-Technologien mbH,
3+
* und Informatik-Technologien mbH,
44
* Berlin, Duesseldorf, Frankfurt (Germany) and others.
55
*
6-
* This program and the accompanying materials
6+
* This program and the accompanying materials
77
* are made available under the terms of the Eclipse Public License 2.0
88
* which accompanies this distribution, and is available at
99
* https://www.eclipse.org/legal/epl-2.0/
1010
*
1111
* SPDX-License-Identifier: EPL-2.0
12-
*
12+
*
1313
* Contributors:
1414
* GEBIT Gesellschaft fuer EDV-Beratung und Informatik-Technologien mbH - initial API and implementation
1515
* IBM Corporation - bug fixes
1616
* John-Mason P. Shackelford ([email protected]) - bug 49383, 56299, 59024
17-
* Brock Janiczak ([email protected] ) - bug 78028, 78030
17+
* Brock Janiczak ([email protected] ) - bug 78028, 78030
1818
* Remy Chi Jian Suen - bug 277587
1919
*******************************************************************************/
2020

@@ -26,6 +26,7 @@
2626
import java.io.InputStreamReader;
2727
import java.io.Reader;
2828
import java.lang.reflect.InvocationTargetException;
29+
import java.nio.charset.StandardCharsets;
2930
import java.text.MessageFormat;
3031
import java.util.ArrayList;
3132
import java.util.Arrays;
@@ -157,7 +158,7 @@ private int getProposalType(Object o) {
157158

158159
/**
159160
* The fully qualified name of the {@link MacroInstance} class
160-
*
161+
*
161162
* @since 3.5.500
162163
*/
163164
private static final String MACROINSTANCE_NAME = "org.apache.tools.ant.taskdefs.MacroInstance"; //$NON-NLS-1$
@@ -211,7 +212,7 @@ private int getProposalType(Object o) {
211212

212213
/**
213214
* The proposal mode for the current content assist
214-
*
215+
*
215216
* @see #determineProposalMode(IDocument, int, String)
216217
*/
217218
private int currentProposalMode = -1;
@@ -223,7 +224,7 @@ private int getProposalType(Object o) {
223224

224225
/**
225226
* The current task string for content assist
226-
*
227+
*
227228
* @see #determineProposalMode(IDocument, int, String)
228229
*/
229230
protected String currentTaskString = null;
@@ -240,7 +241,7 @@ public AntEditorCompletionProcessor(AntModel model) {
240241
* Parses the dtd.
241242
*/
242243
private ISchema parseDtd() throws ParseError, IOException {
243-
try (InputStream stream = getClass().getResourceAsStream(ANT_DTD_FILENAME); Reader reader = new InputStreamReader(stream, "UTF-8");) {//$NON-NLS-1$
244+
try (InputStream stream = getClass().getResourceAsStream(ANT_DTD_FILENAME); Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
244245
Parser parser = new Parser();
245246
ISchema schema = parser.parseDTD(reader, "project"); //$NON-NLS-1$
246247
return schema;
@@ -602,7 +603,7 @@ private ICompletionProposal[] getTargetProposals(IDocument document, String pref
602603

603604
/**
604605
* Retrieves the representative image of a target of the given name. If the target cannot be found, <code>null</code> will be returned.
605-
*
606+
*
606607
* @param targetName
607608
* the target's name
608609
* @return an image suitable for representing the target, or <code>null</code> if the target cannot be found
@@ -657,7 +658,7 @@ private ICompletionProposal[] getDependsValueProposals(IDocument document, Strin
657658

658659
/**
659660
* Returns all possible attributes for the specified task.
660-
*
661+
*
661662
* @param taskName
662663
* the name of the task for that the attribute shall be completed
663664
* @param prefix
@@ -667,9 +668,7 @@ protected ICompletionProposal[] getAttributeProposals(String taskName, String pr
667668
List<ICompletionProposal> proposals = new ArrayList<>();
668669
IElement element = getDtd().getElement(taskName);
669670
if (element != null) {
670-
Iterator<String> keys = element.getAttributes().keySet().iterator();
671-
while (keys.hasNext()) {
672-
String attrName = keys.next();
671+
for (String attrName : element.getAttributes().keySet()) {
673672
if (prefix.length() == 0 || attrName.toLowerCase().startsWith(prefix)) {
674673
IAttribute dtdAttributes = element.getAttributes().get(attrName);
675674
String replacementString = attrName + "=\"\""; //$NON-NLS-1$
@@ -782,9 +781,7 @@ private void addMacroDefAttributeProposals(String taskName, String prefix, List<
782781
return;
783782
}
784783
List<Attribute> attributes = ((MacroDef) task).getAttributes();
785-
Iterator<Attribute> itr = attributes.iterator();
786-
while (itr.hasNext()) {
787-
MacroDef.Attribute attribute = itr.next();
784+
for (Attribute attribute : attributes) {
788785
String attributeName = attribute.getName();
789786
if (!(prefix.length() == 0 || attributeName.toLowerCase().startsWith(prefix))) {
790787
continue;
@@ -816,11 +813,9 @@ private void addMacroDefElementProposals(String taskName, String prefix, List<IC
816813
return;
817814
}
818815
Map<String, TemplateElement> elements = ((MacroDef) task).getElements();
819-
Iterator<String> itr = elements.keySet().iterator();
820816
int prefixLength = prefix.length();
821817
int replacementOffset = cursorPosition - prefixLength;
822-
while (itr.hasNext()) {
823-
String elementName = itr.next();
818+
for (String elementName : elements.keySet()) {
824819
if (!(prefixLength == 0 || elementName.toLowerCase().startsWith(prefix))) {
825820
continue;
826821
}
@@ -869,13 +864,13 @@ private void addAttributeProposal(String taskName, String prefix, List<ICompleti
869864

870865
/**
871866
* Returns all possible values for the specified attribute of the specified task.
872-
*
867+
*
873868
* @param taskName
874869
* the name of the task that the specified attribute belongs to.
875-
*
870+
*
876871
* @param attributeName
877872
* the name of the attribute for that the value shall be completed
878-
*
873+
*
879874
* @param prefix
880875
* the prefix that all proposals should start with. The prefix may be an empty string.
881876
*/
@@ -1030,7 +1025,7 @@ protected ICompletionProposal[] getPropertyProposals(IDocument document, String
10301025
* Returns all possible proposals for the specified parent name.
10311026
* <P>
10321027
* No completions will be returned if <code>parentName</code> is not known.
1033-
*
1028+
*
10341029
* @param document
10351030
* the entire document
10361031
* @param parentName
@@ -1112,10 +1107,10 @@ private boolean areTasksOrTypesValidChildren(String parentName) {
11121107

11131108
/**
11141109
* Returns proposals that define the structure of a build file.
1115-
*
1110+
*
11161111
* Note that template proposals which define the structure of a build file are handled by {@link #determineTemplateProposals(ITextViewer, int)}
11171112
* which limits proposals by context type.
1118-
*
1113+
*
11191114
* @param document
11201115
* the entire document
11211116
* @param prefix
@@ -1173,7 +1168,7 @@ private ICompletionProposal newCompletionProposal(IDocument document, String aPr
11731168

11741169
/**
11751170
* Returns the one possible completion for the specified unclosed task .
1176-
*
1171+
*
11771172
* @param openElementName
11781173
* the task that hasn't been closed last
11791174
* @param prefix
@@ -1284,7 +1279,7 @@ private boolean hasNestedElements(String elementName) {
12841279
* Finds a direct child element with <code>aChildElementName</code> of <code>anElement</code>.
12851280
* <P>
12861281
* The child will not be searched for in the whole hierarchy but only in the hierarchy step below.
1287-
*
1282+
*
12881283
* @return the found child or <code>null</code> if not found.
12891284
*/
12901285
protected Element findChildElementNamedOf(Element anElement, String aChildElementName) {
@@ -1314,7 +1309,7 @@ private String getCurrentPrefix() {
13141309

13151310
/**
13161311
* Returns the prefix in the specified document text with respect to the specified offset.
1317-
*
1312+
*
13181313
* @param aDocumentText
13191314
* the whole content of the edited file as String
13201315
* @param anOffset
@@ -1449,11 +1444,11 @@ private boolean isPropertyProposalMode(String stringToPrefix) {
14491444
* <P>
14501445
* The returned string must not necessarily be a valid Ant task string. This can be tested with the method <code>inNamedTaskKnown(String)</code>
14511446
* after invoking this method.
1452-
*
1447+
*
14531448
* @param aDocumentStringToPrefix
14541449
* the String that contains the whole string of the currently edited file from the beginning up to the prefix for code completion.
14551450
* Example: {@literal '<project default="name"><property '}.
1456-
*
1451+
*
14571452
* @return the extracted task string or <code>null</code> if no string could be extracted.
14581453
*/
14591454
private String getTaskStringFromDocumentStringToPrefix(String aDocumentStringToPrefix) {
@@ -1563,7 +1558,7 @@ private AntTypeDefinition getTaskClass(String taskName) {
15631558

15641559
/**
15651560
* Finds the parent task element in respect to the cursor position.
1566-
*
1561+
*
15671562
* @return the parent task element or <code>null</code> if not found.
15681563
*/
15691564
protected String getParentName(IDocument document, int aLineNumber, int aColumnNumber) {
@@ -1604,7 +1599,7 @@ protected String getParentName(IDocument document, int aLineNumber, int aColumnN
16041599

16051600
/**
16061601
* Return the properties as defined in the entire buildfile
1607-
*
1602+
*
16081603
* @return a map with all the found properties
16091604
*/
16101605
private Map<String, Object> findPropertiesFromDocument() {
@@ -1642,7 +1637,7 @@ private String getOpenElementName() {
16421637

16431638
/**
16441639
* Finds the enclosing target in respect to the cursor position and returns its name
1645-
*
1640+
*
16461641
* @return the name of the enclosing target or <code>null</code> if not found or the element is not contained in a target.
16471642
*/
16481643
private String getEnclosingTargetName(IDocument document, int aLineNumber, int aColumnNumber) {
@@ -1680,7 +1675,7 @@ private int getOffset(IDocument document, int line, int column) {
16801675

16811676
/**
16821677
* Sets this processor's set of characters triggering the activation of the completion proposal computation.
1683-
*
1678+
*
16841679
* @param activationSet
16851680
* the activation set
16861681
*/

0 commit comments

Comments
 (0)