Search in sources :

Example 1 with Function0

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;
        }
    };
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) NonFocusableCheckBox(com.intellij.ui.NonFocusableCheckBox) Function0(kotlin.jvm.functions.Function0) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with Function0

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;
        }
    };
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) NonFocusableCheckBox(com.intellij.ui.NonFocusableCheckBox) Function0(kotlin.jvm.functions.Function0) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with Function0

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();
}
Also used : Function0(kotlin.jvm.functions.Function0)

Example 4 with Function0

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();
}
Also used : Function0(kotlin.jvm.functions.Function0)

Example 5 with Function0

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();
}
Also used : Function0(kotlin.jvm.functions.Function0)

Aggregations

Function0 (kotlin.jvm.functions.Function0)5 NonFocusableCheckBox (com.intellij.ui.NonFocusableCheckBox)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 Nullable (org.jetbrains.annotations.Nullable)2 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 NotNull (org.jetbrains.annotations.NotNull)1