use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.
the class ExtractMethodDialog method getSignature.
protected String getSignature() {
@NonNls final StringBuilder buffer = new StringBuilder();
if (myGenerateAnnotations != null && myGenerateAnnotations.isSelected()) {
final NullableNotNullManager nullManager = NullableNotNullManager.getInstance(myProject);
buffer.append("@");
buffer.append(StringUtil.getShortName(myNullness == Nullness.NULLABLE ? nullManager.getDefaultNullable() : nullManager.getDefaultNotNull()));
buffer.append("\n");
}
final String visibilityString = VisibilityUtil.getVisibilityString(getVisibility());
buffer.append(visibilityString);
if (buffer.length() > 0) {
buffer.append(" ");
}
if (isMakeStatic() && !isChainedConstructor()) {
buffer.append("static ");
}
if (myTypeParameterList != null) {
final String typeParamsText = myTypeParameterList.getText();
if (!typeParamsText.isEmpty()) {
buffer.append(typeParamsText);
buffer.append(" ");
}
}
if (isChainedConstructor()) {
buffer.append(myTargetClass.getName());
} else {
buffer.append(PsiFormatUtil.formatType(mySelector != null ? mySelector.getSelectedType() : myReturnType, 0, PsiSubstitutor.EMPTY));
buffer.append(" ");
buffer.append(myNameField.getEnteredName());
}
buffer.append("(");
final String INDENT = StringUtil.repeatSymbol(' ', buffer.length());
final VariableData[] datas = myInputVariables;
int count = 0;
for (int i = 0; i < datas.length; i++) {
VariableData data = datas[i];
if (data.passAsParameter) {
//String typeAndModifiers = PsiFormatUtil.formatVariable(data.variable,
// PsiFormatUtil.SHOW_MODIFIERS | PsiFormatUtil.SHOW_TYPE);
PsiType type = data.type;
if (i == datas.length - 1 && type instanceof PsiArrayType && myMakeVarargs != null && myMakeVarargs.isSelected()) {
type = new PsiEllipsisType(((PsiArrayType) type).getComponentType());
}
String typeText = type.getPresentableText();
if (count > 0) {
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");
}
}
return buffer.toString();
}
use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.
the class AnonymousToInnerDialog method getVariableInfos.
public VariableInfo[] getVariableInfos() {
JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(myProject);
VariableInfo[] infos = new VariableInfo[myVariableData.length];
for (int idx = 0; idx < myVariableData.length; idx++) {
VariableData data = myVariableData[idx];
VariableInfo info = myVariableToInfoMap.get(data.variable);
info.passAsParameter = data.passAsParameter;
info.parameterName = data.name;
info.parameterName = data.name;
String propertyName = codeStyleManager.variableNameToPropertyName(data.name, VariableKind.PARAMETER);
info.fieldName = codeStyleManager.propertyNameToVariableName(propertyName, VariableKind.FIELD);
infos[idx] = info;
}
return infos;
}
use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.
the class ParametersFolder method foldParameterUsagesInBody.
public void foldParameterUsagesInBody(@NotNull List<VariableData> datum, PsiElement[] elements, SearchScope scope) {
Map<VariableData, Set<PsiExpression>> equivalentExpressions = new LinkedHashMap<>();
for (VariableData data : datum) {
if (myDeleted.contains(data.variable))
continue;
final PsiExpression psiExpression = myExpressions.get(data.variable);
if (psiExpression == null)
continue;
final Set<PsiExpression> eqExpressions = new HashSet<>();
for (PsiReference reference : ReferencesSearch.search(data.variable, scope)) {
final PsiExpression expression = findEquivalent(psiExpression, reference.getElement());
if (expression != null && expression.isValid()) {
eqExpressions.add(expression);
}
}
equivalentExpressions.put(data, eqExpressions);
}
for (VariableData data : equivalentExpressions.keySet()) {
final Set<PsiExpression> eqExpressions = equivalentExpressions.get(data);
for (PsiExpression expression : eqExpressions) {
//was replaced on previous step
if (!expression.isValid())
continue;
final PsiExpression refExpression = JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(data.name, expression);
final PsiElement replaced = expression.replace(refExpression);
for (int i = 0, psiElementsLength = elements.length; i < psiElementsLength; i++) {
PsiElement psiElement = elements[i];
if (expression == psiElement) {
elements[i] = replaced;
break;
}
}
}
}
}
use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.
the class SuggestedParamTypesTest method doTest.
private void doTest(String... types) throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".java");
final Editor editor = getEditor();
final PsiFile file = getFile();
final Project project = getProject();
int startOffset = editor.getSelectionModel().getSelectionStart();
int endOffset = editor.getSelectionModel().getSelectionEnd();
PsiElement[] elements;
PsiExpression expr = CodeInsightUtil.findExpressionInRange(file, startOffset, endOffset);
if (expr != null) {
elements = new PsiElement[] { expr };
} else {
elements = CodeInsightUtil.findStatementsInRange(file, startOffset, endOffset);
}
assertTrue(elements.length > 0);
final ExtractMethodProcessor processor = new ExtractMethodProcessor(project, editor, elements, null, "Extract Method", "newMethod", null);
processor.prepare();
for (final VariableData data : processor.getInputVariables().getInputVariables()) {
final PsiExpression[] occurrences = ParameterTablePanel.findVariableOccurrences(elements, data.variable);
final TypeSelectorManager manager = new TypeSelectorManagerImpl(project, data.type, occurrences, true) {
@Override
protected boolean isUsedAfter() {
return processor.isOutputVariable(data.variable);
}
};
final JComponent component = manager.getTypeSelector().getComponent();
if (types.length > 1) {
assertTrue("One type suggested", component instanceof JComboBox);
final DefaultComboBoxModel model = (DefaultComboBoxModel) ((JComboBox) component).getModel();
assertEquals(types.length, model.getSize());
for (int i = 0, typesLength = types.length; i < typesLength; i++) {
String type = types[i];
assertEquals(type, model.getElementAt(i).toString());
}
} else if (types.length == 1) {
assertTrue("Multiple types suggested", component instanceof JLabel);
assertEquals(types[0], ((JLabel) component).getText());
}
}
}
use of com.intellij.refactoring.util.VariableData in project intellij-community by JetBrains.
the class MakeMethodStaticTest method performWithFields.
private static void performWithFields(boolean delegate) {
PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED);
assertTrue(element instanceof PsiMethod);
PsiMethod method = (PsiMethod) element;
final ArrayList<VariableData> parametersForFields = new ArrayList<>();
final boolean addClassParameter = MakeStaticUtil.buildVariableData(method, parametersForFields);
new MakeMethodStaticProcessor(getProject(), method, new Settings(true, addClassParameter ? "anObject" : null, parametersForFields.toArray(new VariableData[parametersForFields.size()]), delegate)).run();
}
Aggregations