Skip to content

Commit d1d8191

Browse files
author
zhourenjian
committed
Fixed bug#1844475 List.iterator does not return a valid iterator.
Compiler trying to remove brackets results in incorrect qualified name. For example: java.util.AbstractList<E>.SimpleListIterator results in java.util.AbstractList, which is wrong.
1 parent 305b32a commit d1d8191

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

src/net/sf/j2s/core/astvisitors/ASTTypeVisitor.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ public String discardGenericType(String name) {
7070
if (name == null) {
7171
return null;
7272
}
73-
int index = name.indexOf('<');
74-
if (index != -1) {
75-
name = name.substring(0, index).trim();
76-
}
77-
return name;
73+
return Bindings.removeBrackets(name);
7874
}
7975

8076
/**
@@ -126,11 +122,8 @@ public boolean isInheritedClassName(ITypeBinding binding, String name) {
126122
* @return
127123
*/
128124
public String shortenQualifiedName(String name) {
129-
int index = name.indexOf('<');
130-
if (index != -1) {
131-
name = name.substring(0, index).trim();
132-
}
133-
index = name.indexOf("java.lang.");
125+
name = Bindings.removeBrackets(name);
126+
int index = name.indexOf("java.lang.");
134127
char ch = 0;
135128
if (index != -1
136129
&& (name.indexOf('.', index + 10) == -1 || ((ch = name
@@ -170,11 +163,8 @@ public String shortenQualifiedName(String name) {
170163

171164
public String shortenPackageName(String fullName) {
172165
String name = fullName.substring(0, fullName.lastIndexOf('.'));
173-
int index = name.indexOf('<');
174-
if (index != -1) {
175-
name = name.substring(0, index).trim();
176-
}
177-
index = name.indexOf("java.lang.");
166+
name = Bindings.removeBrackets(name);
167+
int index = name.indexOf("java.lang.");
178168
char ch = 0;
179169
if (index != -1
180170
&& (name.indexOf('.', index + 10) == -1 || ((ch = name

src/net/sf/j2s/core/astvisitors/Bindings.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
3131
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
3232
import org.eclipse.jdt.core.dom.Assignment;
33-
import org.eclipse.jdt.core.dom.EnumDeclaration;
3433
import org.eclipse.jdt.core.dom.Expression;
3534
import org.eclipse.jdt.core.dom.FieldAccess;
3635
import org.eclipse.jdt.core.dom.IBinding;
@@ -43,7 +42,6 @@
4342
import org.eclipse.jdt.core.dom.QualifiedName;
4443
import org.eclipse.jdt.core.dom.SimpleName;
4544
import org.eclipse.jdt.core.dom.SuperFieldAccess;
46-
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
4745

4846
public class Bindings {
4947

@@ -223,6 +221,8 @@ public static String getTypeQualifiedName(ITypeBinding type) {
223221
*/
224222
public static String getFullyQualifiedName(ITypeBinding type) {
225223
String name= type.getQualifiedName();
224+
// TODO: ?
225+
// return removeBrackets(name);
226226
final int index= name.indexOf('<');
227227
if (index > 0)
228228
name= name.substring(0, index);
@@ -930,10 +930,14 @@ public static boolean isEqualMethod(IMethodBinding method, String methodName, St
930930
int index;
931931
for (int i= 0; i < parameters.length; i++) {
932932
first= parameters[i];
933+
// TODO: ?
934+
// first = removeBrackets(first);
933935
index= first.indexOf('<');
934936
if (index > 0)
935937
first= first.substring(0, index);
936938
second= methodParameters[i].getErasure().getQualifiedName();
939+
// TODO: ?
940+
// second = removeBrackets(second);
937941
index= second.indexOf('<');
938942
if (index > 0)
939943
second= second.substring(0, index);
@@ -1125,6 +1129,7 @@ private static boolean sameParameter(ITypeBinding type, String candidate, IType
11251129
return false;
11261130
}
11271131

1132+
/*
11281133
private static boolean isPrimitiveType(String s) {
11291134
return Signature.getTypeSignatureKind(s) == Signature.BASE_TYPE_SIGNATURE;
11301135
}
@@ -1133,6 +1138,7 @@ private static boolean isResolvedType(String s) {
11331138
int arrayCount= Signature.getArrayCount(s);
11341139
return s.charAt(arrayCount) == Signature.C_RESOLVED;
11351140
}
1141+
*/
11361142

11371143
/**
11381144
* Normalizes a type binding received from an expression to a type binding that can be used in a declaration signature.
@@ -1208,6 +1214,8 @@ public static ITypeBinding getBindingOfParentType(ASTNode node) {
12081214
public static String getRawName(ITypeBinding binding) {
12091215
String name= binding.getName();
12101216
if (binding.isParameterizedType() || binding.isGenericType()) {
1217+
// TODO: ?
1218+
// return removeBrackets(name);
12111219
int idx= name.indexOf('<');
12121220
if (idx != -1) {
12131221
return name.substring(0, idx);
@@ -1419,4 +1427,23 @@ public static boolean isMethodInvoking(Expression exp, String className, String
14191427
}
14201428
return false;
14211429
}
1430+
1431+
public static String removeBrackets(String qName) {
1432+
int length = qName.length();
1433+
StringBuffer buf = new StringBuffer();
1434+
int ltCount = 0;
1435+
for (int i = 0; i < length; i++) {
1436+
char c = qName.charAt(i);
1437+
if (c == '<') {
1438+
ltCount++;
1439+
} else if (c == '>') {
1440+
ltCount--;
1441+
}
1442+
if (ltCount == 0 && c != '>') {
1443+
buf.append(c);
1444+
}
1445+
}
1446+
qName = buf.toString().trim();
1447+
return qName;
1448+
}
14221449
}

0 commit comments

Comments
 (0)