Skip to content

Commit

Permalink
Add 'Introduce Parameter...' code action
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza authored and fbricon committed Jul 17, 2020
1 parent 32891e5 commit f64a7e7
Show file tree
Hide file tree
Showing 19 changed files with 5,251 additions and 2 deletions.
6 changes: 6 additions & 0 deletions org.eclipse.jdt.ls.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,10 @@
order="2000"
class="org.eclipse.jdt.ls.core.internal.managers.EclipseBuildSupport" />
</extension>
<extension
point="org.eclipse.ltk.core.refactoring.refactoringContributions">
<contribution
class="org.eclipse.jdt.ls.core.internal.corext.refactoring.ChangeMethodSignatureRefactoringContribution"
id="org.eclipse.jdt.ls.change.method.signature"/>
</extension>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ public interface IConstants {
* Update workspace folders job family id
*/
public static final String UPDATE_WORKSPACE_FOLDERS_FAMILY = JOBS_FAMILY + ".updateWorkspaceFolders";

public static final String CHANGE_METHOD_SIGNATURE = "org.eclipse.jdt.ls.change.method.signature";
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public interface JavaCodeActionKind {
*/
public static final String REFACTOR_ASSIGN_FIELD = CodeActionKind.Refactor + ".assign.field";

/**
* Introduce parameter
*/
public static final String REFACTOR_INTRODUCE_PARAMETER = CodeActionKind.Refactor + ".introduce.parameter";

/**
* Base kind for "quickassist" code actions
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Originally copied from org.eclipse.jdt.internal.corext.refactoring.structure.BodyUpdater
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ls.core.internal.corext.refactoring;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;


public abstract class BodyUpdater {

/**
* Updates the body of a method declaration. This method is called by the
* {@link ChangeSignatureProcessor} and allows implementors to refactor the body
* of the given method declaration.
*
* @param methodDeclaration
* @param cuRewrite
* @param result
* @throws CoreException
*/
public abstract void updateBody(MethodDeclaration methodDeclaration, CompilationUnitRewrite cuRewrite, RefactoringStatus result) throws CoreException;

/**
* Returns whether {@link ChangeSignatureProcessor} should check if
* deleted parameters are currently used in the method body.
*
* @return <code>true</code> by default, subclasses can override
*/
public boolean needsParameterUsedCheck() {
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2005, 2011 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Copied from org.eclipse.jdt.internal.corext.refactoring.scripting.ChangeMethodSignatureRefactoringContribution
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/

package org.eclipse.jdt.ls.core.internal.corext.refactoring;

import java.util.Map;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringContribution;
import org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor;
import org.eclipse.jdt.internal.core.refactoring.descriptors.RefactoringSignatureDescriptorFactory;
import org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments;
import org.eclipse.ltk.core.refactoring.Refactoring;
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring;

/**
* Refactoring contribution for the change method signature refactoring.
*
* @since 3.2
*/
public final class ChangeMethodSignatureRefactoringContribution extends JavaRefactoringContribution {

@Override
public Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) throws CoreException {
JavaRefactoringArguments arguments= new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor));
ChangeSignatureProcessor processor= new ChangeSignatureProcessor(arguments, status);
return new ProcessorBasedRefactoring(processor);
}

@Override
public RefactoringDescriptor createDescriptor() {
return RefactoringSignatureDescriptorFactory.createChangeMethodSignatureDescriptor();
}

@Override
public RefactoringDescriptor createDescriptor(String id, String project, String description, String comment, Map<String, String> arguments, int flags) {
return RefactoringSignatureDescriptorFactory.createChangeMethodSignatureDescriptor(project, description, comment, arguments, flags);
}

}
Loading

0 comments on commit f64a7e7

Please sign in to comment.