Skip to content

Commit 7386823

Browse files
author
jossonsmith
committed
Fixed a bug so that referencing by type literal "ClassABC.this" will put class
ClassABC into optional imports list. And class java.lang.*Error or java.lang.*Exception are now generated as full qualified name not as ther former *Error or *Exception. Because these classes are usually used in try and catch blocks. This modification will let the browser tree those yet not loaded *Error/Exception classes as nulls. So those *Error/Exception classes may not be in the optinal import list.
1 parent 912c114 commit 7386823

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/DependencyASTVisitor.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.eclipse.jdt.core.dom.TextElement;
4444
import org.eclipse.jdt.core.dom.Type;
4545
import org.eclipse.jdt.core.dom.TypeDeclaration;
46+
import org.eclipse.jdt.core.dom.TypeLiteral;
4647
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
4748

4849
/**
@@ -414,6 +415,30 @@ protected void readClasses(TagElement tagEl, Set set) {
414415
}
415416
}
416417
}
418+
/* (non-Javadoc)
419+
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TypeLiteral)
420+
*/
421+
public boolean visit(TypeLiteral node) {
422+
ITypeBinding resolveTypeBinding = node.getType().resolveBinding();
423+
ITypeBinding declaringClass = resolveTypeBinding.getDeclaringClass();
424+
QNTypeBinding qn = new QNTypeBinding();
425+
String qualifiedName = null;
426+
if (declaringClass != null) {
427+
qualifiedName = declaringClass.getQualifiedName();
428+
qn.binding = declaringClass;
429+
} else {
430+
qualifiedName = resolveTypeBinding.getQualifiedName();
431+
qn.binding = resolveTypeBinding;
432+
}
433+
qualifiedName = JavaLangUtil.ripGeneric(qualifiedName);
434+
qn.qualifiedName = qualifiedName;
435+
if (isQualifiedNameOK(qualifiedName, node)
436+
&& !musts.contains(qn)
437+
&& !requires.contains(qn)) {
438+
optionals.add(qn);
439+
}
440+
return false;
441+
}
417442
/*
418443
* (non-Javadoc)
419444
*

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/JavaLangUtil.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ public static String ripJavaLang(String name) {
2424
|| ((ch = name.charAt(index + 10)) >= 'A' && ch <= 'Z'))) {
2525
// ((idx2 = name.indexOf('.', index + 10)) == -1
2626
// || !name.substring(index + 10, idx2).startsWith ("ref"))) {
27-
name = name.substring(10);
27+
if (name.indexOf ("Error") != -1 || name.indexOf("Exception") != -1
28+
|| name.indexOf("ThreadDeath") != -1) {
29+
30+
} else {
31+
name = name.substring(10);
32+
}
2833
}
2934
String swt = "org.eclipse.swt.SWT";
3035
index = name.indexOf(swt);

0 commit comments

Comments
 (0)