package jetbrains.mps.debugger.java.api.state.watchables;

/*Generated by MPS */

import jetbrains.mps.annotations.GeneratedClass;
import jetbrains.mps.debug.api.programState.IWatchable;
import com.sun.jdi.ReferenceType;
import com.sun.jdi.ThreadReference;
import jetbrains.mps.debug.api.programState.WatchablesCategory;
import jetbrains.mps.debug.api.programState.IValue;
import javax.swing.Icon;
import jetbrains.mps.debugger.java.api.ui.Icons;
import java.util.List;
import java.util.ArrayList;
import com.sun.jdi.Field;

@GeneratedClass(node = "r:6ed9d174-6cbf-4569-b2b8-259c43efcbd9(jetbrains.mps.debugger.java.api.state.watchables)/3432969378036015904", model = "r:6ed9d174-6cbf-4569-b2b8-259c43efcbd9(jetbrains.mps.debugger.java.api.state.watchables)")
public class JavaStaticContext extends JavaWatchable implements IWatchable {
  private final ReferenceType myStaticType;
  private final StaticContextValue myValue;
  public JavaStaticContext(ReferenceType staticType, ThreadReference threadReference) {
    super(threadReference);
    myStaticType = staticType;
    myValue = new StaticContextValue();
  }
  @Override
  public String getName() {
    return "static";
  }
  @Override
  public WatchablesCategory getCategory() {
    return JavaWatchablesCategory.STATIC_CONTEXT;
  }
  @Override
  public IValue getValue() {
    assert myValue != null;
    return myValue;
  }
  @Override
  public Icon getPresentationIcon() {
    return Icons.WATCHABLE_STATIC;
  }

  private class StaticContextValue implements IValue {
    private final String myName;
    private volatile List<IWatchable> mySubvalues;
    private StaticContextValue() {
      myName = myStaticType.name();
    }
    @Override
    public String getValuePresentation() {
      return myName;
    }
    @Override
    public Icon getPresentationIcon() {
      return Icons.VALUE_OBJECT;
    }
    @Override
    public boolean isStructure() {
      return true;
    }
    public List<IWatchable> calculateSubvalues() {
      List<IWatchable> result = new ArrayList<IWatchable>();
      for (Field field : myStaticType.fields()) {
        if (!(field.isStatic())) {
          continue;
        }
        result.add(new JavaStaticField(field, myThreadReference));
      }
      return result;
    }
    @Override
    public List<IWatchable> getSubvalues() {
      return mySubvalues;
    }
    @Override
    public void initSubvalues() {
      mySubvalues = calculateSubvalues();
    }
  }
}
