use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.
the class IntroduceParameterObjectDialog method createParametersPanel.
protected ParameterTablePanel createParametersPanel() {
final PsiParameterList parameterList = mySourceMethod.getParameterList();
final PsiParameter[] parameters = parameterList.getParameters();
VariableData[] parameterInfo = new VariableData[parameters.length];
for (int i = 0; i < parameterInfo.length; i++) {
parameterInfo[i] = new VariableData(parameters[i]);
parameterInfo[i].name = parameters[i].getName();
parameterInfo[i].passAsParameter = true;
}
return new ParameterTablePanel(myProject, parameterInfo) {
protected void updateSignature() {
}
protected void doEnterAction() {
}
protected void doCancelAction() {
IntroduceParameterObjectDialog.this.doCancelAction();
}
};
}
use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.
the class ExtractMethodDialog method checkMethodConflicts.
protected void checkMethodConflicts(MultiMap<PsiElement, String> conflicts) {
PsiMethod prototype;
try {
PsiElementFactory factory = JavaPsiFacade.getInstance(myProject).getElementFactory();
prototype = factory.createMethod(myNameField.getEnteredName().trim(), myReturnType);
if (myTypeParameterList != null)
prototype.getTypeParameterList().replace(myTypeParameterList);
for (VariableData data : myInputVariables) {
if (data.passAsParameter) {
prototype.getParameterList().add(factory.createParameter(data.name, data.type));
}
}
// set the modifiers with which the method is supposed to be created
PsiUtil.setModifierProperty(prototype, PsiModifier.PRIVATE, true);
} catch (IncorrectOperationException e) {
return;
}
ConflictsUtil.checkMethodConflicts(myTargetClass, null, prototype, conflicts);
}
use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.
the class ExtractMethodDialog method createOptionsPanel.
protected JPanel createOptionsPanel() {
final JPanel optionsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 5));
if (myStaticFlag || myCanBeStatic) {
myMakeStatic.setEnabled(!myStaticFlag);
myMakeStatic.setSelected(myStaticFlag);
if (myVariableData.hasInstanceFields()) {
myMakeStatic.setText(RefactoringBundle.message("declare.static.pass.fields.checkbox"));
}
myMakeStatic.addItemListener(e -> {
if (myVariableData.hasInstanceFields()) {
myVariableData.setPassFields(myMakeStatic.isSelected());
myInputVariables = myVariableData.getInputVariables().toArray(new VariableData[myVariableData.getInputVariables().size()]);
updateVarargsEnabled();
createParametersPanel();
}
updateSignature();
});
optionsPanel.add(myMakeStatic);
} else {
myMakeStatic.setSelected(false);
myMakeStatic.setEnabled(false);
}
final Border emptyBorder = IdeBorderFactory.createEmptyBorder(5, 0, 5, 4);
myMakeStatic.setBorder(emptyBorder);
myFoldParameters.setSelected(myVariableData.isFoldingSelectedByDefault());
myFoldParameters.setVisible(myVariableData.isFoldable());
myVariableData.setFoldingAvailable(myFoldParameters.isSelected());
myInputVariables = myVariableData.getInputVariables().toArray(new VariableData[myVariableData.getInputVariables().size()]);
myFoldParameters.addActionListener(e -> {
myVariableData.setFoldingAvailable(myFoldParameters.isSelected());
myInputVariables = myVariableData.getInputVariables().toArray(new VariableData[myVariableData.getInputVariables().size()]);
updateVarargsEnabled();
createParametersPanel();
updateSignature();
});
optionsPanel.add(myFoldParameters);
myFoldParameters.setBorder(emptyBorder);
boolean canBeVarargs = false;
for (VariableData data : myInputVariables) {
canBeVarargs |= data.type instanceof PsiArrayType;
}
if (myVariableData.isFoldable()) {
canBeVarargs |= myVariableData.isFoldingSelectedByDefault();
}
if (canBeVarargs) {
myMakeVarargs = new NonFocusableCheckBox(RefactoringBundle.message("declare.varargs.checkbox"));
myMakeVarargs.setBorder(emptyBorder);
updateVarargsEnabled();
myMakeVarargs.addItemListener(e -> updateSignature());
myMakeVarargs.setSelected(false);
optionsPanel.add(myMakeVarargs);
}
if (myNullness != null && myNullness != Nullness.UNKNOWN) {
final boolean isSelected = PropertiesComponent.getInstance(myProject).getBoolean(EXTRACT_METHOD_GENERATE_ANNOTATIONS, true);
myGenerateAnnotations = new JCheckBox(RefactoringBundle.message("declare.generated.annotations"), isSelected);
myGenerateAnnotations.addItemListener(e -> updateSignature());
optionsPanel.add(myGenerateAnnotations);
}
if (myCbChainedConstructor != null) {
optionsPanel.add(myCbChainedConstructor);
myCbChainedConstructor.setBorder(emptyBorder);
myCbChainedConstructor.addItemListener(e -> {
if (myDefaultVisibility) {
myChangingVisibility = true;
try {
if (isChainedConstructor()) {
myVisibilityPanel.setVisibility(VisibilityUtil.getVisibilityModifier(myTargetClass.getModifierList()));
} else {
myVisibilityPanel.setVisibility(PsiModifier.PRIVATE);
}
} finally {
myChangingVisibility = false;
}
}
update();
});
}
return optionsPanel;
}
use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.
the class ExtractMethodDialog method doOKAction.
@Override
protected void doOKAction() {
MultiMap<PsiElement, String> conflicts = new MultiMap<>();
checkMethodConflicts(conflicts);
if (!conflicts.isEmpty()) {
final ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
if (!conflictsDialog.showAndGet()) {
if (conflictsDialog.isShowConflicts())
close(CANCEL_EXIT_CODE);
return;
}
}
if (myMakeVarargs != null && myMakeVarargs.isSelected()) {
final VariableData data = myInputVariables[myInputVariables.length - 1];
if (data.type instanceof PsiArrayType) {
data.type = new PsiEllipsisType(((PsiArrayType) data.type).getComponentType());
}
}
final PsiMethod containingMethod = getContainingMethod();
if (containingMethod != null && containingMethod.hasModifierProperty(PsiModifier.PUBLIC)) {
PropertiesComponent.getInstance(myProject).setValue(EXTRACT_METHOD_DEFAULT_VISIBILITY, getVisibility());
}
if (myGenerateAnnotations != null && myGenerateAnnotations.isEnabled()) {
PropertiesComponent.getInstance(myProject).setValue(EXTRACT_METHOD_GENERATE_ANNOTATIONS, myGenerateAnnotations.isSelected(), true);
}
super.doOKAction();
}
use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.
the class ExtractMethodSignatureSuggester method restoreRenamedParams.
private void restoreRenamedParams(List<PsiExpression> copies, ParametersFolder folder) {
final Map<String, String> renameMap = new HashMap<>();
for (VariableData data : myVariableData) {
final String replacement = folder.getGeneratedCallArgument(data);
if (!data.name.equals(replacement)) {
renameMap.put(data.name, replacement);
}
}
if (!renameMap.isEmpty()) {
for (PsiExpression currentExpression : copies) {
final Map<PsiReferenceExpression, String> params = new HashMap<>();
currentExpression.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
super.visitReferenceExpression(expression);
final PsiElement resolve = expression.resolve();
if (resolve instanceof PsiParameter && myExtractedMethod.equals(((PsiParameter) resolve).getDeclarationScope())) {
final String name = ((PsiParameter) resolve).getName();
final String variable = renameMap.get(name);
if (renameMap.containsKey(name)) {
params.put(expression, variable);
}
}
}
});
for (PsiReferenceExpression expression : params.keySet()) {
final String var = params.get(expression);
expression.replace(myElementFactory.createExpressionFromText(var, expression));
}
}
}
}
Aggregations