Search in sources :

Example 26 with ConfigNode

use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.

the class MissingFieldTransformer method generate.

public FieldConfigNode generate() {
    ConfigNode node = NodeFinder.findByValue(parent, name);
    if (node instanceof FieldConfigNode) {
        return (FieldConfigNode) node;
    }
    if (prev == null) {
        ConfigNode next = parent.getChild();
        int startLine = next.isPresent() ? next.getStartLine() : parent.getStartLine() + 1;
        node = new FieldConfigNode(startLine, name);
        parent.setChild(node.insertNext(next));
    } else {
        ConfigNode next = node.getNext();
        node = new FieldConfigNode(NodeFinder.getNextLine(prev), name);
        prev.insertNext(node.insertNext(next));
    }
    return ((FieldConfigNode) node);
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode)

Example 27 with ConfigNode

use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.

the class CollectionMerger method generateCollectionNode.

private ConfigNode generateCollectionNode(int startLine, String namePattern, String entityName) {
    ConfigNode collectionNode = new ListItemConfigNode(startLine);
    ConfigNode namePatternNode = FieldConfigNode.createStringPair(collectionNode.getStartLine(), "name_pattern", namePattern);
    collectionNode.setChild(namePatternNode);
    ConfigNode entityNameNode = FieldConfigNode.createStringPair(NodeFinder.getNextLine(namePatternNode), "entity_name", entityName);
    namePatternNode.insertNext(entityNameNode);
    return collectionNode;
}
Also used : ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode)

Example 28 with ConfigNode

use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.

the class ConfigMerger method mergeConfig.

private FieldConfigNode mergeConfig(ApiModel model, FieldConfigNode configNode) {
    ConfigNode typeNode = mergeType(configNode);
    if (typeNode == null) {
        return null;
    }
    ConfigNode versionNode = mergeVersion(configNode, typeNode);
    if (versionNode == null) {
        return null;
    }
    ConfigNode languageSettingsNode = languageSettingsMerger.mergeLanguageSettings(packageName, configNode, versionNode);
    mergeLicenseHeader(configNode, languageSettingsNode);
    interfaceMerger.mergeInterfaces(model, configNode);
    return configNode;
}
Also used : ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode)

Example 29 with ConfigNode

use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.

the class InterfaceMerger method mergeInterfaces.

public void mergeInterfaces(ApiModel model, ConfigNode configNode) {
    FieldConfigNode interfacesNode = MissingFieldTransformer.append("interfaces", configNode).generate();
    if (NodeFinder.hasContent(interfacesNode.getChild())) {
        return;
    }
    ConfigNode interfacesValueNode = ListTransformer.generateList(model.getInterfaces(), interfacesNode, this::generateInterfaceNode);
    interfacesNode.setChild(interfacesValueNode).setComment(new DefaultComment("A list of API interface configurations."));
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) DefaultComment(com.google.api.codegen.configgen.nodes.metadata.DefaultComment)

Example 30 with ConfigNode

use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.

the class LanguageSettingsMerger method mergePackageNameValue.

private ConfigNode mergePackageNameValue(ConfigNode packageNameNode, LanguageFormatter languageFormatter, String packageName) {
    ConfigNode packageNameValueNode = new ScalarConfigNode(packageNameNode.getStartLine(), languageFormatter.getFormattedPackageName(packageName));
    packageNameNode.setChild(packageNameValueNode);
    return packageNameValueNode;
}
Also used : ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode)

Aggregations

ConfigNode (com.google.api.codegen.configgen.nodes.ConfigNode)39 FieldConfigNode (com.google.api.codegen.configgen.nodes.FieldConfigNode)35 ListItemConfigNode (com.google.api.codegen.configgen.nodes.ListItemConfigNode)22 ScalarConfigNode (com.google.api.codegen.configgen.nodes.ScalarConfigNode)12 NullConfigNode (com.google.api.codegen.configgen.nodes.NullConfigNode)11 Test (org.junit.Test)5 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)5 DefaultComment (com.google.api.codegen.configgen.nodes.metadata.DefaultComment)4 FixmeComment (com.google.api.codegen.configgen.nodes.metadata.FixmeComment)4 Node (org.yaml.snakeyaml.nodes.Node)4 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)3 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)3 SequenceNode (org.yaml.snakeyaml.nodes.SequenceNode)3 ConfigHelper (com.google.api.codegen.configgen.ConfigHelper)2 ConfigYamlReader (com.google.api.codegen.configgen.ConfigYamlReader)2 MessageGenerator (com.google.api.codegen.configgen.MessageGenerator)2 File (java.io.File)2 NodeTuple (org.yaml.snakeyaml.nodes.NodeTuple)2 FieldModel (com.google.api.codegen.config.FieldModel)1 ProtoConfigMerger (com.google.api.codegen.configgen.mergers.ProtoConfigMerger)1