1
1
/*******************************************************************************
2
2
* Copyright (c) 2002, 2021 GEBIT Gesellschaft fuer EDV-Beratung
3
- * und Informatik-Technologien mbH,
3
+ * und Informatik-Technologien mbH,
4
4
* Berlin, Duesseldorf, Frankfurt (Germany) and others.
5
5
*
6
- * This program and the accompanying materials
6
+ * This program and the accompanying materials
7
7
* are made available under the terms of the Eclipse Public License 2.0
8
8
* which accompanies this distribution, and is available at
9
9
* https://www.eclipse.org/legal/epl-2.0/
10
10
*
11
11
* SPDX-License-Identifier: EPL-2.0
12
- *
12
+ *
13
13
* Contributors:
14
14
* GEBIT Gesellschaft fuer EDV-Beratung und Informatik-Technologien mbH - initial API and implementation
15
15
* IBM Corporation - bug fixes
16
16
* 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
18
18
* Remy Chi Jian Suen - bug 277587
19
19
*******************************************************************************/
20
20
26
26
import java .io .InputStreamReader ;
27
27
import java .io .Reader ;
28
28
import java .lang .reflect .InvocationTargetException ;
29
+ import java .nio .charset .StandardCharsets ;
29
30
import java .text .MessageFormat ;
30
31
import java .util .ArrayList ;
31
32
import java .util .Arrays ;
@@ -157,7 +158,7 @@ private int getProposalType(Object o) {
157
158
158
159
/**
159
160
* The fully qualified name of the {@link MacroInstance} class
160
- *
161
+ *
161
162
* @since 3.5.500
162
163
*/
163
164
private static final String MACROINSTANCE_NAME = "org.apache.tools.ant.taskdefs.MacroInstance" ; //$NON-NLS-1$
@@ -211,7 +212,7 @@ private int getProposalType(Object o) {
211
212
212
213
/**
213
214
* The proposal mode for the current content assist
214
- *
215
+ *
215
216
* @see #determineProposalMode(IDocument, int, String)
216
217
*/
217
218
private int currentProposalMode = -1 ;
@@ -223,7 +224,7 @@ private int getProposalType(Object o) {
223
224
224
225
/**
225
226
* The current task string for content assist
226
- *
227
+ *
227
228
* @see #determineProposalMode(IDocument, int, String)
228
229
*/
229
230
protected String currentTaskString = null ;
@@ -240,7 +241,7 @@ public AntEditorCompletionProcessor(AntModel model) {
240
241
* Parses the dtd.
241
242
*/
242
243
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 ) ) {
244
245
Parser parser = new Parser ();
245
246
ISchema schema = parser .parseDTD (reader , "project" ); //$NON-NLS-1$
246
247
return schema ;
@@ -602,7 +603,7 @@ private ICompletionProposal[] getTargetProposals(IDocument document, String pref
602
603
603
604
/**
604
605
* 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
+ *
606
607
* @param targetName
607
608
* the target's name
608
609
* @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
657
658
658
659
/**
659
660
* Returns all possible attributes for the specified task.
660
- *
661
+ *
661
662
* @param taskName
662
663
* the name of the task for that the attribute shall be completed
663
664
* @param prefix
@@ -667,9 +668,7 @@ protected ICompletionProposal[] getAttributeProposals(String taskName, String pr
667
668
List <ICompletionProposal > proposals = new ArrayList <>();
668
669
IElement element = getDtd ().getElement (taskName );
669
670
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 ()) {
673
672
if (prefix .length () == 0 || attrName .toLowerCase ().startsWith (prefix )) {
674
673
IAttribute dtdAttributes = element .getAttributes ().get (attrName );
675
674
String replacementString = attrName + "=\" \" " ; //$NON-NLS-1$
@@ -782,9 +781,7 @@ private void addMacroDefAttributeProposals(String taskName, String prefix, List<
782
781
return ;
783
782
}
784
783
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 ) {
788
785
String attributeName = attribute .getName ();
789
786
if (!(prefix .length () == 0 || attributeName .toLowerCase ().startsWith (prefix ))) {
790
787
continue ;
@@ -816,11 +813,9 @@ private void addMacroDefElementProposals(String taskName, String prefix, List<IC
816
813
return ;
817
814
}
818
815
Map <String , TemplateElement > elements = ((MacroDef ) task ).getElements ();
819
- Iterator <String > itr = elements .keySet ().iterator ();
820
816
int prefixLength = prefix .length ();
821
817
int replacementOffset = cursorPosition - prefixLength ;
822
- while (itr .hasNext ()) {
823
- String elementName = itr .next ();
818
+ for (String elementName : elements .keySet ()) {
824
819
if (!(prefixLength == 0 || elementName .toLowerCase ().startsWith (prefix ))) {
825
820
continue ;
826
821
}
@@ -869,13 +864,13 @@ private void addAttributeProposal(String taskName, String prefix, List<ICompleti
869
864
870
865
/**
871
866
* Returns all possible values for the specified attribute of the specified task.
872
- *
867
+ *
873
868
* @param taskName
874
869
* the name of the task that the specified attribute belongs to.
875
- *
870
+ *
876
871
* @param attributeName
877
872
* the name of the attribute for that the value shall be completed
878
- *
873
+ *
879
874
* @param prefix
880
875
* the prefix that all proposals should start with. The prefix may be an empty string.
881
876
*/
@@ -1030,7 +1025,7 @@ protected ICompletionProposal[] getPropertyProposals(IDocument document, String
1030
1025
* Returns all possible proposals for the specified parent name.
1031
1026
* <P>
1032
1027
* No completions will be returned if <code>parentName</code> is not known.
1033
- *
1028
+ *
1034
1029
* @param document
1035
1030
* the entire document
1036
1031
* @param parentName
@@ -1112,10 +1107,10 @@ private boolean areTasksOrTypesValidChildren(String parentName) {
1112
1107
1113
1108
/**
1114
1109
* Returns proposals that define the structure of a build file.
1115
- *
1110
+ *
1116
1111
* Note that template proposals which define the structure of a build file are handled by {@link #determineTemplateProposals(ITextViewer, int)}
1117
1112
* which limits proposals by context type.
1118
- *
1113
+ *
1119
1114
* @param document
1120
1115
* the entire document
1121
1116
* @param prefix
@@ -1173,7 +1168,7 @@ private ICompletionProposal newCompletionProposal(IDocument document, String aPr
1173
1168
1174
1169
/**
1175
1170
* Returns the one possible completion for the specified unclosed task .
1176
- *
1171
+ *
1177
1172
* @param openElementName
1178
1173
* the task that hasn't been closed last
1179
1174
* @param prefix
@@ -1284,7 +1279,7 @@ private boolean hasNestedElements(String elementName) {
1284
1279
* Finds a direct child element with <code>aChildElementName</code> of <code>anElement</code>.
1285
1280
* <P>
1286
1281
* The child will not be searched for in the whole hierarchy but only in the hierarchy step below.
1287
- *
1282
+ *
1288
1283
* @return the found child or <code>null</code> if not found.
1289
1284
*/
1290
1285
protected Element findChildElementNamedOf (Element anElement , String aChildElementName ) {
@@ -1314,7 +1309,7 @@ private String getCurrentPrefix() {
1314
1309
1315
1310
/**
1316
1311
* Returns the prefix in the specified document text with respect to the specified offset.
1317
- *
1312
+ *
1318
1313
* @param aDocumentText
1319
1314
* the whole content of the edited file as String
1320
1315
* @param anOffset
@@ -1449,11 +1444,11 @@ private boolean isPropertyProposalMode(String stringToPrefix) {
1449
1444
* <P>
1450
1445
* The returned string must not necessarily be a valid Ant task string. This can be tested with the method <code>inNamedTaskKnown(String)</code>
1451
1446
* after invoking this method.
1452
- *
1447
+ *
1453
1448
* @param aDocumentStringToPrefix
1454
1449
* the String that contains the whole string of the currently edited file from the beginning up to the prefix for code completion.
1455
1450
* Example: {@literal '<project default="name"><property '}.
1456
- *
1451
+ *
1457
1452
* @return the extracted task string or <code>null</code> if no string could be extracted.
1458
1453
*/
1459
1454
private String getTaskStringFromDocumentStringToPrefix (String aDocumentStringToPrefix ) {
@@ -1563,7 +1558,7 @@ private AntTypeDefinition getTaskClass(String taskName) {
1563
1558
1564
1559
/**
1565
1560
* Finds the parent task element in respect to the cursor position.
1566
- *
1561
+ *
1567
1562
* @return the parent task element or <code>null</code> if not found.
1568
1563
*/
1569
1564
protected String getParentName (IDocument document , int aLineNumber , int aColumnNumber ) {
@@ -1604,7 +1599,7 @@ protected String getParentName(IDocument document, int aLineNumber, int aColumnN
1604
1599
1605
1600
/**
1606
1601
* Return the properties as defined in the entire buildfile
1607
- *
1602
+ *
1608
1603
* @return a map with all the found properties
1609
1604
*/
1610
1605
private Map <String , Object > findPropertiesFromDocument () {
@@ -1642,7 +1637,7 @@ private String getOpenElementName() {
1642
1637
1643
1638
/**
1644
1639
* Finds the enclosing target in respect to the cursor position and returns its name
1645
- *
1640
+ *
1646
1641
* @return the name of the enclosing target or <code>null</code> if not found or the element is not contained in a target.
1647
1642
*/
1648
1643
private String getEnclosingTargetName (IDocument document , int aLineNumber , int aColumnNumber ) {
@@ -1680,7 +1675,7 @@ private int getOffset(IDocument document, int line, int column) {
1680
1675
1681
1676
/**
1682
1677
* Sets this processor's set of characters triggering the activation of the completion proposal computation.
1683
- *
1678
+ *
1684
1679
* @param activationSet
1685
1680
* the activation set
1686
1681
*/
0 commit comments