@Test public void testGetDeclaredType() { assertThat(registry.getMessageType("number.I"), is(sameInstance(Imaginary.kDescriptor))); assertThat(registry.getEnumType("calculator.Operator"), is(sameInstance(Operator.kDescriptor))); try { registry.getDeclaredType("FakeNews"); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("Requesting global type name without program name: \"FakeNews\"")); } try { registry.getDeclaredType("real.fake.News"); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("Invalid identifier: \"real.fake.News\"")); } try { registry.getDeclaredType("fake.News"); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("No such program \"fake\" known for type \"News\"")); } try { registry.getDeclaredType("number.Fake"); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("No such type \"Fake\" in program \"number\"")); } try { registry.getDeclaredType("gurba.Imaginary"); fail("no exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("No such program \"gurba\" known for type \"Imaginary\"")); } try { registry.getDeclaredType("Imaginary", "gurba"); fail("no exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("No such program \"gurba\" known for type \"Imaginary\"")); } try { registry.getDeclaredType("number.Gurba"); fail("no exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("No such type \"Gurba\" in program \"number\"")); } try { registry.getDeclaredType("Gurba", "number"); fail("no exception"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("No such type \"Gurba\" in program \"number\"")); } }
@Nonnull @Override @SuppressWarnings("unchecked") public <T extends PDeclaredDescriptor<T>> T getDeclaredType(@Nonnull String typeName, @Nonnull String programContext) { String finalName = finalTypename(typeName, programContext); if (declaredTypes.containsKey(finalName)) { return (T) declaredTypes.get(finalName); } String program = finalName.replaceAll("\\..*", ""); String name = finalName.replaceAll(".*\\.", ""); if (knownPrograms.contains(program)) { throw new IllegalArgumentException( "No such type \"" + name + "\" in program \"" + program + "\""); } else { throw new IllegalArgumentException( "No such program \"" + program + "\" known for type \"" + typeName + "\""); } }
SimpleTypeRegistry extends BaseTypeRegistry { @Nonnull @Override @SuppressWarnings("unchecked") public <T extends PDeclaredDescriptor<T>> T getDeclaredType(@Nonnull String typeName, @Nonnull String programContext) { String finalName = finalTypename(typeName, programContext); if (declaredTypes.containsKey(finalName)) { return (T) declaredTypes.get(finalName); } String program = finalName.replaceAll("\\..*", ""); String name = finalName.replaceAll(".*\\.", ""); if (knownPrograms.contains(program)) { throw new IllegalArgumentException( "No such type \"" + name + "\" in program \"" + program + "\""); } else { throw new IllegalArgumentException( "No such program \"" + program + "\" known for type \"" + typeName + "\""); } } }
SimpleTypeRegistry extends BaseTypeRegistry { @Nonnull @Override @SuppressWarnings("unchecked") public <T extends PDeclaredDescriptor<T>> T getDeclaredType(@Nonnull String typeName, @Nonnull String programContext) { String finalName = finalTypename(typeName, programContext); if (declaredTypes.containsKey(finalName)) { return (T) declaredTypes.get(finalName); } String program = finalName.replaceAll("\\..*", ""); String name = finalName.replaceAll(".*\\.", ""); if (knownPrograms.contains(program)) { throw new IllegalArgumentException( "No such type \"" + name + "\" in program \"" + program + "\""); } else { throw new IllegalArgumentException( "No such program \"" + program + "\" known for type \"" + typeName + "\""); } } SimpleTypeRegistry(); }
SimpleTypeRegistry extends BaseTypeRegistry { @Nonnull @Override @SuppressWarnings("unchecked") public <T extends PDeclaredDescriptor<T>> T getDeclaredType(@Nonnull String typeName, @Nonnull String programContext) { String finalName = finalTypename(typeName, programContext); if (declaredTypes.containsKey(finalName)) { return (T) declaredTypes.get(finalName); } String program = finalName.replaceAll("\\..*", ""); String name = finalName.replaceAll(".*\\.", ""); if (knownPrograms.contains(program)) { throw new IllegalArgumentException( "No such type \"" + name + "\" in program \"" + program + "\""); } else { throw new IllegalArgumentException( "No such program \"" + program + "\" known for type \"" + typeName + "\""); } } SimpleTypeRegistry(); @Nonnull @Override @SuppressWarnings("unchecked") T getDeclaredType(@Nonnull String typeName,
                                                                @Nonnull String programContext); @Nullable @Override @SuppressWarnings("unchecked") T getConstantValue(@Nonnull String constReference, @Nonnull String programContext); @Nonnull @Override PService getService(String serviceName, String programContext); @Override void registerConstant(@Nonnull String identifier, @Nonnull String program, @Nonnull Object value); @Override @SuppressWarnings("unchecked") boolean register(@Nonnull PService service); @Override boolean register(PDeclaredDescriptor<T> declaredType); }
SimpleTypeRegistry extends BaseTypeRegistry { @Nonnull @Override @SuppressWarnings("unchecked") public <T extends PDeclaredDescriptor<T>> T getDeclaredType(@Nonnull String typeName, @Nonnull String programContext) { String finalName = finalTypename(typeName, programContext); if (declaredTypes.containsKey(finalName)) { return (T) declaredTypes.get(finalName); } String program = finalName.replaceAll("\\..*", ""); String name = finalName.replaceAll(".*\\.", ""); if (knownPrograms.contains(program)) { throw new IllegalArgumentException( "No such type \"" + name + "\" in program \"" + program + "\""); } else { throw new IllegalArgumentException( "No such program \"" + program + "\" known for type \"" + typeName + "\""); } } SimpleTypeRegistry(); @Nonnull @Override @SuppressWarnings("unchecked") T getDeclaredType(@Nonnull String typeName,
                                                                @Nonnull String programContext); @Nullable @Override @SuppressWarnings("unchecked") T getConstantValue(@Nonnull String constReference, @Nonnull String programContext); @Nonnull @Override PService getService(String serviceName, String programContext); @Override void registerConstant(@Nonnull String identifier, @Nonnull String program, @Nonnull Object value); @Override @SuppressWarnings("unchecked") boolean register(@Nonnull PService service); @Override boolean register(PDeclaredDescriptor<T> declaredType);  }