Search in sources :

Example 1 with GeneratedResult

use of com.google.api.codegen.GeneratedResult in project toolkit by googleapis.

the class CommonGapicProvider method generateSnip.

@Nullable
private List<GeneratedResult> generateSnip(String snippetFileName) {
    // Establish required stage for generation.
    model.establishStage(Merged.KEY);
    if (model.getDiagCollector().getErrorCount() > 0) {
        return null;
    }
    // Run the generator for each service.
    List<GeneratedResult> generated = new ArrayList<>();
    for (ElementT element : view.getElementIterable(model)) {
        GeneratedResult result = generator.generate(element, snippetFileName, context);
        String subPath;
        // where the element is an Iterable<> instead of a ProtoElement.
        if (element instanceof ProtoElement) {
            subPath = pathMapper.getOutputPath(((ProtoElement) element).getFullName(), context.getApiConfig());
        } else {
            subPath = pathMapper.getOutputPath(null, context.getApiConfig());
        }
        if (!Strings.isNullOrEmpty(subPath)) {
            subPath = subPath + "/" + result.getFilename();
        } else {
            subPath = result.getFilename();
        }
        GeneratedResult outputResult = GeneratedResult.create(result.getDoc(), subPath);
        generated.add(outputResult);
    }
    // Return result.
    if (model.getDiagCollector().getErrorCount() > 0) {
        return null;
    }
    return generated;
}
Also used : ProtoElement(com.google.api.tools.framework.model.ProtoElement) GeneratedResult(com.google.api.codegen.GeneratedResult) ArrayList(java.util.ArrayList) Nullable(javax.annotation.Nullable)

Example 2 with GeneratedResult

use of com.google.api.codegen.GeneratedResult in project toolkit by googleapis.

the class CommonGapicProvider method generate.

@Nullable
@Override
public Map<String, Doc> generate(String snippetFileName) {
    Map<String, Doc> docs = new TreeMap<>();
    List<GeneratedResult> generatedOutput = generateSnip(snippetFileName);
    if (generatedOutput == null) {
        return docs;
    }
    for (GeneratedResult result : generatedOutput) {
        if (!result.getDoc().isWhitespace()) {
            docs.put(result.getFilename(), result.getDoc());
        }
    }
    return docs;
}
Also used : GeneratedResult(com.google.api.codegen.GeneratedResult) Doc(com.google.api.tools.framework.snippet.Doc) TreeMap(java.util.TreeMap) Nullable(javax.annotation.Nullable)

Aggregations

GeneratedResult (com.google.api.codegen.GeneratedResult)2 Nullable (javax.annotation.Nullable)2 ProtoElement (com.google.api.tools.framework.model.ProtoElement)1 Doc (com.google.api.tools.framework.snippet.Doc)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1