private void checkRefs(MethodDeclaration meth, ClassScope scope) {
Map<String, Set<String>> errors = new LinkedHashMap<String, Set<String>>();
// first do a sloppy parse, for speed
FindJsniRefVisitor sloppyRefsVisitor = new FindJsniRefVisitor();
sloppyRefsVisitor.beSloppy();
meth.traverse(sloppyRefsVisitor, scope);
for (String jsniRefString : sloppyRefsVisitor.getJsniRefs()) {
JsniRef jsniRef = JsniRef.parse(jsniRefString);
Map<String, Set<String>> warnings = new LinkedHashMap<String, Set<String>>();
if (jsniRef != null) {
ReferenceBinding clazz = findClass(jsniRef);
if (looksLikeAnonymousClass(jsniRef)
|| (clazz != null && clazz.isAnonymousType())) {
add(warnings, "deprecation", "Referencing class '"
+ jsniRef.className()
+ ": JSNI references to anonymous classes are deprecated");
} else if (clazz != null) {
if (clazz.isDeprecated()) {
add(warnings, "deprecation", "Referencing deprecated class '"
+ jsniRef.className() + "'");
}
Set<String> refErrors = new LinkedHashSet<String>();
if (jsniRef.isMethod()) {
checkMethodRef(clazz, jsniRef, refErrors, warnings);
} else {
checkFieldRef(clazz, jsniRef, refErrors, warnings);
}
if (!refErrors.isEmpty()) {
errors.put(jsniRefString, refErrors);
}
} else if (!jsniRef.className().equals("null")) {
/*
* TODO(scottb): re-enable this when we no longer get a bunch of
* false failures. Currently we can't resolve top level types (like
* boolean_Array_Rank_1_FieldSerializer), and we also don't resolve
* array and primitive refs, like @Z[]::class.
*/
// GWTProblem.recordInCud(ProblemSeverities.Warning, meth, cud,
// "Referencing class '" + jsniRef.className()
// + ": unable to resolve class, expect subsequent failures",
// null);
}
}
filterWarnings(meth, warnings);
for (Set<String> set : warnings.values()) {
for (String warning : set) {
GWTProblem.recordInCud(ProblemSeverities.Warning, meth, cud,
warning, null);
}
}
}
if (!errors.isEmpty()) {
// do a strict parse to find out which JSNI refs are real
FindJsniRefVisitor jsniRefsVisitor = new FindJsniRefVisitor();
meth.traverse(jsniRefsVisitor, scope);
for (String jsniRefString : jsniRefsVisitor.getJsniRefs()) {
if (errors.containsKey(jsniRefString)) {
for (String err : errors.get(jsniRefString)) {
longAccessError(meth, err);
}
}