KT-7704 Intention actions on visibility modifier for quick changing it

#KT-7704 Fixed
This commit is contained in:
Valentin Kipyatkov
2015-05-12 19:41:44 +03:00
parent ad91d2cd9e
commit 181af17315
67 changed files with 532 additions and 13 deletions
@@ -22,6 +22,7 @@ import com.intellij.navigation.ItemPresentationProviders;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.tree.TokenSet;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
@@ -255,4 +256,9 @@ public class JetClass extends JetTypeParameterListOwnerStub<KotlinClassStub> imp
JetClassBody body = getBody();
return body != null ? body.getSecondaryConstructors() : Collections.<JetSecondaryConstructor>emptyList();
}
@Nullable
public PsiElement getClassOrTraitKeyword() {
return findChildByType(TokenSet.create(JetTokens.CLASS_KEYWORD, JetTokens.TRAIT_KEYWORD));
}
}
@@ -79,7 +79,7 @@ public class JetNamedFunction extends JetTypeParameterListOwnerStub<KotlinFuncti
}
@NotNull
public PsiElement getFunToken() {
public PsiElement getFunKeyword() {
PsiElement element = findChildByType(JetTokens.FUN_KEYWORD);
assert element != null : "'fun' must be present: " + PsiUtilPackage.getElementTextWithContext(this);
return element;
@@ -52,9 +52,7 @@ internal fun addModifier(modifierList: JetModifierList, modifier: JetModifierKey
if (modifier == defaultVisibilityModifier) { // do not insert explicit 'internal' keyword (or 'public' for primary constructor)
//TODO: code style option
if (modifierToReplace != null) {
modifierToReplace.delete()
}
modifierToReplace?.delete()
return
}
@@ -72,8 +70,17 @@ internal fun addModifier(modifierList: JetModifierList, modifier: JetModifierKey
return newModifierOrder > order
}
val anchor = modifierList.getLastChild()?.siblings(forward = false)?.firstOrNull(::placeAfter)
val lastChild = modifierList.getLastChild()
val anchor = lastChild?.siblings(forward = false)?.firstOrNull(::placeAfter)
modifierList.addAfter(newModifier, anchor)
if (anchor == lastChild) { // add line break if needed, otherwise visibility keyword may appear on previous line
val whiteSpace = modifierList.getNextSibling() as? PsiWhiteSpace
if (whiteSpace != null && whiteSpace.getText().contains('\n')) {
modifierList.addAfter(whiteSpace, anchor)
whiteSpace.delete()
}
}
}
}