Search in sources :

Example 6 with VariableData

use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.

the class ExtractMethodSignatureSuggester method getDuplicates.

public List<Match> getDuplicates(final PsiMethod method, final PsiMethodCallExpression methodCall, ParametersFolder folder) {
    final List<Match> duplicates = findDuplicatesSignature(method, folder);
    if (duplicates != null && !duplicates.isEmpty()) {
        if (ApplicationManager.getApplication().isUnitTestMode() || new PreviewDialog(method, myExtractedMethod, methodCall, myMethodCall, duplicates.size()).showAndGet()) {
            PsiDocumentManager.getInstance(myProject).commitAllDocuments();
            WriteCommandAction.runWriteCommandAction(myProject, () -> {
                myMethodCall = (PsiMethodCallExpression) methodCall.replace(myMethodCall);
                myExtractedMethod = (PsiMethod) method.replace(myExtractedMethod);
            });
            final DuplicatesFinder finder = MethodDuplicatesHandler.createDuplicatesFinder(myExtractedMethod);
            if (finder != null) {
                final List<VariableData> datas = finder.getParameters().getInputVariables();
                myVariableData = datas.toArray(new VariableData[datas.size()]);
                return finder.findDuplicates(myExtractedMethod.getContainingClass());
            }
        }
    }
    return null;
}
Also used : DuplicatesFinder(com.intellij.refactoring.util.duplicates.DuplicatesFinder) VariableData(com.intellij.refactoring.util.VariableData) Match(com.intellij.refactoring.util.duplicates.Match)

Example 7 with VariableData

use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.

the class ExtractMethodObjectDialog method methodSignature.

private void methodSignature(final String INDENT, final StringBuffer buffer) {
    buffer.append("(");
    int count = 0;
    final String indent = "    ";
    for (int i = 0; i < myInputVariables.length; i++) {
        VariableData data = myInputVariables[i];
        if (data.passAsParameter) {
            //String typeAndModifiers = PsiFormatUtil.formatVariable(data.variable,
            //  PsiFormatUtil.SHOW_MODIFIERS | PsiFormatUtil.SHOW_TYPE);
            PsiType type = data.type;
            if (i == myInputVariables.length - 1 && type instanceof PsiArrayType && ((myCreateInnerClassRb.isSelected() && myCbMakeVarargs.isSelected()) || (myCreateAnonymousClassWrapperRb.isSelected() && myCbMakeVarargsAnonymous.isSelected()))) {
                type = new PsiEllipsisType(((PsiArrayType) type).getComponentType());
            }
            String typeText = type.getPresentableText();
            if (count > 0) {
                buffer.append(", ");
            }
            buffer.append("\n");
            buffer.append(indent);
            buffer.append(typeText);
            buffer.append(" ");
            buffer.append(data.name);
            count++;
        }
    }
    buffer.append(")");
    if (myExceptions.length > 0) {
        buffer.append("\n");
        buffer.append("throws\n");
        for (PsiType exception : myExceptions) {
            buffer.append(INDENT);
            buffer.append(PsiFormatUtil.formatType(exception, 0, PsiSubstitutor.EMPTY));
            buffer.append("\n");
        }
    }
    buffer.append("{}");
}
Also used : VariableData(com.intellij.refactoring.util.VariableData)

Example 8 with VariableData

use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.

the class ExtractMethodObjectDialog method doOKAction.

@Override
protected void doOKAction() {
    MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    if (myCreateInnerClassRb.isSelected()) {
        final PsiClass innerClass = myTargetClass.findInnerClassByName(myInnerClassName.getText(), false);
        if (innerClass != null) {
            conflicts.putValue(innerClass, "Inner class " + myInnerClassName.getText() + " already defined in class " + myTargetClass.getName());
        }
    }
    if (conflicts.size() > 0) {
        final ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
        if (!conflictsDialog.showAndGet()) {
            if (conflictsDialog.isShowConflicts())
                close(CANCEL_EXIT_CODE);
            return;
        }
    }
    final JCheckBox makeVarargsCb = myCreateInnerClassRb.isSelected() ? myCbMakeVarargs : myCbMakeVarargsAnonymous;
    if (makeVarargsCb != null && makeVarargsCb.isSelected()) {
        final VariableData data = myInputVariables[myInputVariables.length - 1];
        if (data.type instanceof PsiArrayType) {
            data.type = new PsiEllipsisType(((PsiArrayType) data.type).getComponentType());
        }
    }
    super.doOKAction();
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) VariableData(com.intellij.refactoring.util.VariableData)

Example 9 with VariableData

use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.

the class ExtractMethodObjectDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    mySignatureArea.setEditable(false);
    myCreateInnerClassRb.setSelected(true);
    final ActionListener enableDisableListener = new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            enable(myCreateInnerClassRb.isSelected());
        }
    };
    myCreateInnerClassRb.addActionListener(enableDisableListener);
    myCreateAnonymousClassWrapperRb.addActionListener(enableDisableListener);
    myCreateAnonymousClassWrapperRb.setEnabled(!myMultipleExitPoints);
    myFoldCb.setSelected(myVariableData.isFoldingSelectedByDefault());
    myFoldCb.setVisible(myVariableData.isFoldable());
    myVariableData.setFoldingAvailable(myFoldCb.isSelected());
    myInputVariables = myVariableData.getInputVariables().toArray(new VariableData[myVariableData.getInputVariables().size()]);
    myFoldCb.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            myVariableData.setFoldingAvailable(myFoldCb.isSelected());
            myInputVariables = myVariableData.getInputVariables().toArray(new VariableData[myVariableData.getInputVariables().size()]);
            myParametersTableContainer.removeAll();
            myParametersTableContainer.add(createParametersPanel(), BorderLayout.CENTER);
            myParametersTableContainer.revalidate();
            updateSignature();
            updateVarargsEnabled();
        }
    });
    myParametersTableContainer.add(createParametersPanel(), BorderLayout.CENTER);
    final ActionListener updateSugnatureListener = new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            updateSignature();
            IdeFocusManager.getInstance(myProject).requestFocus(myCreateInnerClassRb.isSelected() ? myInnerClassName : myMethodName, false);
        }
    };
    if (myStaticFlag || myCanBeStatic) {
        myCbMakeStatic.setEnabled(!myStaticFlag);
        myCbMakeStatic.setSelected(myStaticFlag);
        myCbMakeStatic.addActionListener(updateSugnatureListener);
    } else {
        myCbMakeStatic.setSelected(false);
        myCbMakeStatic.setEnabled(false);
    }
    updateVarargsEnabled();
    myCbMakeVarargs.setSelected(myWasStatic);
    myCbMakeVarargs.addActionListener(updateSugnatureListener);
    myCbMakeVarargsAnonymous.setSelected(myWasStatic);
    myCbMakeVarargsAnonymous.addActionListener(updateSugnatureListener);
    final DocumentAdapter nameListener = new DocumentAdapter() {

        @Override
        public void documentChanged(final DocumentEvent e) {
            update();
        }
    };
    myInnerClassName.getDocument().addDocumentListener(nameListener);
    myMethodName.getDocument().addDocumentListener(nameListener);
    myPrivateRadioButton.setSelected(true);
    myCreateInnerClassRb.addActionListener(updateSugnatureListener);
    myCreateAnonymousClassWrapperRb.addActionListener(updateSugnatureListener);
    final Enumeration<AbstractButton> visibilities = myVisibilityGroup.getElements();
    while (visibilities.hasMoreElements()) {
        visibilities.nextElement().addActionListener(updateSugnatureListener);
    }
    enable(true);
    return myWholePanel;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) VariableData(com.intellij.refactoring.util.VariableData) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 10 with VariableData

use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.

the class IntroduceParameterObjectDialog method createClassDescriptor.

@Override
protected JavaIntroduceParameterObjectClassDescriptor createClassDescriptor() {
    final boolean useExistingClass = useExistingClass();
    final String className;
    final String packageName;
    final boolean createInnerClass = myCreateInnerClassRadioButton.isSelected();
    if (createInnerClass) {
        className = getInnerClassName();
        packageName = "";
    } else if (useExistingClass) {
        final String existingClassName = getExistingClassName();
        className = StringUtil.getShortName(existingClassName);
        packageName = StringUtil.getPackageName(existingClassName);
    } else {
        packageName = getPackageName();
        className = getClassName();
    }
    final String newVisibility = myEscalateVisibilityCheckBox.isEnabled() && myEscalateVisibilityCheckBox.isSelected() ? VisibilityUtil.ESCALATE_VISIBILITY : null;
    final MoveDestination moveDestination = ((DestinationFolderComboBox) myDestinationCb).selectDirectory(new PackageWrapper(PsiManager.getInstance(myProject), packageName), false);
    final PsiParameterList parameterList = mySourceMethod.getParameterList();
    final List<ParameterInfoImpl> parameters = new ArrayList<>();
    for (VariableData data : myParameterTablePanel.getVariableData()) {
        if (data.passAsParameter) {
            parameters.add(new ParameterInfoImpl(parameterList.getParameterIndex((PsiParameter) data.variable), data.name, data.type));
        }
    }
    final ParameterInfoImpl[] infos = parameters.toArray(new ParameterInfoImpl[parameters.size()]);
    return new JavaIntroduceParameterObjectClassDescriptor(className, packageName, moveDestination, useExistingClass, createInnerClass, newVisibility, infos, mySourceMethod, myGenerateAccessorsCheckBox.isSelected());
}
Also used : ArrayList(java.util.ArrayList) DestinationFolderComboBox(com.intellij.refactoring.move.moveClassesOrPackages.DestinationFolderComboBox) ParameterInfoImpl(com.intellij.refactoring.changeSignature.ParameterInfoImpl) VariableData(com.intellij.refactoring.util.VariableData)

Aggregations

VariableData (com.intellij.refactoring.util.VariableData)20 ArrayList (java.util.ArrayList)4 PsiElement (com.intellij.psi.PsiElement)3 JavaCodeStyleManager (com.intellij.psi.codeStyle.JavaCodeStyleManager)2 Settings (com.intellij.refactoring.makeStatic.Settings)2 MultiMap (com.intellij.util.containers.MultiMap)2 THashMap (gnu.trove.THashMap)2 NullableNotNullManager (com.intellij.codeInsight.NullableNotNullManager)1 Editor (com.intellij.openapi.editor.Editor)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 Project (com.intellij.openapi.project.Project)1 PsiClass (com.intellij.psi.PsiClass)1 PsiExpression (com.intellij.psi.PsiExpression)1 PsiFile (com.intellij.psi.PsiFile)1 PsiMethod (com.intellij.psi.PsiMethod)1 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)1 ParameterInfoImpl (com.intellij.refactoring.changeSignature.ParameterInfoImpl)1 ExtractMethodProcessor (com.intellij.refactoring.extractMethod.ExtractMethodProcessor)1 MakeClassStaticProcessor (com.intellij.refactoring.makeStatic.MakeClassStaticProcessor)1