Search in sources :

Example 1 with PhpTypeTable

use of com.google.api.codegen.util.php.PhpTypeTable in project toolkit by googleapis.

the class PhpGapicSurfaceTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        ModelTypeTable modelTypeTable = new ModelTypeTable(new PhpTypeTable(productConfig.getPackageName()), new PhpModelTypeNameConverter(productConfig.getPackageName()));
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, modelTypeTable, new PhpSurfaceNamer(productConfig.getPackageName()), new PhpFeatureConfig());
        surfaceDocs.addAll(transform(context));
    }
    return surfaceDocs;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ArrayList(java.util.ArrayList) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) PhpTypeTable(com.google.api.codegen.util.php.PhpTypeTable)

Example 2 with PhpTypeTable

use of com.google.api.codegen.util.php.PhpTypeTable in project toolkit by googleapis.

the class PhpModelTypeNameConverterTest method testNestedMessageFullName.

@Test
public void testNestedMessageFullName() {
    String packageName = "Google\\Example\\Library\\V1";
    TypeRef type = ModelTypeNameConverterTestUtil.getTestType(tempDir, "SomeMessage2", "SomeMessage3");
    PhpModelTypeNameConverter converter = new PhpModelTypeNameConverter(packageName);
    PhpTypeTable typeTable = new PhpTypeTable(packageName);
    TypeName typeName = converter.getTypeName(type);
    assertThat(typeName.getFullName()).isEqualTo("\\Google\\Example\\Library\\V1\\SomeMessage2\\SomeMessage3");
    typeTable.getAndSaveNicknameFor(typeName);
    assertThat(typeTable.getImports()).containsKey("\\Google\\Example\\Library\\V1\\SomeMessage2\\SomeMessage3");
}
Also used : TypeName(com.google.api.codegen.util.TypeName) TypeRef(com.google.api.tools.framework.model.TypeRef) PhpTypeTable(com.google.api.codegen.util.php.PhpTypeTable) Test(org.junit.Test)

Example 3 with PhpTypeTable

use of com.google.api.codegen.util.php.PhpTypeTable in project toolkit by googleapis.

the class PhpModelTypeNameConverterTest method testGetEnumValue.

@Test
public void testGetEnumValue() {
    String packageName = "Google\\Example\\Library\\V1";
    TypeRef type = ModelTypeNameConverterTestUtil.getTestEnumType(tempDir);
    EnumValue value = type.getEnumType().getValues().get(0);
    PhpModelTypeNameConverter converter = new PhpModelTypeNameConverter(packageName);
    PhpTypeTable typeTable = new PhpTypeTable(packageName);
    assertThat(converter.getEnumValue(type, value).getValueAndSaveTypeNicknameIn(typeTable)).isEqualTo("Rating::GOOD");
    assertThat(typeTable.getImports()).containsKey("\\Google\\Example\\Library\\V1\\Book\\Rating");
}
Also used : TypeRef(com.google.api.tools.framework.model.TypeRef) EnumValue(com.google.api.tools.framework.model.EnumValue) PhpTypeTable(com.google.api.codegen.util.php.PhpTypeTable) Test(org.junit.Test)

Example 4 with PhpTypeTable

use of com.google.api.codegen.util.php.PhpTypeTable in project toolkit by googleapis.

the class PhpGapicSurfaceTransformer method transform.

@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        ModelTypeTable modelTypeTable = new ModelTypeTable(new PhpTypeTable(productConfig.getPackageName()), new PhpModelTypeNameConverter(productConfig.getPackageName()));
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, modelTypeTable, new PhpSurfaceNamer(productConfig.getPackageName()), new PhpFeatureConfig(productConfig));
        surfaceDocs.addAll(transform(context));
    }
    return surfaceDocs;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ArrayList(java.util.ArrayList) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) PhpTypeTable(com.google.api.codegen.util.php.PhpTypeTable)

Example 5 with PhpTypeTable

use of com.google.api.codegen.util.php.PhpTypeTable in project toolkit by googleapis.

the class PhpGapicSurfaceTestTransformer method createContext.

private GapicInterfaceContext createContext(InterfaceModel apiInterface, GapicProductConfig productConfig, PhpSurfaceNamer.TestKind testKind) {
    PhpSurfaceNamer surfacePackageNamer = new PhpSurfaceNamer(productConfig.getPackageName());
    String testPackageName = surfacePackageNamer.getTestPackageName(testKind);
    ModelTypeTable typeTable = new ModelTypeTable(new PhpTypeTable(testPackageName), new PhpModelTypeNameConverter(testPackageName));
    return GapicInterfaceContext.create(apiInterface, productConfig, typeTable, surfacePackageNamer, new PhpFeatureConfig(productConfig));
}
Also used : ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) PhpTypeTable(com.google.api.codegen.util.php.PhpTypeTable)

Aggregations

PhpTypeTable (com.google.api.codegen.util.php.PhpTypeTable)6 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)3 TypeRef (com.google.api.tools.framework.model.TypeRef)3 Test (org.junit.Test)3 InterfaceModel (com.google.api.codegen.config.InterfaceModel)2 TypeName (com.google.api.codegen.util.TypeName)2 ViewModel (com.google.api.codegen.viewmodel.ViewModel)2 ArrayList (java.util.ArrayList)2 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)1 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)1 EnumValue (com.google.api.tools.framework.model.EnumValue)1