1 回答

TA貢獻1784條經驗 獲得超9個贊
你可以看看 org.netbeans.modules.java.hints.jdk.mapreduce.PreconditionsChecker
private boolean isIterbale(ExpressionTree expression) {
? ? TypeMirror tm = workingCopy.getTrees().getTypeMirror(TreePath.getPath(workingCopy.getCompilationUnit(), expression));
? ? if (!Utilities.isValidType(tm)) {
? ? ? ? return false;
? ? }
? ? if (tm.getKind() == TypeKind.ARRAY) {
? ? ? ? return false;
? ? } else {
? ? ? ? tm = workingCopy.getTypes().erasure(tm);
? ? ? ? TypeElement typeEl = workingCopy.getElements().getTypeElement("java.util.Collection");
? ? ? ? if (typeEl != null) {
? ? ? ? ? ? TypeMirror collection = typeEl.asType();
? ? ? ? ? ? collection = workingCopy.getTypes().erasure(collection);
? ? ? ? ? ? if (this.workingCopy.getTypes().isSubtype(tm, collection)) {
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? return false;
}
先決條件檢查器
添加回答
舉報