package jetbrains.mps.ide.findusages.model.holders;

/*Generated by MPS */

import jetbrains.mps.annotations.GeneratedClass;
import org.jetbrains.mps.openapi.module.SModuleReference;
import org.jdom.Element;
import jetbrains.mps.project.Project;
import jetbrains.mps.ide.findusages.CantLoadSomethingException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.mps.openapi.persistence.PersistenceFacade;
import jetbrains.mps.ide.findusages.CantSaveSomethingException;

/**
 * Replacement for {@code jetbrains.mps.ide.findusages.model.holders.ModuleHolder} that doesn't force SModule resolution
 * @author Artem Tikhomirov
 */
@GeneratedClass(node = "r:6d26b589-14c5-496e-9d2b-5c71b3a15e5d(jetbrains.mps.ide.findusages.model.holders)/8568892084424438952", model = "r:6d26b589-14c5-496e-9d2b-5c71b3a15e5d(jetbrains.mps.ide.findusages.model.holders)")
public class ModuleRefHolder implements IHolder<SModuleReference> {
  private static final String UID = "moduleReference";
  private SModuleReference myReference;
  public ModuleRefHolder(Element element, Project project) throws CantLoadSomethingException {
    read(element, project);
  }
  public ModuleRefHolder(@NotNull SModuleReference moduleReference) {
    myReference = moduleReference;
  }
  @Override
  public SModuleReference getObject() {
    return myReference;
  }
  @NotNull
  @Override
  public String getCaption() {
    return myReference.getModuleName();
  }
  @Override
  public void read(Element element, Project project) throws CantLoadSomethingException {
    try {
      myReference = PersistenceFacade.getInstance().createModuleReference(element.getAttributeValue(UID));
    } catch (Exception ex) {
      throw new CantLoadSomethingException(ex);
    }
  }
  @Override
  public void write(Element element, Project project) throws CantSaveSomethingException {
    element.setAttribute(UID, PersistenceFacade.getInstance().asString(myReference));
  }
}
