/** * Produces a subset of this symbol table that has the symbols with resource type / name defined * in {@code filter}. In other words, a symbol {@code s} will exist in the result if and only * if {@code s} exists in {@code this} and there is a symbol {@code s1} in {@code table} * such that {@code s.resourceType == s1.resourceType && s.name == s1.name}. * * @param table the filter table * @return the filter result; this table will have the same name and package as this one */ @NonNull public SymbolTable filter(@NonNull SymbolTable table) { SymbolTable.Builder stb = builder(); stb.tableName(tableName); stb.tablePackage(tablePackage); for (Map.Entry<String, Symbol> e : symbols.entrySet()) { if (table.symbols.containsKey(e.getKey())) { stb.symbols.put(e.getKey(), e.getValue()); } } return stb.build(); }
SymbolTable.Builder table = SymbolTable.builder();
mainRTxt.isFile()? SymbolIo.read(mainRTxt) : SymbolTable.builder().build(); mainSymbols = mainSymbols.rename(mainPackageName, mainSymbols.getTableName()); rFile.exists()? SymbolIo.read(rFile) : SymbolTable.builder().build(); depSymbols = depSymbols.rename(depPackageName, depSymbols.getTableName()); depSymbolTables.add(depSymbols);
/** * Builds a new symbol table that has the same symbols as this one, but was renamed with * the given package and table name. * * @param tablePackage the table package * @param tableName the table name * @return the new renamed symbol table */ @NonNull public SymbolTable rename(@NonNull String tablePackage, @NonNull String tableName) { return builder() .tablePackage(tablePackage) .tableName(tableName) .addAll(allSymbols()) .build(); }
/** * Merges a list of tables into a single table. The merge is order-sensitive: when multiple * symbols with the same class / name exist in multiple tables, the first one will be used. * * @param tables the tables to merge * @return the table with the result of the merge; this table will have the package / name of * the first table in {@code tables}, or the default one if there are no tables in * {@code tables} */ @NonNull public static SymbolTable merge(@NonNull List<SymbolTable> tables) { SymbolTable.Builder builder = SymbolTable.builder(); boolean first = true; for (SymbolTable t : tables) { if (first) { builder.tablePackage(t.getTablePackage()); builder.tableName(t.getTableName()); first = false; } for (Symbol s : t.allSymbols()) { if (!builder.contains(s)) { builder.add(s); } } } return builder.build(); }