Implement quckfix adding explicit upper bounds for generic when needed

This commit is contained in:
Denis Zharkov
2015-08-31 17:42:56 +03:00
parent c17451cf5c
commit c59b118b09
15 changed files with 236 additions and 0 deletions
@@ -17,6 +17,8 @@
package org.jetbrains.kotlin.psi;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.psi.stubs.KotlinTypeParameterStub;
@@ -56,6 +58,27 @@ public class JetTypeParameter extends JetNamedDeclarationStub<KotlinTypeParamete
return Variance.INVARIANT;
}
@Nullable
public JetTypeReference setExtendsBound(@Nullable JetTypeReference typeReference) {
JetTypeReference currentExtendsBound = getExtendsBound();
if (currentExtendsBound != null) {
if (typeReference == null) {
PsiElement colon = findChildByType(JetTokens.COLON);
if (colon != null) colon.delete();
currentExtendsBound.delete();
return null;
}
return (JetTypeReference) currentExtendsBound.replace(typeReference);
}
if (typeReference != null) {
PsiElement colon = addAfter(new JetPsiFactory(getProject()).createColon(), getNameIdentifier());
return (JetTypeReference) addAfter(typeReference, colon);
}
return null;
}
@Nullable
public JetTypeReference getExtendsBound() {
return getStubOrPsiChild(JetStubElementTypes.TYPE_REFERENCE);