extract method object: order moved methods by usages; write access (IDEA-78847)

This commit is contained in:
anna
2011-12-14 12:59:29 +01:00
parent fba470d64d
commit e8ccd03fa2
5 changed files with 129 additions and 8 deletions
@@ -98,6 +98,7 @@ public class ExtractMethodObjectHandler implements RefactoringActionHandler {
PsiDocumentManager.getInstance(project).commitAllDocuments();
if (processor.isCreateInnerClass()) {
processor.moveUsedMethodsToInner();
PsiDocumentManager.getInstance(project).commitAllDocuments();
DuplicatesImpl.processDuplicates(extractProcessor, project, editor);
}
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@@ -80,7 +80,7 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
private PsiMethod myInnerMethod;
private boolean myMadeStatic = false;
private final Set<MethodToMoveUsageInfo> myUsages = new HashSet<MethodToMoveUsageInfo>();
private final Set<MethodToMoveUsageInfo> myUsages = new LinkedHashSet<MethodToMoveUsageInfo>();
private PsiClass myInnerClass;
private ChangeSignatureProcessor myChangeSignatureProcessor;
private Runnable myCopyMethodToInner;
@@ -109,7 +109,7 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
}
}
if (isCreateInnerClass()) {
final Set<PsiMethod> usedMethods = new HashSet<PsiMethod>();
final Set<PsiMethod> usedMethods = new LinkedHashSet<PsiMethod>();
getMethod().accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
@@ -224,13 +224,16 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
};
dlg.show();
if (dlg.isOK()) {
for (MemberInfoBase<PsiMember> memberInfo : panel.getTable().getSelectedMemberInfos()) {
if (memberInfo.isChecked()) {
myInnerClass.add(memberInfo.getMember().copy());
memberInfo.getMember().delete();
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
for (MemberInfoBase<PsiMember> memberInfo : panel.getTable().getSelectedMemberInfos()) {
if (memberInfo.isChecked()) {
myInnerClass.add(memberInfo.getMember().copy());
memberInfo.getMember().delete();
}
}
}
}
});
}
}
}
@@ -0,0 +1,54 @@
import java.util.Date;
public class TestClass {
private Date expiry;
private Date maturity;
private int commitment;
private double outstanding;
private Iterable payments;
private Date today;
private Date start;
private int riskRating;
public double cal<caret>culate() {
return ( outstandingRiskAmount() * duration() * riskFactor() ) + ( unusedRiskAmount() * duration() * unusedRiskFactor() );
}
private double riskFactor() {
return 5.0;
}
private double unusedRiskFactor() {
return 6.0;
}
private double unusedRiskAmount() {
return ( commitment - outstanding );
}
private double outstandingRiskAmount() {
return outstanding;
}
private double getUsedPercentage() {
return 1.0;
}
private double duration() {
if ( expiry == null && maturity != null ) {
return 1.0;
} else if ( expiry != null && maturity == null ) {
return yearsTo( expiry );
}
return 0.0;
}
private double yearsTo( final Date endDate ) {
Date beginDate = ( today == null ? start : today );
return ( ( endDate.getTime() - beginDate.getTime() ));
}
}
@@ -0,0 +1,59 @@
import java.util.Date;
public class TestClass {
private Date expiry;
private Date maturity;
private int commitment;
private double outstanding;
private Iterable payments;
private Date today;
private Date start;
private int riskRating;
public double calculate() {
return new InnerClass().invoke();
}
private double getUsedPercentage() {
return 1.0;
}
private double yearsTo( final Date endDate ) {
Date beginDate = ( today == null ? start : today );
return ( ( endDate.getTime() - beginDate.getTime() ));
}
private class InnerClass {
public double invoke() {
return ( outstandingRiskAmount() * duration() * riskFactor() ) + ( unusedRiskAmount() * duration() * unusedRiskFactor() );
}
private double outstandingRiskAmount() {
return outstanding;
}
private double duration() {
if ( expiry == null && maturity != null ) {
return 1.0;
} else if ( expiry != null && maturity == null ) {
return yearsTo( expiry );
}
return 0.0;
}
private double riskFactor() {
return 5.0;
}
private double unusedRiskAmount() {
return ( commitment - outstanding );
}
private double unusedRiskFactor() {
return 6.0;
}
}
}
@@ -110,6 +110,10 @@ public class ExtractMethodObjectTest extends LightRefactoringTestCase {
public void testWithPrivateMethodUsed() throws Exception {
doTest();
}
public void testWithPrivateMethodUsed1() throws Exception {
doTest();
}
public void testWithPrivateMethodWhichCantBeMoved() throws Exception {
doTest();