Skip to content

Commit ed44f19

Browse files
authored
Revert "Explicitencoding cleanup (eclipse-jdt#1631)" (eclipse-jdt#2197)
This reverts commit b69eafb.
1 parent 0d7c003 commit ed44f19

File tree

57 files changed

+117
-11707
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+117
-11707
lines changed

org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/common/ASTProcessor.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2021, 2025 Carsten Hammer.
2+
* Copyright (c) 2021, 2022 Carsten Hammer.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,10 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.jdt.internal.common;
1515

16-
import java.util.AbstractMap;
1716
import java.util.LinkedHashMap;
1817
import java.util.LinkedList;
19-
import java.util.Map;
2018
import java.util.Set;
2119
import java.util.function.BiPredicate;
2220
import java.util.function.Function;
@@ -1199,9 +1197,7 @@ public ASTProcessor<E, V, T> callMethodInvocationVisitor(
11991197
*/
12001198
public ASTProcessor<E, V, T> callMethodInvocationVisitor(String methodname,
12011199
BiPredicate<ASTNode, E> bs) {
1202-
nodetypelist.put(VisitorEnum.MethodInvocation, new NodeHolder(bs, null, Map.ofEntries(
1203-
new AbstractMap.SimpleEntry<>(HelperVisitor.METHODNAME, methodname)
1204-
)));
1200+
nodetypelist.put(VisitorEnum.MethodInvocation, new NodeHolder(bs, null, methodname));
12051201
return this;
12061202
}
12071203

@@ -1213,9 +1209,7 @@ public ASTProcessor<E, V, T> callMethodInvocationVisitor(String methodname,
12131209
*/
12141210
public ASTProcessor<E, V, T> callMethodInvocationVisitor(String methodname,
12151211
BiPredicate<ASTNode, E> bs, Function<ASTNode, ASTNode> navigate) {
1216-
nodetypelist.put(VisitorEnum.MethodInvocation, new NodeHolder(bs, navigate, Map.ofEntries(
1217-
new AbstractMap.SimpleEntry<>(HelperVisitor.METHODNAME, methodname)
1218-
)));
1212+
nodetypelist.put(VisitorEnum.MethodInvocation, new NodeHolder(bs, navigate, methodname));
12191213
return this;
12201214
}
12211215

org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/common/HelperVisitor.java

Lines changed: 5 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2021, 2025 Carsten Hammer.
2+
* Copyright (c) 2021, 2022 Carsten Hammer.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,7 +13,6 @@
1313
*******************************************************************************/
1414
package org.eclipse.jdt.internal.common;
1515

16-
import java.util.AbstractMap;
1716
import java.util.EnumSet;
1817
import java.util.HashMap;
1918
import java.util.LinkedHashMap;
@@ -35,9 +34,6 @@
3534
*/
3635
public class HelperVisitor<E extends HelperVisitorProvider<V, T, E>,V,T> {
3736

38-
public static final String TYPEOF = "typeof"; //$NON-NLS-1$
39-
public static final String METHODNAME = "methodname"; //$NON-NLS-1$
40-
public static final String PARAMTYPENAMES = "paramtypenames"; //$NON-NLS-1$
4137
ASTVisitor astvisitor;
4238

4339
public E dataholder;
@@ -374,20 +370,6 @@ public BiPredicate<? extends ASTNode, E> addClassInstanceCreation(BiPredicate<Cl
374370
return predicatemap.put(VisitorEnum.ClassInstanceCreation, bs);
375371
}
376372

377-
/**
378-
*
379-
* @param typeof class to be instantiated
380-
* @param bs - BiPredicate that can be assigned a lambda expression
381-
* @return - previous BiPredicate registered
382-
*/
383-
public BiPredicate<? extends ASTNode, E> addClassInstanceCreation(Class<?> typeof, BiPredicate<ClassInstanceCreation, E> bs) {
384-
Map<String, Object> map = Map.ofEntries(
385-
new AbstractMap.SimpleEntry<>(TYPEOF, typeof)
386-
);
387-
predicatedata.put(VisitorEnum.ClassInstanceCreation, map);
388-
return predicatemap.put(VisitorEnum.ClassInstanceCreation, bs);
389-
}
390-
391373
/**
392374
* Add BiPredicate to use for CompilationUnit visit
393375
*
@@ -737,27 +719,7 @@ public BiPredicate<? extends ASTNode, E> addMethodInvocation(BiPredicate<MethodI
737719
*/
738720
public BiPredicate<? extends ASTNode, E> addMethodInvocation(String methodname,
739721
BiPredicate<MethodInvocation, E> bs) {
740-
this.predicatedata.put(VisitorEnum.MethodInvocation, Map.ofEntries(
741-
new AbstractMap.SimpleEntry<>(METHODNAME, methodname)
742-
));
743-
return predicatemap.put(VisitorEnum.MethodInvocation, bs);
744-
}
745-
746-
/**
747-
* Add BiPredicate to use for MethodInvocation visit where class and method name is specified
748-
*
749-
* @param typeof class whose method is called
750-
* @param methodname name of the method that is called
751-
* @param bs BiPredicate that can be assigned a lambda expression
752-
* @return previous BiPredicate registered
753-
*/
754-
public BiPredicate<? extends ASTNode, E> addMethodInvocation(Class<?> typeof, String methodname,
755-
BiPredicate<MethodInvocation, E> bs) {
756-
Map<String, Object> map = Map.ofEntries(
757-
new AbstractMap.SimpleEntry<>(METHODNAME, methodname),
758-
new AbstractMap.SimpleEntry<>(TYPEOF, typeof)
759-
);
760-
predicatedata.put(VisitorEnum.MethodInvocation, map);
722+
this.predicatedata.put(VisitorEnum.MethodInvocation, methodname);
761723
return predicatemap.put(VisitorEnum.MethodInvocation, bs);
762724
}
763725

@@ -1522,9 +1484,7 @@ public BiConsumer<? extends ASTNode, E> addMethodInvocation(BiConsumer<MethodInv
15221484
}
15231485

15241486
public BiConsumer<? extends ASTNode, E> addMethodInvocation(String methodname, BiConsumer<MethodInvocation, E> bc) {
1525-
this.consumerdata.put(VisitorEnum.MethodInvocation, Map.ofEntries(
1526-
new AbstractMap.SimpleEntry<>(METHODNAME, methodname)
1527-
));
1487+
this.consumerdata.put(VisitorEnum.MethodInvocation, methodname);
15281488
return consumermap.put(VisitorEnum.MethodInvocation, bc);
15291489
}
15301490

@@ -2220,51 +2180,24 @@ public void addMethodDeclaration(BiPredicate<MethodDeclaration, E> bs, BiConsume
22202180

22212181
/**
22222182
*
2223-
* @param methodname Only visit MethodInvocation with this name
2224-
* @param bs - BiPredicate that is visited when a MethodInvocation is found
2225-
* @param bc - BiConsumer that is visited at the end after a MethodInvocation has been found
2183+
* @param bs - BiPredicate that can be assigned a lambda expression
22262184
*/
22272185
public void addMethodInvocation(String methodname, BiPredicate<MethodInvocation, E> bs,
22282186
BiConsumer<MethodInvocation, E> bc) {
2229-
predicatedata.put(VisitorEnum.MethodInvocation, Map.ofEntries(
2230-
new AbstractMap.SimpleEntry<>(METHODNAME, methodname)
2231-
));
2232-
predicatemap.put(VisitorEnum.MethodInvocation, bs);
2233-
consumerdata.put(VisitorEnum.MethodInvocation, Map.ofEntries(
2234-
new AbstractMap.SimpleEntry<>(METHODNAME, methodname)
2235-
));
2236-
consumermap.put(VisitorEnum.MethodInvocation, bc);
2237-
}
2238-
2239-
/**
2240-
* @param typeof Only visit MethodInvocation calling a method of this class
2241-
* @param methodname Only visit MethodInvocation with this name
2242-
* @param bs - BiPredicate that is visited when a MethodInvocation is found
2243-
* @param bc - BiConsumer that is visited at the end after a MethodInvocation has been found
2244-
*/
2245-
public void addMethodInvocation(Class<?> typeof, String methodname, BiPredicate<MethodInvocation, E> bs,
2246-
BiConsumer<MethodInvocation, E> bc) {
2247-
Map<String, Object> map = Map.ofEntries(
2248-
new AbstractMap.SimpleEntry<>(METHODNAME, methodname),
2249-
new AbstractMap.SimpleEntry<>(TYPEOF, typeof)
2250-
);
2251-
predicatedata.put(VisitorEnum.MethodInvocation, map);
2187+
this.predicatedata.put(VisitorEnum.MethodInvocation, methodname);
22522188
predicatemap.put(VisitorEnum.MethodInvocation, bs);
2253-
consumerdata.put(VisitorEnum.MethodInvocation, map);
22542189
consumermap.put(VisitorEnum.MethodInvocation, bc);
22552190
}
22562191

22572192
/**
22582193
*
22592194
* @param bs - BiPredicate that can be assigned a lambda expression
2260-
* @param bc - BiConsumer that is visited at the end after a MethodInvocation has been found
22612195
*/
22622196
public void addMethodInvocation(BiPredicate<MethodInvocation, E> bs, BiConsumer<MethodInvocation, E> bc) {
22632197
predicatemap.put(VisitorEnum.MethodInvocation, bs);
22642198
consumermap.put(VisitorEnum.MethodInvocation, bc);
22652199
}
22662200

2267-
22682201
/**
22692202
*
22702203
* @param bs - BiPredicate that can be assigned a lambda expression
@@ -3495,13 +3428,6 @@ public static <V, T> void callMethodInvocationVisitor(String methodname, ASTNode
34953428
hv.build(node);
34963429
}
34973430

3498-
public static <V, T> void callMethodInvocationVisitor(Class<?> methodof, String methodname, ASTNode node, ReferenceHolder<V, T> dataholder, Set<ASTNode> nodesprocessed,
3499-
BiPredicate<MethodInvocation, ReferenceHolder<V, T>> bs) {
3500-
3501-
HelperVisitor<ReferenceHolder<V, T>,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
3502-
hv.addMethodInvocation(methodof, methodname, bs);
3503-
hv.build(node);
3504-
}
35053431
/**
35063432
*
35073433
* @param nodesprocessed - set of nodes processed
@@ -5701,13 +5627,6 @@ public static <V, T> void callClassInstanceCreationVisitor(ASTNode node, Referen
57015627
hv.build(node);
57025628
}
57035629

5704-
public static <V, T> void callClassInstanceCreationVisitor(Class<?> class1, ASTNode node, ReferenceHolder<V, T> dataholder, Set<ASTNode> nodesprocessed,
5705-
BiPredicate<ClassInstanceCreation, ReferenceHolder<V, T>> bs) {
5706-
5707-
HelperVisitor<ReferenceHolder<V, T>,V,T> hv= new HelperVisitor<>(nodesprocessed, dataholder);
5708-
hv.addClassInstanceCreation(class1, bs);
5709-
hv.build(node);
5710-
}
57115630
/**
57125631
*
57135632
* @param nodesprocessed - set of nodes processed

org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/common/LambdaASTVisitor.java

Lines changed: 24 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2021, 2025 Carsten Hammer.
2+
* Copyright (c) 2021, 2022 Carsten Hammer.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,28 +13,21 @@
1313
*******************************************************************************/
1414
package org.eclipse.jdt.internal.common;
1515

16-
import java.util.Map;
1716
import java.util.function.BiConsumer;
1817
import java.util.function.BiPredicate;
1918

2019
import org.eclipse.jdt.core.dom.*;
2120

22-
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
23-
2421
/**
2522
*
2623
* @author chammer
2724
*
2825
* @param <E> - type that extends HelpVisitorProvider that provides {@code HelperVisitor<V, T>}
2926
* @param <V> - type that HelperVisitor uses as map key type
3027
* @param <T> - type that HelperVisitor uses as map value type
31-
* @since 1.15
3228
*/
33-
@SuppressWarnings({ "unchecked" })
29+
@SuppressWarnings("unchecked")
3430
public class LambdaASTVisitor<E extends HelperVisitorProvider<V,T,E>, V, T> extends ASTVisitor {
35-
/**
36-
*
37-
*/
3831
private final HelperVisitor<E,V,T> helperVisitor;
3932

4033
/**
@@ -197,16 +190,6 @@ public boolean visit(CharacterLiteral node) {
197190
@Override
198191
public boolean visit(ClassInstanceCreation node) {
199192
if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.ClassInstanceCreation)) {
200-
Map<String, Object> map=(Map<String, Object>) this.helperVisitor.getSupplierData().get(VisitorEnum.ClassInstanceCreation);
201-
if(map != null) {
202-
Class<?> typeof=(Class<?>) map.get(HelperVisitor.TYPEOF);
203-
if(typeof!=null) {
204-
ITypeBinding binding= node.resolveTypeBinding();
205-
if (!typeof.getSimpleName().equals(binding.getName())) {
206-
return true;
207-
}
208-
}
209-
}
210193
return ((BiPredicate<ClassInstanceCreation, E>) (this.helperVisitor.predicatemap
211194
.get(VisitorEnum.ClassInstanceCreation))).test(node, this.helperVisitor.dataholder);
212195
}
@@ -513,25 +496,9 @@ public boolean visit(MethodDeclaration node) {
513496
@Override
514497
public boolean visit(MethodInvocation node) {
515498
if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.MethodInvocation)) {
516-
Map<String, Object> map=(Map<String, Object>) this.helperVisitor.getSupplierData().get(VisitorEnum.MethodInvocation);
517-
if(map != null) {
518-
String data=(String) map.get(HelperVisitor.METHODNAME);
519-
if ((data!= null) && !node.getName().getIdentifier().equals(data)) {
520-
return true;
521-
}
522-
Class<?> typeof=(Class<?>) map.get(HelperVisitor.TYPEOF);
523-
String[] parameterTypesQualifiedNames=(String[]) map.get(HelperVisitor.PARAMTYPENAMES);
524-
525-
if(typeof!=null) {
526-
if(parameterTypesQualifiedNames==null) {
527-
if (ASTNodes.usesGivenSignature(node, typeof.getCanonicalName(), data)) {
528-
return ((BiPredicate<MethodInvocation, E>) (this.helperVisitor.predicatemap.get(VisitorEnum.MethodInvocation))).test(node, this.helperVisitor.dataholder);
529-
}
530-
} else
531-
if (ASTNodes.usesGivenSignature(node, typeof.getCanonicalName(), data, parameterTypesQualifiedNames)) {
532-
return ((BiPredicate<MethodInvocation, E>) (this.helperVisitor.predicatemap.get(VisitorEnum.MethodInvocation))).test(node, this.helperVisitor.dataholder);
533-
}
534-
}
499+
String data=(String) this.helperVisitor.getSupplierData().get(VisitorEnum.MethodInvocation);
500+
if (data!= null && !node.getName().getIdentifier().equals(data)) {
501+
return true;
535502
}
536503
return ((BiPredicate<MethodInvocation, E>) (this.helperVisitor.predicatemap.get(VisitorEnum.MethodInvocation))).test(node, this.helperVisitor.dataholder);
537504
}
@@ -982,17 +949,14 @@ public boolean visit(VariableDeclarationExpression node) {
982949
@Override
983950
public boolean visit(VariableDeclarationStatement node) {
984951
if (this.helperVisitor.predicatemap.containsKey(VisitorEnum.VariableDeclarationStatement)) {
985-
Map<String, Object> map=(Map<String, Object>)this.helperVisitor.getConsumerData().get(VisitorEnum.VariableDeclarationStatement);
986-
if(map != null) {
987-
Class<?> data=(Class<?>) map.get(HelperVisitor.TYPEOF);
988-
if (data!= null) {
989-
VariableDeclarationFragment bli = (VariableDeclarationFragment) node.fragments().get(0);
990-
IVariableBinding resolveBinding = bli.resolveBinding();
991-
if(resolveBinding!=null) {
992-
String qualifiedName = resolveBinding.getType().getErasure().getQualifiedName();
993-
if (!data.getCanonicalName().equals(qualifiedName)) {
994-
return true;
995-
}
952+
Class<?> data=(Class<?>) this.helperVisitor.getSupplierData().get(VisitorEnum.VariableDeclarationStatement);
953+
if (data!= null) {
954+
VariableDeclarationFragment bli = (VariableDeclarationFragment) node.fragments().get(0);
955+
IVariableBinding resolveBinding = bli.resolveBinding();
956+
if(resolveBinding!=null) {
957+
String qualifiedName = resolveBinding.getType().getErasure().getQualifiedName();
958+
if (!data.getCanonicalName().equals(qualifiedName)) {
959+
return true;
996960
}
997961
}
998962
}
@@ -1424,18 +1388,9 @@ public void endVisit(MethodDeclaration node) {
14241388
@Override
14251389
public void endVisit(MethodInvocation node) {
14261390
if (this.helperVisitor.consumermap.containsKey(VisitorEnum.MethodInvocation)) {
1427-
Map<String, Object> map=(Map<String, Object>) this.helperVisitor.getConsumerData().get(VisitorEnum.MethodInvocation);
1428-
if(map != null) {
1429-
String data=(String) map.get(HelperVisitor.METHODNAME);
1430-
if ((data!= null) && !node.getName().getIdentifier().equals(data)) {
1431-
return;
1432-
}
1433-
Class<?> typeof=(Class<?>) map.get(HelperVisitor.TYPEOF);
1434-
if(typeof!=null) {
1435-
if (!ASTNodes.usesGivenSignature(node, typeof.getCanonicalName(), data)) {
1436-
return;
1437-
}
1438-
}
1391+
String data=(String) this.helperVisitor.getConsumerData().get(VisitorEnum.MethodInvocation);
1392+
if (data!= null && !node.getName().getIdentifier().equals(data)) {
1393+
return;
14391394
}
14401395
((BiConsumer<MethodInvocation, E>) (this.helperVisitor.consumermap.get(VisitorEnum.MethodInvocation))).accept(node,
14411396
this.helperVisitor.dataholder);
@@ -1819,17 +1774,14 @@ public void endVisit(VariableDeclarationExpression node) {
18191774
@Override
18201775
public void endVisit(VariableDeclarationStatement node) {
18211776
if (this.helperVisitor.consumermap.containsKey(VisitorEnum.VariableDeclarationStatement)) {
1822-
Map<String, Object> map=(Map<String, Object>)this.helperVisitor.getConsumerData().get(VisitorEnum.VariableDeclarationStatement);
1823-
if(map != null) {
1824-
Class<?> data=(Class<?>) map.get(HelperVisitor.TYPEOF);
1825-
if (data!= null) {
1826-
VariableDeclarationFragment bli = (VariableDeclarationFragment) node.fragments().get(0);
1827-
IVariableBinding resolveBinding = bli.resolveBinding();
1828-
if(resolveBinding!=null) {
1829-
String qualifiedName = resolveBinding.getType().getErasure().getQualifiedName();
1830-
if (!data.getCanonicalName().equals(qualifiedName)) {
1831-
return;
1832-
}
1777+
Class<?> data=(Class<?>) this.helperVisitor.getConsumerData().get(VisitorEnum.VariableDeclarationStatement);
1778+
if (data!= null) {
1779+
VariableDeclarationFragment bli = (VariableDeclarationFragment) node.fragments().get(0);
1780+
IVariableBinding resolveBinding = bli.resolveBinding();
1781+
if(resolveBinding!=null) {
1782+
String qualifiedName = resolveBinding.getType().getErasure().getQualifiedName();
1783+
if (!data.getCanonicalName().equals(qualifiedName)) {
1784+
return;
18331785
}
18341786
}
18351787
}

org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ private MultiFixMessages() {
211211
public static String StringConcatToTextBlockCleanUp_description;
212212
public static String StringConcatToTextBlockStringBuffer_description;
213213
public static String StringBuilderForLocalVarsOnlyCleanUp_description;
214-
public static String ExplicitEncodingCleanUp_description;
215-
public static String ExplicitEncodingCleanUpFix_refactor;
216214

217215
static {
218216
// initialize resource bundle

org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/MultiFixMessages.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,3 @@ StringBufferToStringBuilderCleanUp_description=Convert StringBuffer to StringBui
193193
StringConcatToTextBlockCleanUp_description=Convert String concatenation to Text Block
194194
StringConcatToTextBlockStringBuffer_description=Convert String/StringBuffer/StringBuilder concatenation to Text Block
195195
StringBuilderForLocalVarsOnlyCleanUp_description=Convert StringBuffer to StringBuilder for local variables
196-
ExplicitEncodingCleanUp_description=Set explicit encoding or default encoding where applicable using {0}
197-
ExplicitEncodingCleanUpFix_refactor=Use explicit encoding

0 commit comments

Comments
 (0)