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;
}
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("{}");
}
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();
}
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;
}
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());
}
Aggregations