/** * Writes a symbol table to a symbol file. * * @param table the table * @param file the file where the table should be written * @throws UncheckedIOException I/O error */ public static void write(@NonNull SymbolTable table, @NonNull File file) { List<String> lines = new ArrayList<>(); for (Symbol s : table.allSymbols()) { lines.add( s.getJavaType() + " " + s.getResourceType() + " " + s.getName() + " " + s.getValue()); } try ( FileOutputStream fos = new FileOutputStream(file); PrintWriter pw = new PrintWriter(fos)) { lines.forEach(pw::println); } catch (IOException e) { throw new UncheckedIOException(e); } }
table.allSymbols().forEach(s -> resourceTypes.add(s.getResourceType())); table.allSymbols().forEach(sym -> { if (sym.getResourceType().equals(rt)) { syms.add(sym);
/** * 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(); }