Search in sources :

Example 11 with ParameterInfo

use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project xtext-xtend by eclipse.

the class ExtractMethodUserInputPage method createParameterControl.

protected void createParameterControl(Composite result) {
    if (!refactoring.getParameterInfos().isEmpty()) {
        ChangeParametersControl cp = new ChangeParametersControl(result, SWT.NONE, "Parameters", new IParameterListChangeListener() {

            @Override
            public void parameterChanged(ParameterInfo parameter) {
                parameterModified();
            }

            @Override
            public void parameterListChanged() {
                parameterModified();
            }

            @Override
            public void parameterAdded(ParameterInfo parameter) {
                updatePreview();
            }
        }, ChangeParametersControl.Mode.EXTRACT_METHOD);
        GridData gridData = new GridData(GridData.FILL_BOTH);
        gridData.horizontalSpan = 2;
        cp.setLayoutData(gridData);
        cp.setInput(refactoring.getParameterInfos());
    }
}
Also used : IParameterListChangeListener(org.eclipse.jdt.internal.ui.refactoring.IParameterListChangeListener) GridData(org.eclipse.swt.layout.GridData) ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo) ChangeParametersControl(org.eclipse.jdt.internal.ui.refactoring.ChangeParametersControl)

Example 12 with ParameterInfo

use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project xtext-xtend by eclipse.

the class ExtractMethodIntegrationTest method testSwapParameterNames.

@Test
public void testSwapParameterNames() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo(int i, int j) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("$i-j$");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final Procedure1<ExtractMethodRefactoring> _function = (ExtractMethodRefactoring it) -> {
        ParameterInfo _get = it.getParameterInfos().get(0);
        _get.setNewName("j");
        ParameterInfo _get_1 = it.getParameterInfos().get(1);
        _get_1.setNewName("i");
    };
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("class Foo {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def foo(int i, int j) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("bar(i, j)");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def bar(int j, int i) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("j-i");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertAfterExtract(_builder, _function, _builder_1);
}
Also used : ExtractMethodRefactoring(org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo) Test(org.junit.Test)

Example 13 with ParameterInfo

use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project xtext-xtend by eclipse.

the class ExtractMethodIntegrationTest method testFailOnDuplicateParameterName.

@Test
public void testFailOnDuplicateParameterName() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val x = 4");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val y = 2");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("$x+y$");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final Procedure1<ExtractMethodRefactoring> _function = (ExtractMethodRefactoring it) -> {
        ParameterInfo _get = it.getParameterInfos().get(1);
        _get.setNewName("x");
    };
    this.assertExtractForbidden(_builder, _function, "duplicate");
}
Also used : ExtractMethodRefactoring(org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo) Test(org.junit.Test)

Example 14 with ParameterInfo

use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project xtext-xtend by eclipse.

the class ExtractMethodIntegrationTest method testRenameParameter.

@Test
public void testRenameParameter() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo(int shrinkMe, int expandMe) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("$shrinkMe + expandMe - shrinkMe-  expandMe$");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final Procedure1<ExtractMethodRefactoring> _function = (ExtractMethodRefactoring it) -> {
        ParameterInfo _get = it.getParameterInfos().get(0);
        _get.setNewName("s");
        ParameterInfo _get_1 = it.getParameterInfos().get(1);
        _get_1.setNewName("expandMeMore");
    };
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("class Foo {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def foo(int shrinkMe, int expandMe) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("bar(shrinkMe, expandMe)");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def bar(int s, int expandMeMore) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("s + expandMeMore - s-  expandMeMore");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertAfterExtract(_builder, _function, _builder_1);
}
Also used : ExtractMethodRefactoring(org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo) Test(org.junit.Test)

Example 15 with ParameterInfo

use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project che by eclipse.

the class RenameParametersTest method modifyInfos.

private void modifyInfos(List list, String[] newNames) {
    int i = 0;
    for (Iterator iter = list.iterator(); iter.hasNext(); i++) {
        ParameterInfo info = (ParameterInfo) iter.next();
        info.setNewName(newNames[i]);
    }
}
Also used : Iterator(java.util.Iterator) ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)

Aggregations

ParameterInfo (org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)30 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)6 ArrayList (java.util.ArrayList)5 JavaModelException (org.eclipse.jdt.core.JavaModelException)4 ASTNode (org.eclipse.jdt.core.dom.ASTNode)4 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)4 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)4 ExceptionInfo (org.eclipse.jdt.internal.corext.refactoring.ExceptionInfo)4 RichString (org.eclipse.xtend.core.xtend.RichString)4 HashSet (java.util.HashSet)3 ExtractMethodRefactoring (org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)3 Test (org.junit.Test)3 Expression (org.eclipse.jdt.core.dom.Expression)2 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)2 ReturnStatement (org.eclipse.jdt.core.dom.ReturnStatement)2 SimpleName (org.eclipse.jdt.core.dom.SimpleName)2 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)2 VariableDeclaration (org.eclipse.jdt.core.dom.VariableDeclaration)2