mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-07 16:26:11 +02:00
Extract Function: Add virtual option
This commit is contained in:
parent
c3704262e9
commit
86f9ee8ab7
8 changed files with 133 additions and 5 deletions
|
@ -2778,3 +2778,102 @@ int main()
|
|||
return a;
|
||||
}
|
||||
|
||||
//!ExtractFunctionRefactoringTest virtual
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
//@A.h
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//=
|
||||
#ifndef A_H_
|
||||
#define A_H_
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
A();
|
||||
virtual ~A();
|
||||
int foo();
|
||||
virtual void exp(int & i);
|
||||
|
||||
private:
|
||||
int help();
|
||||
};
|
||||
|
||||
#endif /*A_H_*/
|
||||
|
||||
//@A.cpp
|
||||
#include "A.h"
|
||||
|
||||
A::A()
|
||||
{
|
||||
}
|
||||
|
||||
A::~A()
|
||||
{
|
||||
}
|
||||
int A::foo()
|
||||
{
|
||||
int i = 2;
|
||||
//comment
|
||||
/*$*/++i;
|
||||
help();/*$$*/
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "A.h"
|
||||
|
||||
A::A()
|
||||
{
|
||||
}
|
||||
|
||||
A::~A()
|
||||
{
|
||||
}
|
||||
void A::exp(int & i)
|
||||
{
|
||||
//comment
|
||||
++i;
|
||||
help();
|
||||
}
|
||||
|
||||
int A::foo()
|
||||
{
|
||||
int i = 2;
|
||||
exp(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
int A::help()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
//@.config
|
||||
filename=A.cpp
|
||||
methodname=exp
|
||||
replaceduplicates=false
|
||||
returnvalue=false
|
||||
returnparameterindex=0
|
||||
virtual=true
|
||||
visibility=public
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ public class ExtractFunctionRefactoringTest extends RefactoringTest {
|
|||
protected int returnParameterIndex;
|
||||
protected boolean fatalError;
|
||||
private VisibilityEnum visibility;
|
||||
private boolean virtual;
|
||||
private static int nr = 1;
|
||||
|
||||
/**
|
||||
|
@ -90,6 +91,7 @@ public class ExtractFunctionRefactoringTest extends RefactoringTest {
|
|||
info.setReturnVariable( info.getInScopeDeclaredVariable() );
|
||||
}
|
||||
info.setVisibility(visibility);
|
||||
info.setVirtual(virtual);
|
||||
|
||||
for (NameInformation name : info.getAllAfterUsedNames()) {
|
||||
if(!name.isUserSetIsReturnValue()){
|
||||
|
@ -107,6 +109,7 @@ public class ExtractFunctionRefactoringTest extends RefactoringTest {
|
|||
returnParameterIndex = new Integer(refactoringProperties.getProperty("returnparameterindex", "0")).intValue(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fatalError = Boolean.valueOf(refactoringProperties.getProperty("fatalerror", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
visibility = VisibilityEnum.getEnumForStringRepresentation(refactoringProperties.getProperty("visibility", VisibilityEnum.v_private.toString())); //$NON-NLS-1$
|
||||
virtual = Boolean.valueOf(refactoringProperties.getProperty("virtual", "false")).booleanValue(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
|
@ -101,6 +103,16 @@ public class ExtractFunctionComposite extends Composite {
|
|||
gridData.horizontalAlignment = GridData.FILL;
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
nameVisiComp.setLayoutData(gridData);
|
||||
final Button virtual = new Button(nameVisiComp, SWT.CHECK);
|
||||
virtual.setText(Messages.ExtractFunctionComposite_Virtual);
|
||||
virtual.addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
info.setVirtual(virtual.getSelection());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik
|
||||
* Rapperswil, University of applied sciences and others
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
|
@ -36,6 +36,7 @@ public class ExtractFunctionInformation {
|
|||
private ICPPASTFunctionDeclarator declarator;
|
||||
private MethodContext context;
|
||||
private boolean isExtractExpression;
|
||||
private boolean virtual;
|
||||
|
||||
/**
|
||||
* Returns the function declarator of the method / function from were the statements
|
||||
|
@ -133,4 +134,12 @@ public class ExtractFunctionInformation {
|
|||
public void setExtractExpression(boolean isExtractExpression) {
|
||||
this.isExtractExpression = isExtractExpression;
|
||||
}
|
||||
|
||||
public boolean isVirtual() {
|
||||
return virtual;
|
||||
}
|
||||
|
||||
public void setVirtual(boolean isVirtual) {
|
||||
this.virtual = isVirtual;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ import org.eclipse.cdt.core.dom.ast.IParameter;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
|
@ -875,8 +876,11 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
private IASTSimpleDeclaration getDeclaration(ModificationCollector collector,IASTName name) {
|
||||
IASTDeclSpecifier declSpec = getReturnType();
|
||||
IASTSimpleDeclaration simpleDecl = factory.newSimpleDeclaration(declSpec);
|
||||
if(info.isVirtual() && declSpec instanceof ICPPASTDeclSpecifier) {
|
||||
((ICPPASTDeclSpecifier)declSpec).setVirtual(true);
|
||||
}
|
||||
simpleDecl.setParent(unit);
|
||||
IASTStandardFunctionDeclarator declarator = extractedFunctionConstructionHelper
|
||||
ICPPASTFunctionDeclarator declarator = extractedFunctionConstructionHelper
|
||||
.createFunctionDeclarator(name, info.getDeclarator(), info
|
||||
.getReturnVariable(), container.getNodesToWrite(), info
|
||||
.getAllUsedNames());
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
||||
|
@ -59,7 +58,7 @@ public abstract class ExtractedFunctionConstructionHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
IASTStandardFunctionDeclarator createFunctionDeclarator(IASTName name, ICPPASTFunctionDeclarator functionDeclarator, NameInformation returnVariable, List<IASTNode> nodesToWrite, Collection<NameInformation> allUsedNames) {
|
||||
ICPPASTFunctionDeclarator createFunctionDeclarator(IASTName name, ICPPASTFunctionDeclarator functionDeclarator, NameInformation returnVariable, List<IASTNode> nodesToWrite, Collection<NameInformation> allUsedNames) {
|
||||
ICPPASTFunctionDeclarator declarator = new CPPASTFunctionDeclarator();
|
||||
declarator.setName(name);
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ public final class Messages extends NLS {
|
|||
public static String ExtractFunctionRefactoring_CreateMethodDef;
|
||||
public static String ExtractFunctionRefactoring_CreateFunctionDef;
|
||||
public static String ExtractFunctionComposite_ReplaceDuplicates;
|
||||
public static String ExtractFunctionComposite_Virtual;
|
||||
public static String ExtractFunctionRefactoring_CreateMethodCall;
|
||||
public static String ExtractFunctionRefactoring_CreateFunctionCall;
|
||||
public static String ChooserComposite_Return;
|
||||
|
|
|
@ -23,6 +23,7 @@ ExtractFunctionComposite_ReturnValue=Return value:
|
|||
ExtractFunctionRefactoring_CreateMethodDef=Create Method Definition
|
||||
ExtractFunctionRefactoring_CreateFunctionDef=Create Function Definition
|
||||
ExtractFunctionComposite_ReplaceDuplicates=Replace all occurrences of statements with method.
|
||||
ExtractFunctionComposite_Virtual=virtual
|
||||
ExtractFunctionRefactoring_CreateMethodCall=Create Method Call
|
||||
ExtractFunctionRefactoring_CreateFunctionCall=Create Function Call
|
||||
ChooserComposite_Return=Return
|
||||
|
|
Loading…
Add table
Reference in a new issue