@Test public void testResolveType() { Assert.assertSame(TypeRef.of(Type.TYPE_INT32), table.resolveType("a.b", "int32")); Assert.assertSame(m1, table.resolveType("a.b", "m")); Assert.assertSame(m2, table.resolveType("a.b", "m.m")); Assert.assertSame(m2, table.resolveType("a.b.m", "m")); Assert.assertSame(m1, table.resolveType("a.b.m", ".a.b.m")); Assert.assertSame(m3, table.resolveType("a.b.a", "a.m")); // Note: different from resolveType() }
@Test public void testResolveType2() { Mockito.when(message1.getFullName()).thenReturn(m1Name); Mockito.when(message2.getFullName()).thenReturn(m2Name); Mockito.when(message3.getFullName()).thenReturn(m3Name); Mockito.when(message4.getFullName()).thenReturn(m4Name); Assert.assertSame(TypeRef.of(Type.TYPE_INT32), table.resolveType("a.b", "int32")); Assert.assertSame(m1, table.resolveType2("a.b", "m")); Assert.assertSame(m2, table.resolveType2("a.b", "m.m")); Assert.assertSame(m2, table.resolveType2("a.b.m", "m")); Assert.assertSame(m1, table.resolveType2("a.b.m", ".a.b.m")); Assert.assertSame(m4, table.resolveType2("a.b.a", "a.n")); Assert.assertNull(table.resolveType2("a.b.a", "a.m")); // Note: different from resolveType() } }
firstComponent = name.substring(0, name.indexOf(".")); } else { return resolveType(inPackage, name);
firstComponent = name.substring(0, name.indexOf(".")); } else { return resolveType(inPackage, name);
/** * Resolves a type based on the given partial name. This does not assume that the name, as * obtained from the descriptor, is in absolute form. */ private TypeRef resolveType(Location location, FieldDescriptorProto.Type kind, String name) { TypeRef type; switch (kind) { case TYPE_MESSAGE: case TYPE_ENUM: case TYPE_GROUP: type = symbolTable.resolveType(namespaces.peek(), name); break; default: type = TypeRef.of(kind); } if (type == null) { model.getDiagReporter().report(Diag.error(location, "Unresolved type '%s'", name)); } return type; } }
/** * Resolves a type based on the given partial name. This does not assume that the name, as * obtained from the descriptor, is in absolute form. */ private TypeRef resolveType(Location location, FieldDescriptorProto.Type kind, String name) { TypeRef type; switch (kind) { case TYPE_MESSAGE: case TYPE_ENUM: case TYPE_GROUP: type = symbolTable.resolveType(namespaces.peek(), name); break; default: type = TypeRef.of(kind); } if (type == null) { model.getDiagReporter().report(Diag.error(location, "Unresolved type '%s'", name)); } return type; } }