Search in sources :

Example 1 with ClassMember

use of com.intellij.codeInsight.generation.ClassMember in project intellij-community by JetBrains.

the class GroovyGeneratePropertyMissingHandler method chooseOriginalMembers.

@Nullable
@Override
protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project) {
    final PsiMethod[] missings = aClass.findMethodsByName("propertyMissing", true);
    PsiMethod getter = null;
    PsiMethod setter = null;
    for (PsiMethod missing : missings) {
        final PsiParameter[] parameters = missing.getParameterList().getParameters();
        if (parameters.length == 1) {
            if (isNameParam(parameters[0])) {
                getter = missing;
            }
        } else if (parameters.length == 2) {
            if (isNameParam(parameters[0])) {
                setter = missing;
            }
        }
    }
    if (setter != null && getter != null) {
        String text = GroovyCodeInsightBundle.message("generate.property.missing.already.defined.warning");
        if (Messages.showYesNoDialog(project, text, GroovyCodeInsightBundle.message("generate.property.missing.already.defined.title"), Messages.getQuestionIcon()) == Messages.YES) {
            final PsiMethod finalGetter = getter;
            final PsiMethod finalSetter = setter;
            if (!ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() {

                @Override
                public Boolean compute() {
                    try {
                        finalSetter.delete();
                        finalGetter.delete();
                        return Boolean.TRUE;
                    } catch (IncorrectOperationException e) {
                        LOG.error(e);
                        return Boolean.FALSE;
                    }
                }
            }).booleanValue()) {
                return null;
            }
        } else {
            return null;
        }
    }
    return new ClassMember[1];
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) PsiMethod(com.intellij.psi.PsiMethod) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ClassMember(com.intellij.codeInsight.generation.ClassMember) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ClassMember

use of com.intellij.codeInsight.generation.ClassMember in project intellij-community by JetBrains.

the class GenerateConstructorTest method doTest.

private void doTest(boolean preSelect) {
    String name = getTestName(false);
    myFixture.configureByFile("before" + name + ".java");
    new GenerateConstructorHandler() {

        @Override
        protected ClassMember[] chooseMembers(ClassMember[] members, boolean allowEmpty, boolean copyJavadoc, Project project, Editor editor) {
            if (preSelect) {
                List<ClassMember> preselection = GenerateConstructorHandler.preselect(members);
                return preselection.toArray(new ClassMember[preselection.size()]);
            } else {
                return members;
            }
        }
    }.invoke(getProject(), getEditor(), getFile());
    myFixture.checkResultByFile("after" + name + ".java");
}
Also used : Project(com.intellij.openapi.project.Project) List(java.util.List) Editor(com.intellij.openapi.editor.Editor) ClassMember(com.intellij.codeInsight.generation.ClassMember) GenerateConstructorHandler(com.intellij.codeInsight.generation.GenerateConstructorHandler)

Example 3 with ClassMember

use of com.intellij.codeInsight.generation.ClassMember in project intellij-community by JetBrains.

the class GroovyGenerateMethodMissingHandler method chooseOriginalMembers.

@Nullable
@Override
protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project) {
    final PsiMethod[] missings = aClass.findMethodsByName("methodMissing", true);
    PsiMethod method = null;
    for (PsiMethod missing : missings) {
        final PsiParameter[] parameters = missing.getParameterList().getParameters();
        if (parameters.length == 2) {
            if (isNameParam(parameters[0])) {
                method = missing;
            }
        }
    }
    if (method != null) {
        String text = GroovyCodeInsightBundle.message("generate.method.missing.already.defined.warning");
        if (Messages.showYesNoDialog(project, text, GroovyCodeInsightBundle.message("generate.method.missing.already.defined.title"), Messages.getQuestionIcon()) == Messages.YES) {
            final PsiMethod finalMethod = method;
            if (!ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() {

                @Override
                public Boolean compute() {
                    try {
                        finalMethod.delete();
                        return Boolean.TRUE;
                    } catch (IncorrectOperationException e) {
                        LOG.error(e);
                        return Boolean.FALSE;
                    }
                }
            }).booleanValue()) {
                return null;
            }
        } else {
            return null;
        }
    }
    return new ClassMember[1];
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) PsiMethod(com.intellij.psi.PsiMethod) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ClassMember(com.intellij.codeInsight.generation.ClassMember) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ClassMember

use of com.intellij.codeInsight.generation.ClassMember in project intellij-community by JetBrains.

the class GenerateGetterSetterTest method doTest.

protected void doTest() throws Exception {
    configureByFile("/generateGetterSetter/before" + getTestName(false) + ".java");
    new GenerateGetterAndSetterHandler() {

        @Nullable
        @Override
        protected ClassMember[] chooseMembers(ClassMember[] members, boolean allowEmptySelection, boolean copyJavadocCheckbox, Project project, @Nullable Editor editor) {
            return members;
        }
    }.invoke(getProject(), getEditor(), getFile());
    UIUtil.dispatchAllInvocationEvents();
    checkResultByFile("/generateGetterSetter/after" + getTestName(false) + ".java");
}
Also used : Project(com.intellij.openapi.project.Project) GenerateGetterAndSetterHandler(com.intellij.codeInsight.generation.GenerateGetterAndSetterHandler) Editor(com.intellij.openapi.editor.Editor) ClassMember(com.intellij.codeInsight.generation.ClassMember) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ClassMember

use of com.intellij.codeInsight.generation.ClassMember in project intellij-plugins by JetBrains.

the class RubyMotionOverrideTest method doTest.

private void doTest(@NotNull final String name, @NotNull final String result) throws Exception {
    final Symbol controller = SymbolUtil.findSymbol(getProject(), Type.CLASS, "TestController", null);
    assertNotNull(controller);
    final List<ClassMember> list = RubyOverrideHandler.createOverrideMembers(controller, myFixture.getFile());
    final StringBuilder namesInClass = new StringBuilder();
    for (ClassMember classMember : list) {
        MemberChooserObjectBase methodMember = (MemberChooserObjectBase) classMember;
        if (name.equals(methodMember.getText())) {
            final PsiElement element = OverriddenMethodGenerator.generate(classMember, LanguageLevel.RUBY19);
            assertNotNull(element);
            namesInClass.append(element.getText()).append("\n");
        }
    }
    assertEquals(result, namesInClass.toString().trim());
}
Also used : MemberChooserObjectBase(com.intellij.codeInsight.generation.MemberChooserObjectBase) Symbol(org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol) ClassMember(com.intellij.codeInsight.generation.ClassMember) PsiElement(com.intellij.psi.PsiElement)

Aggregations

ClassMember (com.intellij.codeInsight.generation.ClassMember)5 Nullable (org.jetbrains.annotations.Nullable)3 Editor (com.intellij.openapi.editor.Editor)2 Project (com.intellij.openapi.project.Project)2 PsiMethod (com.intellij.psi.PsiMethod)2 PsiParameter (com.intellij.psi.PsiParameter)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 GenerateConstructorHandler (com.intellij.codeInsight.generation.GenerateConstructorHandler)1 GenerateGetterAndSetterHandler (com.intellij.codeInsight.generation.GenerateGetterAndSetterHandler)1 MemberChooserObjectBase (com.intellij.codeInsight.generation.MemberChooserObjectBase)1 PsiElement (com.intellij.psi.PsiElement)1 List (java.util.List)1 Symbol (org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol)1