use of kotlin.jvm.functions.Function0 in project kotlin by JetBrains.
the class KotlinInplaceVariableIntroducer method getCreateExplicitTypeCheckBox.
@Nullable
protected final Function0<JComponent> getCreateExplicitTypeCheckBox() {
if (myExprType == null || noTypeInference)
return null;
return new Function0<JComponent>() {
@Override
public JComponent invoke() {
final JCheckBox exprTypeCheckbox = new NonFocusableCheckBox("Specify type explicitly");
exprTypeCheckbox.setSelected(false);
exprTypeCheckbox.setMnemonic('t');
exprTypeCheckbox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
runWriteActionAndRestartRefactoring(new Runnable() {
@Override
public void run() {
if (exprTypeCheckbox.isSelected()) {
String renderedType = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(myExprType);
myDeclaration.setTypeReference(new KtPsiFactory(myProject).createType(renderedType));
} else {
myDeclaration.setTypeReference(null);
}
}
});
}
});
return exprTypeCheckbox;
}
};
}
use of kotlin.jvm.functions.Function0 in project kotlin by JetBrains.
the class KotlinInplaceVariableIntroducer method getCreateVarCheckBox.
@Nullable
protected final Function0<JComponent> getCreateVarCheckBox() {
if (myDoNotChangeVar)
return null;
return new Function0<JComponent>() {
@Override
public JComponent invoke() {
final JCheckBox varCheckbox = new NonFocusableCheckBox("Declare with var");
varCheckbox.setSelected(isVar);
varCheckbox.setMnemonic('v');
varCheckbox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(@NotNull ActionEvent e) {
new WriteCommandAction(myProject, getCommandName(), getCommandName()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument());
KtPsiFactory psiFactory = new KtPsiFactory(myProject);
PsiElement keyword = varCheckbox.isSelected() ? psiFactory.createVarKeyword() : psiFactory.createValKeyword();
PsiElement valOrVar = myDeclaration instanceof KtProperty ? ((KtProperty) myDeclaration).getValOrVarKeyword() : ((KtParameter) myDeclaration).getValOrVarKeyword();
valOrVar.replace(keyword);
}
}.execute();
}
});
return varCheckbox;
}
};
}
use of kotlin.jvm.functions.Function0 in project kotlin by JetBrains.
the class Java8Class method testConstructor.
public void testConstructor() {
Function0 constructorSameClass = Java8Class::new;
constructorSameClass.invoke();
Function0 qualifiedConstructorSameClass = test.Java8Class::new;
qualifiedConstructorSameClass.invoke();
Function0 constructorAnotherClass = Test::new;
constructorAnotherClass.invoke();
Function0 qualifiedConstructorAnotherClass = test.Test::new;
qualifiedConstructorAnotherClass.invoke();
}
use of kotlin.jvm.functions.Function0 in project kotlin by JetBrains.
the class Java8Class method testStaticFunction.
public void testStaticFunction() {
Function0 staticFunFromSameClass = Java8Class::staticFun;
staticFunFromSameClass.invoke();
Function0 staticFunFromAnotherClass = Test::staticFun;
staticFunFromAnotherClass.invoke();
}
use of kotlin.jvm.functions.Function0 in project kotlin by JetBrains.
the class Java8Class method testMemberFunctionThroughObject.
public void testMemberFunctionThroughObject() {
Java8Class obj = new Java8Class();
Function0 memberFunFromSameClass = obj::memberFun;
memberFunFromSameClass.invoke();
Test anotherObj = new Test();
Function0 memFunFromAnotherClass = anotherObj::memberFun;
memFunFromAnotherClass.invoke();
Function0 memberFunThroughObj1 = field::memberFun;
memberFunThroughObj1.invoke();
Function0 memberFunThroughObj2 = Test.field::memberFun;
memberFunThroughObj2.invoke();
Function0 memberFunThroughObj3 = Test.staticFun()::memberFun;
memberFunThroughObj3.invoke();
}
Aggregations