@Test public void testCreateNotAnInterface() { PlaceHistoryGeneratorContext context = PlaceHistoryGeneratorContext.create( messager, compilationRule.getTypes(), compilationRule.getElements(), compilationRule .getElements() .getTypeElement(MyAbstractPlaceHistoryMapper.class.getCanonicalName())); assertThat(context).isNull(); }
static PlaceHistoryGeneratorContext create( Messager messager, Types types, Elements elements, Element element) { TypeElement stringType = requireType(elements, String.class); TypeElement placeTokenizerType = requireType(elements, PlaceTokenizer.class); TypeElement placeHistoryMapperType = requireType(elements, PlaceHistoryMapper.class); if (element.getKind() != ElementKind.INTERFACE) { messager.printMessage( Diagnostic.Kind.WARNING, String.format( "%s applied on a type that's not an interface; ignoring.", WithTokenizers.class.getCanonicalName())); return null; } if (!types.isSubtype(element.asType(), placeHistoryMapperType.asType())) { messager.printMessage( Diagnostic.Kind.WARNING, String.format( "%s applied on a type that doesn't implement %s; ignoring.", WithTokenizers.class.getCanonicalName(), PlaceHistoryMapper.class.getCanonicalName())); return null; } TypeElement interfaceType = (TypeElement) element; DeclaredType factoryType = findFactoryType(interfaceType); ClassName interfaceName = ClassName.get(interfaceType); String implName = ClassName.get(interfaceType).simpleNames().stream().collect(Collectors.joining("_")) + "Impl"; return new PlaceHistoryGeneratorContext( messager, types, elements, interfaceType, factoryType, stringType, placeTokenizerType, interfaceName.packageName(), implName); }
PlaceHistoryGeneratorContext { static PlaceHistoryGeneratorContext create( Messager messager, Types types, Elements elements, Element element) { TypeElement stringType = requireType(elements, String.class); TypeElement placeTokenizerType = requireType(elements, PlaceTokenizer.class); TypeElement placeHistoryMapperType = requireType(elements, PlaceHistoryMapper.class); if (element.getKind() != ElementKind.INTERFACE) { messager.printMessage( Diagnostic.Kind.WARNING, String.format( "%s applied on a type that's not an interface; ignoring.", WithTokenizers.class.getCanonicalName())); return null; } if (!types.isSubtype(element.asType(), placeHistoryMapperType.asType())) { messager.printMessage( Diagnostic.Kind.WARNING, String.format( "%s applied on a type that doesn't implement %s; ignoring.", WithTokenizers.class.getCanonicalName(), PlaceHistoryMapper.class.getCanonicalName())); return null; } TypeElement interfaceType = (TypeElement) element; DeclaredType factoryType = findFactoryType(interfaceType); ClassName interfaceName = ClassName.get(interfaceType); String implName = ClassName.get(interfaceType).simpleNames().stream().collect(Collectors.joining("_")) + "Impl"; return new PlaceHistoryGeneratorContext( messager, types, elements, interfaceType, factoryType, stringType, placeTokenizerType, interfaceName.packageName(), implName); } }
PlaceHistoryGeneratorContext { static PlaceHistoryGeneratorContext create( Messager messager, Types types, Elements elements, Element element) { TypeElement stringType = requireType(elements, String.class); TypeElement placeTokenizerType = requireType(elements, PlaceTokenizer.class); TypeElement placeHistoryMapperType = requireType(elements, PlaceHistoryMapper.class); if (element.getKind() != ElementKind.INTERFACE) { messager.printMessage( Diagnostic.Kind.WARNING, String.format( "%s applied on a type that's not an interface; ignoring.", WithTokenizers.class.getCanonicalName())); return null; } if (!types.isSubtype(element.asType(), placeHistoryMapperType.asType())) { messager.printMessage( Diagnostic.Kind.WARNING, String.format( "%s applied on a type that doesn't implement %s; ignoring.", WithTokenizers.class.getCanonicalName(), PlaceHistoryMapper.class.getCanonicalName())); return null; } TypeElement interfaceType = (TypeElement) element; DeclaredType factoryType = findFactoryType(interfaceType); ClassName interfaceName = ClassName.get(interfaceType); String implName = ClassName.get(interfaceType).simpleNames().stream().collect(Collectors.joining("_")) + "Impl"; return new PlaceHistoryGeneratorContext( messager, types, elements, interfaceType, factoryType, stringType, placeTokenizerType, interfaceName.packageName(), implName); } PlaceHistoryGeneratorContext(
      Messager messager,
      Types types,
      Elements elements,
      TypeElement interfaceType,
      DeclaredType factoryType,
      TypeElement stringType,
      TypeElement placeTokenizerType,
      String packageName,
      String implName); }
PlaceHistoryGeneratorContext { static PlaceHistoryGeneratorContext create( Messager messager, Types types, Elements elements, Element element) { TypeElement stringType = requireType(elements, String.class); TypeElement placeTokenizerType = requireType(elements, PlaceTokenizer.class); TypeElement placeHistoryMapperType = requireType(elements, PlaceHistoryMapper.class); if (element.getKind() != ElementKind.INTERFACE) { messager.printMessage( Diagnostic.Kind.WARNING, String.format( "%s applied on a type that's not an interface; ignoring.", WithTokenizers.class.getCanonicalName())); return null; } if (!types.isSubtype(element.asType(), placeHistoryMapperType.asType())) { messager.printMessage( Diagnostic.Kind.WARNING, String.format( "%s applied on a type that doesn't implement %s; ignoring.", WithTokenizers.class.getCanonicalName(), PlaceHistoryMapper.class.getCanonicalName())); return null; } TypeElement interfaceType = (TypeElement) element; DeclaredType factoryType = findFactoryType(interfaceType); ClassName interfaceName = ClassName.get(interfaceType); String implName = ClassName.get(interfaceType).simpleNames().stream().collect(Collectors.joining("_")) + "Impl"; return new PlaceHistoryGeneratorContext( messager, types, elements, interfaceType, factoryType, stringType, placeTokenizerType, interfaceName.packageName(), implName); } PlaceHistoryGeneratorContext(
      Messager messager,
      Types types,
      Elements elements,
      TypeElement interfaceType,
      DeclaredType factoryType,
      TypeElement stringType,
      TypeElement placeTokenizerType,
      String packageName,
      String implName); Set<TypeElement> getPlaceTypes(); String getPrefix(TypeElement placeType); Set<String> getPrefixes(); ExecutableElement getTokenizerGetter(String prefix); TypeElement getTokenizerType(String prefix); }
PlaceHistoryGeneratorContext { static PlaceHistoryGeneratorContext create( Messager messager, Types types, Elements elements, Element element) { TypeElement stringType = requireType(elements, String.class); TypeElement placeTokenizerType = requireType(elements, PlaceTokenizer.class); TypeElement placeHistoryMapperType = requireType(elements, PlaceHistoryMapper.class); if (element.getKind() != ElementKind.INTERFACE) { messager.printMessage( Diagnostic.Kind.WARNING, String.format( "%s applied on a type that's not an interface; ignoring.", WithTokenizers.class.getCanonicalName())); return null; } if (!types.isSubtype(element.asType(), placeHistoryMapperType.asType())) { messager.printMessage( Diagnostic.Kind.WARNING, String.format( "%s applied on a type that doesn't implement %s; ignoring.", WithTokenizers.class.getCanonicalName(), PlaceHistoryMapper.class.getCanonicalName())); return null; } TypeElement interfaceType = (TypeElement) element; DeclaredType factoryType = findFactoryType(interfaceType); ClassName interfaceName = ClassName.get(interfaceType); String implName = ClassName.get(interfaceType).simpleNames().stream().collect(Collectors.joining("_")) + "Impl"; return new PlaceHistoryGeneratorContext( messager, types, elements, interfaceType, factoryType, stringType, placeTokenizerType, interfaceName.packageName(), implName); } PlaceHistoryGeneratorContext(
      Messager messager,
      Types types,
      Elements elements,
      TypeElement interfaceType,
      DeclaredType factoryType,
      TypeElement stringType,
      TypeElement placeTokenizerType,
      String packageName,
      String implName); Set<TypeElement> getPlaceTypes(); String getPrefix(TypeElement placeType); Set<String> getPrefixes(); ExecutableElement getTokenizerGetter(String prefix); TypeElement getTokenizerType(String prefix);  }