All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.mmm.code.api.imports.CodeImports Maven / Gradle / Ivy

There is a newer version: 1.0.0-beta7
Show newest version
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0 */
package net.sf.mmm.code.api.imports;

import net.sf.mmm.code.api.CodeFile;
import net.sf.mmm.code.api.copy.CodeNodeItemCopyable;
import net.sf.mmm.code.api.node.CodeNodeItemContainerFlat;
import net.sf.mmm.code.api.type.CodeGenericType;
import net.sf.mmm.code.api.type.CodeType;

/**
 * {@link CodeNodeItemContainerFlat} containing the {@link CodeImport}s of a {@link CodeFile}.
 *
 * @see CodeFile#getImports()
 *
 * @author Joerg Hohwiller (hohwille at users.sourceforge.net)
 * @since 1.0.0
 */
public abstract interface CodeImports extends CodeNodeItemContainerFlat, CodeNodeItemCopyable {

  /**
   * @param type the {@link CodeType} to import.
   * @return the new {@link CodeImport} that has been added or {@code null} if no (additional) import is required.
   */
  CodeImport add(CodeType type);

  /**
   * @param type the {@link CodeGenericType} to import.
   * @return the new {@link CodeImport} that has been added or {@code null} if no (additional) import is required.
   */
  default CodeImport add(CodeGenericType type) {

    if (type.isQualified()) {
      return null;
    }
    return add(type.asType());
  }

  /**
   * Creates and adds {@link CodeImport import statements} automatically for all {@link CodeType types} required by the
   * {@link #getParent() owning} {@link CodeFile}.
   */
  default void addAutoGenerated() {

    CodeImportGeneratorVisitor.createImports(this);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy