/** * Given a list of field names and a node referring to a type, finds each name in the list that * does not match a field within the type. */ public static List<Integer> createListOfNonExistentFields( List<String> list, JavacNode type, boolean excludeStandard, boolean excludeTransient) { boolean[] matched = new boolean[list.size()]; for (JavacNode child : type.down()) { if (list.isEmpty()) break; if (child.getKind() != Kind.FIELD) continue; JCVariableDecl field = (JCVariableDecl) child.get(); if (excludeStandard) { if ((field.mods.flags & Flags.STATIC) != 0) continue; if (field.name.toString().startsWith("$")) continue; } if (excludeTransient && (field.mods.flags & Flags.TRANSIENT) != 0) continue; int idx = list.indexOf(child.getName()); if (idx > -1) matched[idx] = true; } ListBuffer<Integer> problematic = ListBuffer.lb(); for (int i = 0; i < list.size(); i++) { if (!matched[i]) problematic.append(i); } return problematic.toList(); }
boolean isApplicable(TypeConfiguration that) { List<TypeKind> actuals = that.typeKindList; List<TypeKind> formals = parameterTypes.typeKindList; if ((actuals.size() - formals.size()) < -1) return false; // not enough args for (TypeKind actual : actuals) { if (!actual.isSubtypeOf(formals.head)) return false; // type mismatch formals = formals.tail.isEmpty() ? formals : formals.tail; } return true; }
boolean isMoreSpecificThan(VarargsMethod that) { List<TypeKind> actuals = parameterTypes.typeKindList; List<TypeKind> formals = that.parameterTypes.typeKindList; int checks = 0; int expectedCheck = Math.max(actuals.size(), formals.size()); while (checks < expectedCheck) { if (!actuals.head.isSubtypeOf(formals.head)) return false; // type mismatch formals = formals.tail.isEmpty() ? formals : formals.tail; actuals = actuals.tail.isEmpty() ? actuals : actuals.tail; checks++; } return true; }
private String asBytecodeString() { StringBuilder buf = new StringBuilder(); int count = 0; for (TypeKind arg : typeKindList) { if (count == (typeKindList.size() - 1)) { buf.append("["); } buf.append(arg.bytecodeString); count++; } return buf.toString(); }
private String asParameterList() { StringBuilder buf = new StringBuilder(); String sep = ""; int count = 0; for (TypeKind arg : typeKindList) { buf.append(sep); buf.append(arg.typeString); if (count == (typeKindList.size() - 1)) { buf.append("..."); } buf.append(" "); buf.append("arg" + count++); sep = ","; } return buf.toString(); }
/** * Build a list of multiline diagnostics containing detailed info about type-variables, captured * types, and intersection types * * @return where clause list */ protected List<JCDiagnostic> getWhereClauses() { List<JCDiagnostic> clauses = List.nil(); for (WhereClauseKind kind : WhereClauseKind.values()) { List<JCDiagnostic> lines = List.nil(); for (Map.Entry<Type, JCDiagnostic> entry : whereClauses.get(kind).entrySet()) { lines = lines.prepend(entry.getValue()); } if (!lines.isEmpty()) { String key = kind.key(); if (lines.size() > 1) key += ".1"; JCDiagnostic d = diags.fragment(key, whereClauses.get(kind).keySet()); d = new JCDiagnostic.MultilineDiagnostic(d, lines.reverse()); clauses = clauses.prepend(d); } } return clauses.reverse(); }
private void printLambda0(JCTree tree) { List<JCVariableDecl> params = readObject(tree, "params", List.<JCVariableDecl>nil()); boolean explicit = true; int paramLength = params.size(); try { explicit = readObject(tree, "paramKind", new Object()).toString().equals("EXPLICIT"); } catch (Exception e) { } boolean useParens = paramLength != 1 || explicit; if (useParens) print("("); if (explicit) { boolean first = true; for (JCVariableDecl vd : params) { if (!first) print(", "); first = false; printVarDefInline(vd); } } else { String sep = ""; for (JCVariableDecl param : params) { print(sep); print(param.name); sep = ", "; } } if (useParens) print(")"); print(" -> "); JCTree body = readObject(tree, "body", (JCTree) null); if (body instanceof JCBlock) { println("{"); indent++; print(((JCBlock) body).stats, ""); indent--; aPrint("}"); } else { print(body); } }
public String simplify(Symbol s) { String name = s.getQualifiedName().toString(); if (!s.type.isCompound()) { List<Symbol> conflicts = nameClashes.get(s.getSimpleName()); if (conflicts == null || (conflicts.size() == 1 && conflicts.contains(s))) { List<Name> l = List.nil(); Symbol s2 = s; while (s2.type.getEnclosingType().tag == CLASS && s2.owner.kind == Kinds.TYP) { l = l.prepend(s2.getSimpleName()); s2 = s2.owner; } l = l.prepend(s2.getSimpleName()); StringBuilder buf = new StringBuilder(); String sep = ""; for (Name n2 : l) { buf.append(sep); buf.append(n2); sep = "."; } name = buf.toString(); } } return name; }