KT-1328 removing single class from file, should remove file too. Also changed file icon to one of containing classes icon.
This commit is contained in:
@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.psi;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.StubBasedPsiElement;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
@@ -153,4 +154,9 @@ public class JetClass extends JetTypeParameterListOwner
|
||||
// TODO (stubs)
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() throws IncorrectOperationException {
|
||||
JetPsiUtil.deleteClass(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,5 +117,10 @@ public class JetObjectDeclaration extends JetNamedDeclaration implements JetClas
|
||||
@NotNull
|
||||
public PsiElement getObjectKeyword() {
|
||||
return findChildByType(JetTokens.OBJECT_KEYWORD);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() throws IncorrectOperationException {
|
||||
JetPsiUtil.deleteClass(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.CheckUtil;
|
||||
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -234,4 +237,16 @@ public class JetPsiUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.plugin;
|
||||
import com.intellij.ide.IconProvider;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
@@ -27,6 +28,7 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -38,6 +40,23 @@ public class JetIconProvider extends IconProvider {
|
||||
@Override
|
||||
public Icon getIcon(@NotNull PsiElement psiElement, int flags) {
|
||||
if (psiElement instanceof JetFile) {
|
||||
JetFile file = (JetFile) psiElement;
|
||||
List<JetDeclaration> declarations = file.getDeclarations();
|
||||
JetClassOrObject mostImportantClass = null;
|
||||
String nameWithoutExtension = StringUtil.getPackageName(file.getName());
|
||||
for (JetDeclaration declaration : declarations) {
|
||||
if (mostImportantClass == null && declaration instanceof JetClassOrObject) {
|
||||
mostImportantClass = (JetClassOrObject) declaration;
|
||||
} else if (declaration instanceof JetClassOrObject) {
|
||||
JetClassOrObject object = (JetClassOrObject) declaration;
|
||||
if (nameWithoutExtension.equals(object.getName())) {
|
||||
mostImportantClass = object;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mostImportantClass != null) {
|
||||
return getIcon(mostImportantClass, flags);
|
||||
}
|
||||
return KOTLIN_ICON;
|
||||
}
|
||||
if (psiElement instanceof JetNamespaceHeader) {
|
||||
|
||||
Reference in New Issue
Block a user