public String protoToString() { StringBuilder sb = new StringBuilder(); appendLine(sb, "syntax = \"%s\";", proto.getSyntax()); for (Import importValue : proto.getImports()) { appendLine(sb, "import \"%s\";", importValue.getValue()); } appendLine(sb, "package %s;\n", proto.getPackage().getValue()); for (Message message : proto.getMessages()) { messageToString(message, sb); } for (Enum enumValue : proto.getEnums()) { enumToString(enumValue, sb); } for (Service service : proto.getServices()) { serviceToString(service, sb); } return sb.toString(); }
private void resolveImports(ProtoContext context) { for (Import anImport : context.getProto().getImports()) { FileReader reader = context.getFileReader(); String file = anImport.getValue(); ProtoContext importedContext = importer.importFile(reader, file); if (anImport.isPublic()) { context.addPublicImport(importedContext); } else { context.addImport(importedContext); } anImport.setProto(importedContext.getProto()); } } }
@Override public void exitImportStatement(ProtoParser.ImportStatementContext ctx) { Proto proto = context.peek(Proto.class); String text = ctx.fileReference().getText(); String fileName = Util.removeFirstAndLastChar(text); Import anImport = new Import(proto, fileName, ctx.PUBLIC() != null); anImport.setSourceCodeLocation(getSourceCodeLocation(ctx)); proto.addImport(anImport); } }
@Override public Collection<Extension> getExtensions(String fullMessageName) { return extensionCache.computeIfAbsent(fullMessageName, name -> { Collection<Extension> result = new ArrayList<>(); result.addAll(localExtensionRegistry.getExtensions(name)); Deque<Import> queue = new ArrayDeque<>(); queue.addAll(context.getProto().getImports()); while (!queue.isEmpty()) { Import anImport = queue.poll(); Proto proto = anImport.getProto(); Collection<Extension> extensions = getExtensions(proto, name); result.addAll(extensions); queue.addAll(proto.getPublicImports()); } return result; }); }
private void resolveImports(ProtoContext context) { for (Import anImport : context.getProto().getImports()) { FileReader reader = context.getFileReader(); String file = anImport.getValue(); ProtoContext importedContext = importer.importFile(reader, file); if (anImport.isPublic()) { context.addPublicImport(importedContext); } else { context.addImport(importedContext); } anImport.setProto(importedContext.getProto()); } } }
@Override public void exitImportStatement(ProtoParser.ImportStatementContext ctx) { Proto proto = context.peek(Proto.class); String text = ctx.fileReference().getText(); String fileName = Util.removeFirstAndLastChar(text); Import anImport = new Import(proto, fileName, ctx.PUBLIC() != null); anImport.setSourceCodeLocation(getSourceCodeLocation(ctx)); proto.addImport(anImport); } }
@Override public Collection<Extension> getExtensions(String fullMessageName) { return extensionCache.computeIfAbsent(fullMessageName, name -> { Collection<Extension> result = new ArrayList<>(); result.addAll(localExtensionRegistry.getExtensions(name)); Deque<Import> queue = new ArrayDeque<>(); queue.addAll(context.getProto().getImports()); while (!queue.isEmpty()) { Import anImport = queue.poll(); Proto proto = anImport.getProto(); Collection<Extension> extensions = getExtensions(proto, name); result.addAll(extensions); queue.addAll(proto.getPublicImports()); } return result; }); }
public String protoToString() { StringBuilder sb = new StringBuilder(); appendLine(sb, "syntax = \"%s\";", proto.getSyntax()); for (Import importValue : proto.getImports()) { appendLine(sb, "import \"%s\";", importValue.getValue()); } appendLine(sb, "package %s;\n", proto.getPackage().getValue()); for (Message message : proto.getMessages()) { messageToString(message, sb); } for (Enum enumValue : proto.getEnums()) { enumToString(enumValue, sb); } for (Service service : proto.getServices()) { serviceToString(service, sb); } return sb.toString(); }