public void writeImports()

in maven-faces-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/faces/generator/component/AbstractComponentGenerator.java [264:367]


  public void writeImports(
      PrettyWriter out,
      SourceTemplate template,
      String packageName,
      String fullSuperclassName,
      String superclassName,
      ComponentBean component)
  {
    Set<String> imports = new TreeSet<String>();

    // Use the template imports
    if (template != null)
      imports.addAll(template.getImports());

    // Detect NamingContainer
    if (component.isNamingContainer())
      imports.add("javax.faces.component.NamingContainer");

    // Detect ClientBehaviorHolder
    if (component.isClientBehaviorHolder())
    {
      imports.add("java.util.Arrays");
      imports.add("java.util.Collection");
      imports.add("java.util.Collections");
      imports.add("java.util.List");
      imports.add("java.util.Map");
      imports.add("javax.faces.component.behavior.ClientBehavior");
      imports.add("javax.faces.component.behavior.ClientBehaviorHolder");
    }

    Iterator<PropertyBean> properties = component.properties();
    properties = new FilteredIterator<PropertyBean>(properties, new NonVirtualFilter());
    // PropertyKey only needed if there are properties
    if (properties.hasNext())
    {
      while (properties.hasNext())
      {
        PropertyBean property = properties.next();
        String propertyClass = property.getPropertyClass();
        if (propertyClass != null)
        {
          imports.add(propertyClass);
          // Check for generics
          String[] types = property.getAttributeClassParameters();
          if (types != null)
          {
            for (int i = types.length - 1; i >= 0; i--)
            {
              addGenericImports(imports, types[i]);
            }
          }
        }
      }
    }

    Iterator facets = component.facets();
    // UIComponent needed if there are facets
    if (facets.hasNext())
      imports.add("javax.faces.component.UIComponent");

    Iterator<EventRefBean> events = component.events();
    while (events.hasNext())
    {
      EventRefBean eventRef = events.next();
      EventBean event = eventRef.resolveEventType();

      if (event == null)
      {
        getLog().warn("Unknown event type \"" + eventRef.getEventType() + "\"" +
            " in component:" + component.getComponentType());
      }
      else
      {
        String listenerClass = event.getEventListenerClass();
        if (listenerClass != null)
          imports.add(listenerClass);

        if (!eventRef.isIgnoreSourceInterface())
        {
          String sourceInterface = event.getEventSourceInterface();
          if (sourceInterface != null)
            imports.add(sourceInterface);
        }
      }
    }

    // Import causes a collision if className and superclassName are equal
    if (!superclassName.equals(fullSuperclassName))
    {
      String superPackageName = Util.getPackageFromFullClass(fullSuperclassName);
      // component superclass only needed if not in
      // same package as component class
      if (superPackageName != packageName)
        imports.add(fullSuperclassName);
    }

    // add other imports (generator specific)
    addSpecificImports(imports, component);

    // do not import implicit types!
    imports.removeAll(Util.PRIMITIVE_TYPES);

    GeneratorHelper.writeImports(out, packageName, imports);
  }