Exemplo n.º 1
0
  @Nullable
  public static JetClassOrObject getOutermostClassOrObject(
      @NotNull JetClassOrObject classOrObject) {
    JetClassOrObject current = classOrObject;
    while (true) {
      PsiElement parent = current.getParent();
      assert classOrObject.getParent() != null : "Class with no parent: " + classOrObject.getText();

      if (parent instanceof PsiFile) {
        return current;
      }
      if (parent instanceof JetClassObject) {
        // current class IS the class object declaration
        parent = parent.getParent();
        assert parent instanceof JetClassBody
            : "Parent of class object is not a class body: " + parent;
      }
      if (!(parent instanceof JetClassBody)) {
        // It is a local class, no legitimate outer
        return current;
      }

      current = (JetClassOrObject) parent.getParent();
    }
  }
Exemplo n.º 2
0
 public static void deleteClass(@NotNull JetClassOrObject clazz) {
   CheckUtil.checkWritable(clazz);
   JetFile file = (JetFile) clazz.getContainingFile();
   List<JetDeclaration> declarations = file.getDeclarations();
   if (declarations.size() == 1) {
     file.delete();
   } else {
     PsiElement parent = clazz.getParent();
     CodeEditUtil.removeChild(parent.getNode(), clazz.getNode());
   }
 }