Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 184912 Details for
Bug 331880
Refactoring [427]: IF Statement/Construct Refactoring - CQ Approved
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
If Statement/Construct Refactoring revision patch #1
patchIfRefactoring_v2 (text/plain), 64.57 KB, created by
Xi Chen
on 2010-12-09 18:18:40 EST
(
hide
)
Description:
If Statement/Construct Refactoring revision patch #1
Filename:
MIME Type:
Creator:
Xi Chen
Created:
2010-12-09 18:18:40 EST
Size:
64.57 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.photran.core.vpg >Index: src/org/eclipse/photran/internal/core/refactoring/IfConstructStatementConversionRefactoring.java >=================================================================== >RCS file: src/org/eclipse/photran/internal/core/refactoring/IfConstructStatementConversionRefactoring.java >diff -N src/org/eclipse/photran/internal/core/refactoring/IfConstructStatementConversionRefactoring.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/photran/internal/core/refactoring/IfConstructStatementConversionRefactoring.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,235 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Zeeshan Ansari, Mark Chen, Burim Isai, Waseem Sheikh, Mumtaz Vauhkonen. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Zeeshan Ansari >+ * Mark Chen >+ * Mumtaz Vauhkonen >+ * Burim Isai >+ * Waseem Sheikh >+ *******************************************************************************/ >+package org.eclipse.photran.internal.core.refactoring; >+ >+import java.util.ArrayList; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.OperationCanceledException; >+import org.eclipse.ltk.core.refactoring.RefactoringStatus; >+import org.eclipse.photran.internal.core.parser.ASTIfConstructNode; >+import org.eclipse.photran.internal.core.parser.ASTIfStmtNode; >+import org.eclipse.photran.internal.core.parser.ASTNode; >+import org.eclipse.photran.internal.core.refactoring.infrastructure.FortranEditorRefactoring; >+import org.eclipse.photran.internal.core.reindenter.Reindenter; >+import org.eclipse.photran.internal.core.reindenter.Reindenter.Strategy; >+ >+/** >+ * Converts an IF construct to an IF statement and vice versa. User must select the entire IF >+ * statement or IF construct block, and select the refactoring option in the menu. >+ * >+ * @author Zeeshan Ansari >+ * @author Mark Chen >+ * @author Mumtaz Vauhkonrn >+ * @author Burim Isai >+ * @author Waseem Sheikh >+ */ >+public class IfConstructStatementConversionRefactoring extends FortranEditorRefactoring >+{ >+ private ASTNode selectedNode = null; >+ private ASTNode ifStmtNode, ifConstructNode; >+ private boolean shouldAddEmptyElseBlock = false; >+ private ArrayList<String> commentList = new ArrayList<String>(); >+ >+ /** >+ * Beyond the standard condition checks, this checks to ensure that a valid IF statement or IF >+ * construct is selected and is refactorable. >+ * >+ * @param ifConstructNode >+ * @throws PreconditionFailure >+ */ >+ @Override >+ protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm) >+ throws PreconditionFailure >+ { >+ ensureProjectHasRefactoringEnabled(status); >+ >+ if (!fileInEditor.exists()) >+ fail(Messages.FortranEditorRefactoring_CantPerformRefactoringOnFileThatDoesNotExist); >+ >+ if (fileInEditor.isReadOnly()) >+ fail(Messages.FortranEditorRefactoring_CantPerformRefactoringOnReadOnlyFile); >+ >+ ifStmtNode = getNode(this.astOfFileInEditor, this.selectedRegionInEditor, >+ ASTIfStmtNode.class); >+ ifConstructNode = getNode(this.astOfFileInEditor, this.selectedRegionInEditor, >+ ASTIfConstructNode.class); >+ >+ if (ifStmtNode != null) >+ selectedNode = ifStmtNode; >+ else if (ifConstructNode != null) >+ { >+ checkRefactorableConstruct(ifConstructNode); >+ selectedNode = ifConstructNode; >+ } >+ else >+ fail(Messages.IfConstructStatementConversionRefactoring_SelectAValidIfStatement); >+ } >+ >+ /** >+ * Checks various conditions to see if the user-selected IF construct is refactorable to an IF >+ * statement. This includes making sure there is only one valid statement line in the construct >+ * and that the construct is not named. >+ * >+ * @param ifConstructNode >+ * @throws PreconditionFailure >+ */ >+ private void checkRefactorableConstruct(ASTNode ifConstructNode) throws PreconditionFailure >+ { >+ String constructParser = null; >+ int validStatements = 0; >+ >+ // Checks for named construct >+ if (!ifConstructNode.findFirstToken().getText().equals("if")) //$NON-NLS-1$ >+ fail(Messages.IfConstructStatementConversionRefactoring_InvalidNamedConstruct); >+ >+ // Check for multiple statements within construct and stores comment lines >+ constructParser = this.selectedRegionInEditor.getText(); >+ constructParser = constructParser.substring(constructParser.indexOf("\n") + 1).trim(); //$NON-NLS-1$ >+ >+ while (constructParser.contains("\n")) >+ { >+ //$NON-NLS-1$ >+ constructParser = constructParser.substring(constructParser.indexOf("\n") + 1).trim(); //$NON-NLS-1$ >+ if (!constructParser.startsWith("!") && !constructParser.startsWith("end if")) //$NON-NLS-1$ //$NON-NLS-2$ >+ ++validStatements; >+ >+ if (constructParser.startsWith("!")) //$NON-NLS-1$ >+ commentList.add(constructParser.substring(0, constructParser.indexOf("\n")).trim()); //$NON-NLS-1$ >+ } >+ >+ if (validStatements > 1) >+ fail(Messages.IfConstructStatementConversionRefactoring_TooManyStatements); >+ } >+ >+ public boolean isStmtNode() >+ { >+ return ifStmtNode != null; >+ } >+ >+ public void AddEmptyElseBlock() >+ { >+ shouldAddEmptyElseBlock = true; >+ } >+ >+ @Override >+ protected void doCheckFinalConditions(RefactoringStatus status, IProgressMonitor pm) >+ throws PreconditionFailure >+ { >+ // No final preconditions >+ } >+ >+ /** >+ * Determines whether an IF statement is selected or an IF construct is selected (done in >+ * pre-condition). Depending on which, it will execute the appropriate refactoring (statement to >+ * construct or vise versa). It will then reindent the entire section of refactored code based >+ * on the formating context of the code around it. >+ * >+ * @param pm >+ * @throws CoreException, OperationCanceledException >+ */ >+ @Override >+ protected void doCreateChange(IProgressMonitor pm) throws CoreException, >+ OperationCanceledException >+ { >+ if (selectedNode instanceof ASTIfStmtNode) >+ { >+ RefactorIfStmt(); >+ } >+ else if (selectedNode instanceof ASTIfConstructNode) >+ { >+ RefactorIfConstruct(); >+ } >+ else >+ throw new IllegalStateException(); >+ >+ Reindenter.reindent(selectedNode, this.astOfFileInEditor, Strategy.REINDENT_EACH_LINE); >+ this.addChangeFromModifiedAST(this.fileInEditor, pm); >+ vpg.releaseAST(this.fileInEditor); >+ >+ } >+ >+ protected void RefactorIfStmt() >+ { >+ ASTIfStmtNode ifStmtNode = (ASTIfStmtNode)selectedNode; >+ >+ ifStmtNode.replaceWith(createNewIfConstruct(ifStmtNode)); >+ } >+ >+ protected void RefactorIfConstruct() >+ { >+ ASTIfConstructNode ifConstructNode = (ASTIfConstructNode)selectedNode; >+ >+ ifConstructNode.replaceWith(createNewIfStmt(ifConstructNode)); >+ } >+ >+ /** >+ * Creates a new IF statement from the selected IF construct >+ * >+ * @param ifConstructNode >+ */ >+ private ASTIfStmtNode createNewIfStmt(ASTIfConstructNode ifConstructNode) >+ { >+ StringBuilder sb = new StringBuilder(); >+ >+ sb.append(" if ("); //$NON-NLS-1$ >+ sb.append(ifConstructNode.getIfThenStmt().getGuardingExpression().toString().trim()); >+ sb.append(") "); //$NON-NLS-1$ >+ sb.append(ifConstructNode.getConditionalBody().toString().trim()); >+ >+ for (String comment : commentList) >+ sb.append(" " + comment); //$NON-NLS-1$ >+ sb.append("\n"); //$NON-NLS-1$ >+ >+ ASTIfStmtNode newIfStmtNode = (ASTIfStmtNode)parseLiteralStatement(sb.toString()); >+ >+ return newIfStmtNode; >+ } >+ >+ /** >+ * Creates a new IF construct from the selected IF statement, with an option to add an empty >+ * ELSE construct >+ * >+ * @param ifConstructNode >+ */ >+ private ASTIfConstructNode createNewIfConstruct(ASTIfStmtNode ifStmtNode) >+ { >+ StringBuilder sb = new StringBuilder(); >+ >+ sb.append(" if ("); //$NON-NLS-1$ >+ sb.append(ifStmtNode.getGuardingExpression().toString()); >+ sb.append(") then"); //$NON-NLS-1$ >+ sb.append("\n "); //$NON-NLS-1$ >+ sb.append(ifStmtNode.getActionStmt().toString().trim()); >+ sb.append("\n !can add more statements here"); //$NON-NLS-1$ >+ if (shouldAddEmptyElseBlock) >+ { >+ sb.append("\n else"); //$NON-NLS-1$ >+ sb.append("\n !can add more statements here"); //$NON-NLS-1$ >+ } >+ sb.append("\n end if"); //$NON-NLS-1$ >+ >+ ASTIfConstructNode newIfConstructNode = (ASTIfConstructNode)parseLiteralStatement(sb >+ .toString()); >+ >+ return newIfConstructNode; >+ } >+ >+ @Override >+ public String getName() >+ { >+ return Messages.IfConstructStatementConversionRefactoring_Name; >+ } >+} >Index: src/org/eclipse/photran/internal/core/refactoring/Messages.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.ptp/photran/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/Messages.java,v >retrieving revision 1.15 >diff -u -r1.15 Messages.java >--- src/org/eclipse/photran/internal/core/refactoring/Messages.java 21 Sep 2010 18:32:41 -0000 1.15 >+++ src/org/eclipse/photran/internal/core/refactoring/Messages.java 9 Dec 2010 19:37:34 -0000 >@@ -267,6 +267,18 @@ > public static String ExtractLocalVariableRefactoring_VarsOnlyExtractedFromStmtsIn; > > public static String InterchangeLoopsRefactoring_Name; >+ >+ public static String IfConstructStatementConversionRefactoring_Name; >+ >+ public static String IfConstructStatementConversionRefactoring_SelectAValidIfStatement; >+ >+ public static String IfConstructStatementConversionRefactoring_InvalidNamedConstruct; >+ >+ public static String IfConstructStatementConversionRefactoring_TooManyStatements; >+ >+ public static String FortranEditorRefactoring_CantPerformRefactoringOnReadOnlyFile; >+ >+ public static String FortranEditorRefactoring_CantPerformRefactoringOnFileThatDoesNotExist; > > public static String InterchangeLoopsRefactoring_SelectTwoPerfNextedLoops; > >Index: src/org/eclipse/photran/internal/core/refactoring/messages.properties >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.ptp/photran/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/messages.properties,v >retrieving revision 1.13 >diff -u -r1.13 messages.properties >--- src/org/eclipse/photran/internal/core/refactoring/messages.properties 21 Sep 2010 15:31:10 -0000 1.13 >+++ src/org/eclipse/photran/internal/core/refactoring/messages.properties 9 Dec 2010 19:37:34 -0000 >@@ -200,3 +200,9 @@ > SafeDeleteInternalSubprogramRefactoring_SubroutineMustHaveOnlyInternalReferences=Subroutine must only have internal references. > StandardizeStatementsRefactoring_Name=Standardize Statements > StandardizeStatementsRefactoring_SelectedFileCannotBeParsed=One of the selected files ({0}) cannot be parsed. >+IfConstructStatementConversionRefactoring_Name= Convert Between IF Statement and IF Construct >+IfConstructStatementConversionRefactoring_SelectAValidIfStatement= Please select a valid IF statement or construct. >+IfConstructStatementConversionRefactoring_InvalidNamedConstruct= Cannot refactor a named IF construct. Please select an unnamed IF construct. >+IfConstructStatementConversionRefactoring_TooManyStatements= Selected IF construct contains too many statements and cannot be refactored to an IF statement. >+FortranEditorRefactoring_CantPerformRefactoringOnReadOnlyFile= Can't perform refactoring on a read-only file. >+FortranEditorRefactoring_CantPerformRefactoringOnFileThatDoesNotExist= Can't perform refactoring on a file that does not exist. >Index: src/org/eclipse/photran/internal/core/refactoring/infrastructure/FortranResourceRefactoring.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.ptp/photran/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/infrastructure/FortranResourceRefactoring.java,v >retrieving revision 1.11 >diff -u -r1.11 FortranResourceRefactoring.java >--- src/org/eclipse/photran/internal/core/refactoring/infrastructure/FortranResourceRefactoring.java 21 Sep 2010 15:08:23 -0000 1.11 >+++ src/org/eclipse/photran/internal/core/refactoring/infrastructure/FortranResourceRefactoring.java 9 Dec 2010 19:37:34 -0000 >@@ -43,6 +43,8 @@ > import org.eclipse.photran.internal.core.parser.ASTCallStmtNode; > import org.eclipse.photran.internal.core.parser.ASTContainsStmtNode; > import org.eclipse.photran.internal.core.parser.ASTFunctionSubprogramNode; >+import org.eclipse.photran.internal.core.parser.ASTIfConstructNode; >+import org.eclipse.photran.internal.core.parser.ASTIfStmtNode; > import org.eclipse.photran.internal.core.parser.ASTImplicitStmtNode; > import org.eclipse.photran.internal.core.parser.ASTMainProgramNode; > import org.eclipse.photran.internal.core.parser.ASTModuleNode; >@@ -281,6 +283,38 @@ > LoopReplacer.replaceAllLoopsIn(prog); > return (ASTProperLoopConstructNode)prog.getBody().get(0); > } >+ >+ /** >+ * Parses the given If-Construct as a {@link ASTIfConstructNode}. >+ * <p> >+ * @see parseLiteralStatement >+ * @param string >+ * @author Zeeshan Ansari >+ * @author Mark Chen >+ * @author Mumtaz Vauhkonen >+ */ >+// protected static ASTIfConstructNode parseLiteralIfConstructNode(String string) >+// { >+// string = "program p\n" + string + "\nend program"; //$NON-NLS-1$ //$NON-NLS-2$ >+// ASTMainProgramNode prog = (ASTMainProgramNode)parseLiteralProgramUnit(string); >+// return (ASTIfConstructNode)prog.getBody().get(0); >+// } >+ >+ /** >+ * Parses the given If-Statement as a {@link ASTIfStmtNode}. >+ * <p> >+ * @see parseLiteralStatement >+ * @param string >+ * @author Mark Chen >+ * @author Burim Isai >+ * @author Mumtaz Vauhkonen >+ */ >+// protected static ASTIfStmtNode parseLiteralIfStmtNode(String string) >+// { >+// string = "program p\n" + string + "\nend program"; //$NON-NLS-1$ //$NON-NLS-2$ >+// ASTMainProgramNode prog = (ASTMainProgramNode)parseLiteralProgramUnit(string); >+// return (ASTIfStmtNode)prog.getBody().get(0); >+// } > > /** @return a CONTAINS statement */ > protected static ASTContainsStmtNode createContainsStmt() >#P org.eclipse.photran.core.vpg.tests >Index: refactoring-test-code/if-construct-statement-conversion/test01-fail-notAValidIfStatement/convertIfStatementToIfConstruct_InvalidIfStatement.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test01-fail-notAValidIfStatement/convertIfStatementToIfConstruct_InvalidIfStatement.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test01-fail-notAValidIfStatement/convertIfStatementToIfConstruct_InvalidIfStatement.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test01-fail-notAValidIfStatement/convertIfStatementToIfConstruct_InvalidIfStatement.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,8 @@ >+program notAValidIf >+ implicit none >+ print *, "This is a test" >+ print *, 3+4*5+6 !<<<<< 4, 5, 4, 22, fail-initial >+ >+ !!! This test shows the refactoring failing the initial precondition because the selected text is a print statement, and >+ !!! not a valid IF statement or construct >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test02-convert_ifConstructToIfStmt/convert_ifConstruct.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test02-convert_ifConstructToIfStmt/convert_ifConstruct.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test02-convert_ifConstructToIfStmt/convert_ifConstruct.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test02-convert_ifConstructToIfStmt/convert_ifConstruct.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,10 @@ >+program convert_ifConstructToIfStmt >+ implicit none >+ print *, "This is a test" >+ if(.true.) then >+ a = 1 >+ end if >+ !<<<<< 4, 5, 6, 11, pass >+ >+ !!! This test shows the refactoring successfully refactoring a simple valid IF construct into a valid IF statement. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test02-convert_ifConstructToIfStmt/convert_ifConstruct.f90.result >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test02-convert_ifConstructToIfStmt/convert_ifConstruct.f90.result >diff -N refactoring-test-code/if-construct-statement-conversion/test02-convert_ifConstructToIfStmt/convert_ifConstruct.f90.result >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test02-convert_ifConstructToIfStmt/convert_ifConstruct.f90.result 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,8 @@ >+program convert_ifConstructToIfStmt >+ implicit none >+ print *, "This is a test" >+ if (.true.) a = 1 >+ !<<<<< 4, 5, 6, 11, pass >+ >+ !!! This test shows the refactoring successfully refactoring a simple valid IF construct into a valid IF statement. >+end program >Index: refactoring-test-code/if-construct-statement-conversion/test03-fail-ifNamedVariable/convert_ifStatement_ifNamedVariable.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test03-fail-ifNamedVariable/convert_ifStatement_ifNamedVariable.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test03-fail-ifNamedVariable/convert_ifStatement_ifNamedVariable.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test03-fail-ifNamedVariable/convert_ifStatement_ifNamedVariable.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,9 @@ >+program convert_ifStatementToIfConstruct_incorrectSelection >+ implicit none >+ print *, "This is a test" >+ integer :: if >+ if = 5 !<<<<< 5, 5, 5, 11, fail-initial >+ >+ !!! This test shows the refactoring failing the initial precondition because the selected text is not a valid >+ !!! IF statement or construct, even though the first token is "if" >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test04-complexboolean/ifStmtComplexBoolean_1.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test04-complexboolean/ifStmtComplexBoolean_1.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test04-complexboolean/ifStmtComplexBoolean_1.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test04-complexboolean/ifStmtComplexBoolean_1.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,9 @@ >+program ifStmtComplexBoolean_1 >+ implicit none >+ integer :: x, y, a >+ print *, "This is a test" >+ if (x .LT. y .OR. y .GT. 5 .AND. 6 .GE. 6) a = 1 !<<<<< 5, 5, 5, 53, pass >+ >+ !!! This tests shows the refactoring successfully converting a valid IF statement to a valid IF construct, even >+ !!! with a complex boolean guardian expression. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test04-complexboolean/ifStmtComplexBoolean_1.f90.result >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test04-complexboolean/ifStmtComplexBoolean_1.f90.result >diff -N refactoring-test-code/if-construct-statement-conversion/test04-complexboolean/ifStmtComplexBoolean_1.f90.result >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test04-complexboolean/ifStmtComplexBoolean_1.f90.result 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,12 @@ >+program ifStmtComplexBoolean_1 >+ implicit none >+ integer :: x, y, a >+ print *, "This is a test" >+ if (x .LT. y .OR. y .GT. 5 .AND. 6 .GE. 6) then >+ a = 1 !<<<<< 5, 5, 5, 53, pass >+ !can add more statements here >+ end if >+ >+ !!! This tests shows the refactoring successfully converting a valid IF statement to a valid IF construct, even >+ !!! with a complex boolean guardian expression. >+end program >Index: refactoring-test-code/if-construct-statement-conversion/test05-complexboolean/ifStmtComplexBoolean_2.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test05-complexboolean/ifStmtComplexBoolean_2.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test05-complexboolean/ifStmtComplexBoolean_2.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test05-complexboolean/ifStmtComplexBoolean_2.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,9 @@ >+program ifStmtComplexBoolean_2 >+ implicit none >+ integer :: x, y, z, a >+ print *, "This is a test" >+ if ((x*2+3)/z .GE. y) a = 1 !<<<<< 5, 5, 5, 32, pass >+ >+ !!! This tests shows the refactoring successfully converting a valid IF statement to a valid IF construct, even >+ !!! with a complex boolean guardian expression. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test05-complexboolean/ifStmtComplexBoolean_2.f90.result >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test05-complexboolean/ifStmtComplexBoolean_2.f90.result >diff -N refactoring-test-code/if-construct-statement-conversion/test05-complexboolean/ifStmtComplexBoolean_2.f90.result >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test05-complexboolean/ifStmtComplexBoolean_2.f90.result 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,12 @@ >+program ifStmtComplexBoolean_2 >+ implicit none >+ integer :: x, y, z, a >+ print *, "This is a test" >+ if ((x*2+3)/z .GE. y) then >+ a = 1 !<<<<< 5, 5, 5, 32, pass >+ !can add more statements here >+ end if >+ >+ !!! This tests shows the refactoring successfully converting a valid IF statement to a valid IF construct, even >+ !!! with a complex boolean guardian expression. >+end program >Index: refactoring-test-code/if-construct-statement-conversion/test06-convertifStmt/convertIfStatementToIfConstruct.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test06-convertifStmt/convertIfStatementToIfConstruct.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test06-convertifStmt/convertIfStatementToIfConstruct.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test06-convertifStmt/convertIfStatementToIfConstruct.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,10 @@ >+program convertIfStatementToIfConstruct >+ implicit none >+ integer :: var1, var2 >+ print *, "This is an if construct example." >+ var1 = 4 >+ var2 = 5 >+ if (var1 < var2) print *, var1, " is less than ", var2, " using if-stmt." !<<<<< 7, 5, 7, 78, pass >+ >+ !!! This tests shows the refactoring successfully converting a valid IF statement to a valid IF construct. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test06-convertifStmt/convertIfStatementToIfConstruct.f90.result >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test06-convertifStmt/convertIfStatementToIfConstruct.f90.result >diff -N refactoring-test-code/if-construct-statement-conversion/test06-convertifStmt/convertIfStatementToIfConstruct.f90.result >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test06-convertifStmt/convertIfStatementToIfConstruct.f90.result 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,13 @@ >+program convertIfStatementToIfConstruct >+ implicit none >+ integer :: var1, var2 >+ print *, "This is an if construct example." >+ var1 = 4 >+ var2 = 5 >+ if (var1 < var2) then >+ print *, var1, " is less than ", var2, " using if-stmt." !<<<<< 7, 5, 7, 78, pass >+ !can add more statements here >+ end if >+ >+ !!! This tests shows the refactoring successfully converting a valid IF statement to a valid IF construct. >+end program >Index: refactoring-test-code/if-construct-statement-conversion/test07-ifConstructToStmtBasic/ifConstructToStmtBasic_1.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test07-ifConstructToStmtBasic/ifConstructToStmtBasic_1.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test07-ifConstructToStmtBasic/ifConstructToStmtBasic_1.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test07-ifConstructToStmtBasic/ifConstructToStmtBasic_1.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,8 @@ >+program ifConstructToStmtBasic_1 >+ if (.true.) then >+ a = 2 >+ end if >+ !<<<<< 2, 5, 4, 11, pass >+ >+ !!! This tests shows the refactoring successfully converting a valid IF construct to a valid IF statement. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test07-ifConstructToStmtBasic/ifConstructToStmtBasic_1.f90.result >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test07-ifConstructToStmtBasic/ifConstructToStmtBasic_1.f90.result >diff -N refactoring-test-code/if-construct-statement-conversion/test07-ifConstructToStmtBasic/ifConstructToStmtBasic_1.f90.result >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test07-ifConstructToStmtBasic/ifConstructToStmtBasic_1.f90.result 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,6 @@ >+program ifConstructToStmtBasic_1 >+ if (.true.) a = 2 >+ !<<<<< 2, 5, 4, 11, pass >+ >+ !!! This tests shows the refactoring successfully converting a valid IF construct to a valid IF statement. >+end program >Index: refactoring-test-code/if-construct-statement-conversion/test08-nonIfToken/nonIfToken_fail.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test08-nonIfToken/nonIfToken_fail.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test08-nonIfToken/nonIfToken_fail.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test08-nonIfToken/nonIfToken_fail.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,14 @@ >+program nonIfToken_1 >+ integer :: i, j >+ integer :: k, z >+ do j = 1, 10 !<<<<< 4, 5, 10, 11, fail-initial >+ print *, i >+ if (i .gt. j) then >+ print *, i * 10 >+ end if >+ print *, i >+ end do >+ >+ !!! This tests shows the refactoring failing the initial precondition because the selected text is not a valid >+ !!! IF statement or construct, since the first token is "do" >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test09-ifConstructComplexBoolean/ifConstructComplexBoolean_1.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test09-ifConstructComplexBoolean/ifConstructComplexBoolean_1.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test09-ifConstructComplexBoolean/ifConstructComplexBoolean_1.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test09-ifConstructComplexBoolean/ifConstructComplexBoolean_1.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,12 @@ >+program ifConstructComplexBoolean_1 >+ implicit none >+ integer :: x, y, a >+ print *, "This is a test" >+ if (x .LT. y .OR. y .GT. 5 .AND. 6 .GE. 6) then >+ a = 1 >+ end if >+ !<<<<< 5, 5, 7, 11, pass >+ >+ !!! This tests shows the refactoring successfully converting a valid IF construct to a valid IF statement, even >+ !!! with a complex boolean guardian expression. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test09-ifConstructComplexBoolean/ifConstructComplexBoolean_1.f90.result >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test09-ifConstructComplexBoolean/ifConstructComplexBoolean_1.f90.result >diff -N refactoring-test-code/if-construct-statement-conversion/test09-ifConstructComplexBoolean/ifConstructComplexBoolean_1.f90.result >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test09-ifConstructComplexBoolean/ifConstructComplexBoolean_1.f90.result 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,10 @@ >+program ifConstructComplexBoolean_1 >+ implicit none >+ integer :: x, y, a >+ print *, "This is a test" >+ if (x .LT. y .OR. y .GT. 5 .AND. 6 .GE. 6) a = 1 >+ !<<<<< 5, 5, 7, 11, pass >+ >+ !!! This tests shows the refactoring successfully converting a valid IF construct to a valid IF statement, even >+ !!! with a complex boolean guardian expression. >+end program >Index: refactoring-test-code/if-construct-statement-conversion/test10-namedIfConstruct/namedIfConstruct_fail.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test10-namedIfConstruct/namedIfConstruct_fail.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test10-namedIfConstruct/namedIfConstruct_fail.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test10-namedIfConstruct/namedIfConstruct_fail.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,9 @@ >+program namedIfConstruct_fail >+ myifconstruct: if (.true.) then >+ a = 3 >+ end if myifconstruct >+ print *, "This test tries to convert a named if construct to if statement" !<<<<< 2, 5, 4, 11, fail-initial >+ >+ !!! This test shows the refactoring failing the initial precondition because while the selected text is a >+ !!! valid IF construct, it is a named IF construct, and therefore is not refactorable to an IF statement >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test11-multiLineIfConstructToIfStatement-failure/multiLineIfConstructToIfStmt.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test11-multiLineIfConstructToIfStatement-failure/multiLineIfConstructToIfStmt.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test11-multiLineIfConstructToIfStatement-failure/multiLineIfConstructToIfStmt.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test11-multiLineIfConstructToIfStatement-failure/multiLineIfConstructToIfStmt.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,12 @@ >+program convert_multiLineIfConstructToIfStatement >+ if (.true.) then >+ a = 2 >+ print *, 'hello' >+ print *, 'world' >+ end if >+ print *, 3+4*5+6 !<<<<< 2, 5, 6, 11, fail-initial >+ >+ !!! This test shows the refactoring failing the initial precondition because while the selected text is a valid >+ !!! IF construct, the body contains multiple lines of valid statements, and therefore, is not refactorable to >+ !!! an IF statement. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test12-generalIfConstToIfStmt-failure/generalIfConstToIfStmt.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test12-generalIfConstToIfStmt-failure/generalIfConstToIfStmt.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test12-generalIfConstToIfStmt-failure/generalIfConstToIfStmt.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test12-generalIfConstToIfStmt-failure/generalIfConstToIfStmt.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,13 @@ >+program convert_blockIfConstructToIfStatement >+ if (x .LT. 1) then >+ a = 2 >+ else if (x .GE. 1) then >+ a = 4 >+ else >+ a = 6 >+ end if !<<<<< 2, 5, 8, 11, fail-initial >+ >+ !!! This test shows the refactoring failing the initial precondition because while the selected text is a valid >+ !!! IF construct, the body contains multiple lines of valid statements, and therefore, is not refactorable to >+ !!! an IF statement. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test13-fail-multipleIfSelections1/multipleIfSelections1.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test13-fail-multipleIfSelections1/multipleIfSelections1.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test13-fail-multipleIfSelections1/multipleIfSelections1.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test13-fail-multipleIfSelections1/multipleIfSelections1.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,10 @@ >+program multipleIfSelections1 >+ if (x .LT. y .OR. y .GT. 5 .AND. 6 .GE. 6) a = 1 >+ if (.true.) then >+ a = 2 >+ end if >+ !<<<<< 2, 5, 5, 11, fail-initial >+ >+ !!! This test shows the refactoring failing the initial precondition because multiple IF statements and IF >+ !!! constructs are selected, while the refactoring can only handle one at a time. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test14-fail-multipleIfSelections2/multipleIfSelections2.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test14-fail-multipleIfSelections2/multipleIfSelections2.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test14-fail-multipleIfSelections2/multipleIfSelections2.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test14-fail-multipleIfSelections2/multipleIfSelections2.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,10 @@ >+program multipleIfSelections2 >+ if (.true.) then >+ a = 2 >+ end if >+ if (x .LT. y .OR. y .GT. 5 .AND. 6 .GE. 6) a = 1 >+ !<<<<< 2, 5, 5, 53, fail-initial >+ >+ !!! This test shows the refactoring failing the initial precondition because multiple IF statements and IF >+ !!! constructs are selected, while the refactoring can only handle one at a time. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test15-commentInIfConstructToIfStmt/commentIfConstructToIfStmt.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test15-commentInIfConstructToIfStmt/commentIfConstructToIfStmt.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test15-commentInIfConstructToIfStmt/commentIfConstructToIfStmt.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test15-commentInIfConstructToIfStmt/commentIfConstructToIfStmt.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,11 @@ >+program commentIfConstructToIfStmt >+ implicit none >+ integer :: x, y, a >+ if (x .LT. y .OR. y .GT. 5 .AND. 6 .GE. 6) then >+ a = 1 !This is an if statement >+ end if >+ print *, "This is a test" !<<<<< 4, 5, 6, 11, pass >+ >+ !!! This test shows the refactoring successfully converting a valid IF construct to a valid IF statement, while >+ !!! also preserving the included comment. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test15-commentInIfConstructToIfStmt/commentIfConstructToIfStmt.f90.result >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test15-commentInIfConstructToIfStmt/commentIfConstructToIfStmt.f90.result >diff -N refactoring-test-code/if-construct-statement-conversion/test15-commentInIfConstructToIfStmt/commentIfConstructToIfStmt.f90.result >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test15-commentInIfConstructToIfStmt/commentIfConstructToIfStmt.f90.result 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,9 @@ >+program commentIfConstructToIfStmt >+ implicit none >+ integer :: x, y, a >+ if (x .LT. y .OR. y .GT. 5 .AND. 6 .GE. 6) a = 1 !This is an if statement >+ print *, "This is a test" !<<<<< 4, 5, 6, 11, pass >+ >+ !!! This test shows the refactoring successfully converting a valid IF construct to a valid IF statement, while >+ !!! also preserving the included comment. >+end program >Index: refactoring-test-code/if-construct-statement-conversion/test16-commentInIfStmtToIfConstruct/commentInIfStmtToIfConst.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test16-commentInIfStmtToIfConstruct/commentInIfStmtToIfConst.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test16-commentInIfStmtToIfConstruct/commentInIfStmtToIfConst.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test16-commentInIfStmtToIfConstruct/commentInIfStmtToIfConst.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,9 @@ >+program commentIfStmtToIfConstruct >+ implicit none >+ integer :: x, y, a >+ if (x .LT. y .OR. y .GT. 5 .AND. 6 .GE. 6) a = 1 !This is an if statement >+ print *, "This is a test" !<<<<< 4, 5, 4, 78, pass >+ >+ !!! This test shows the refactoring successfully converting a valid IF statement to a valid IF construct, while >+ !!! also preserving the included comment. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test16-commentInIfStmtToIfConstruct/commentInIfStmtToIfConst.f90.result >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test16-commentInIfStmtToIfConstruct/commentInIfStmtToIfConst.f90.result >diff -N refactoring-test-code/if-construct-statement-conversion/test16-commentInIfStmtToIfConstruct/commentInIfStmtToIfConst.f90.result >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test16-commentInIfStmtToIfConstruct/commentInIfStmtToIfConst.f90.result 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,12 @@ >+program commentIfStmtToIfConstruct >+ implicit none >+ integer :: x, y, a >+ if (x .LT. y .OR. y .GT. 5 .AND. 6 .GE. 6) then >+ a = 1 !This is an if statement >+ !can add more statements here >+ end if >+ print *, "This is a test" !<<<<< 4, 5, 4, 78, pass >+ >+ !!! This test shows the refactoring successfully converting a valid IF statement to a valid IF construct, while >+ !!! also preserving the included comment. >+end program >Index: refactoring-test-code/if-construct-statement-conversion/test17-reindentIfConstruct/reindentIfConstruct.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test17-reindentIfConstruct/reindentIfConstruct.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test17-reindentIfConstruct/reindentIfConstruct.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test17-reindentIfConstruct/reindentIfConstruct.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,9 @@ >+program reindentIfConstruct >+ if (1 .GE. 1) then >+ a = 1 >+ end if >+ !<<<<< 2, 38, 4, 44, pass >+ >+ !!! This test shows the refactoring successfully converting a valid IF construct to a valid IF statement, and >+ !!! then reindenting the section of code to the correct location, based on code context. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test17-reindentIfConstruct/reindentIfConstruct.f90.result >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test17-reindentIfConstruct/reindentIfConstruct.f90.result >diff -N refactoring-test-code/if-construct-statement-conversion/test17-reindentIfConstruct/reindentIfConstruct.f90.result >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test17-reindentIfConstruct/reindentIfConstruct.f90.result 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,7 @@ >+program reindentIfConstruct >+ if (1 .GE. 1) a = 1 >+ !<<<<< 2, 38, 4, 44, pass >+ >+ !!! This test shows the refactoring successfully converting a valid IF construct to a valid IF statement, and >+ !!! then reindenting the section of code to the correct location, based on code context. >+end program >Index: refactoring-test-code/if-construct-statement-conversion/test18-commentHandling/commentHandling.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test18-commentHandling/commentHandling.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test18-commentHandling/commentHandling.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test18-commentHandling/commentHandling.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,15 @@ >+program commentHandling >+ implicit none >+ integer :: x, y, a >+ if (x .LT. y .OR. y .GT. 5 .AND. 6 .GE. 6) then >+ a = 1 !This is an if statement >+ !can add more statements here >+ !more comments here >+ end if >+ print *, "This is a test" !<<<<< 4, 5, 8, 11, pass >+ >+ !!! This test shows the refactoring successfully converting a valid IF construct to a valid IF statement. Even though the IF >+ !!! construct has multiple lines of code, only one of which is a valid statement, so it is therefore still refactorable. The >+ !!! refactoring will then take the lines of comments and append them to the end of the IF statement in order to preserve them. >+ !!! The user can then reformat the comments as they feel fit. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test18-commentHandling/commentHandling.f90.result >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test18-commentHandling/commentHandling.f90.result >diff -N refactoring-test-code/if-construct-statement-conversion/test18-commentHandling/commentHandling.f90.result >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test18-commentHandling/commentHandling.f90.result 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,11 @@ >+program commentHandling >+ implicit none >+ integer :: x, y, a >+ if (x .LT. y .OR. y .GT. 5 .AND. 6 .GE. 6) a = 1 !This is an if statement !can add more statements here !more comments here >+ print *, "This is a test" !<<<<< 4, 5, 8, 11, pass >+ >+ !!! This test shows the refactoring successfully converting a valid IF construct to a valid IF statement. Even though the IF >+ !!! construct has multiple lines of code, only one of which is a valid statement, so it is therefore still refactorable. The >+ !!! refactoring will then take the lines of comments and append them to the end of the IF statement in order to preserve them. >+ !!! The user can then reformat the comments as they feel fit. >+end program >Index: refactoring-test-code/if-construct-statement-conversion/test19-optionalElse/optionalElse.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test19-optionalElse/optionalElse.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test19-optionalElse/optionalElse.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test19-optionalElse/optionalElse.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,11 @@ >+program convertIfStatementToIfConstructWithOptionalElseBlock >+ implicit none >+ integer :: var1, var2 >+ print *, "This is an if construct example." >+ var1 = 4 >+ var2 = 5 >+ if (var1 < var2) print *, var1, " is less than ", var2, " using if-stmt." !<<<<< 7, 5, 7, 78, IfStmtToIfConstruct, TRUE, pass >+ >+ !!! This test shows the refactoring successfully converting a valid IF statement to a valid IF construct, and then based >+ !!! on the user's affirmative selection of the option, will add on an else construct block to the end of it. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test19-optionalElse/optionalElse.f90.result >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test19-optionalElse/optionalElse.f90.result >diff -N refactoring-test-code/if-construct-statement-conversion/test19-optionalElse/optionalElse.f90.result >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test19-optionalElse/optionalElse.f90.result 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,16 @@ >+program convertIfStatementToIfConstructWithOptionalElseBlock >+ implicit none >+ integer :: var1, var2 >+ print *, "This is an if construct example." >+ var1 = 4 >+ var2 = 5 >+ if (var1 < var2) then >+ print *, var1, " is less than ", var2, " using if-stmt." !<<<<< 7, 5, 7, 78, IfStmtToIfConstruct, TRUE, pass >+ !can add more statements here >+ else >+ !can add more statements here >+ end if >+ >+ !!! This test shows the refactoring successfully converting a valid IF statement to a valid IF construct, and then based >+ !!! on the user's affirmative selection of the option, will add on an else construct block to the end of it. >+end program >Index: refactoring-test-code/if-construct-statement-conversion/test20-optionalElseNotAdded/optionalElseNotAdded.f90 >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test20-optionalElseNotAdded/optionalElseNotAdded.f90 >diff -N refactoring-test-code/if-construct-statement-conversion/test20-optionalElseNotAdded/optionalElseNotAdded.f90 >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test20-optionalElseNotAdded/optionalElseNotAdded.f90 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,11 @@ >+program convertIfStatementToIfConstructWithOutOptionalElseBlock >+ implicit none >+ integer :: var1, var2 >+ print *, "This is an if construct example." >+ var1 = 4 >+ var2 = 5 >+ if (var1 < var2) print *, var1, " is less than ", var2, " using if-stmt." !<<<<< 7, 5, 7, 78, IfStmtToIfConstruct, FALSE, pass >+ >+ !!! This test shows the refactoring successfully converting a valid IF statement to a valid IF construct, and then based >+ !!! on the user's negative selection of the option, will now add on an else construct block to the end of it. >+end program >\ No newline at end of file >Index: refactoring-test-code/if-construct-statement-conversion/test20-optionalElseNotAdded/optionalElseNotAdded.f90.result >=================================================================== >RCS file: refactoring-test-code/if-construct-statement-conversion/test20-optionalElseNotAdded/optionalElseNotAdded.f90.result >diff -N refactoring-test-code/if-construct-statement-conversion/test20-optionalElseNotAdded/optionalElseNotAdded.f90.result >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ refactoring-test-code/if-construct-statement-conversion/test20-optionalElseNotAdded/optionalElseNotAdded.f90.result 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,14 @@ >+program convertIfStatementToIfConstructWithOutOptionalElseBlock >+ implicit none >+ integer :: var1, var2 >+ print *, "This is an if construct example." >+ var1 = 4 >+ var2 = 5 >+ if (var1 < var2) then >+ print *, var1, " is less than ", var2, " using if-stmt." !<<<<< 7, 5, 7, 78, IfStmtToIfConstruct, FALSE, pass >+ !can add more statements here >+ end if >+ >+ !!! This test shows the refactoring successfully converting a valid IF statement to a valid IF construct, and then based >+ !!! on the user's negative selection of the option, will now add on an else construct block to the end of it. >+end program >Index: src/org/eclipse/photran/internal/tests/refactoring/IfConstructStatementConversionRefactoringTestSuite.java >=================================================================== >RCS file: src/org/eclipse/photran/internal/tests/refactoring/IfConstructStatementConversionRefactoringTestSuite.java >diff -N src/org/eclipse/photran/internal/tests/refactoring/IfConstructStatementConversionRefactoringTestSuite.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/photran/internal/tests/refactoring/IfConstructStatementConversionRefactoringTestSuite.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,70 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Zeeshan Ansari, Mark Chen, Burim Isai, Waseem Sheikh, Mumtaz Vauhkonen. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Zeeshan Ansari >+ * Mark Chen >+ * Burim Isai >+ * Waseem Sheihk >+ * Mumtaz Vauhkonen >+ *******************************************************************************/ >+package org.eclipse.photran.internal.tests.refactoring; >+ >+import junit.framework.Test; >+import junit.framework.TestFailure; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.jface.text.TextSelection; >+import org.eclipse.photran.internal.core.refactoring.ExtractLocalVariableRefactoring; >+import org.eclipse.photran.internal.core.refactoring.IfConstructStatementConversionRefactoring; >+import org.eclipse.photran.internal.tests.Activator; >+import org.eclipse.photran.internal.tests.PhotranRefactoringTestSuiteFromMarkers; >+ >+/** >+ * Unit tests for the IF Statement/Construct refactoring. >+ * >+ * @author Zeeshan Ansari >+ * @author Mark Chen >+ * @author Mumtaz Vauhkonrn >+ * @author Burim Isai >+ * @author Waseem Sheikh >+ */ >+public class IfConstructStatementConversionRefactoringTestSuite extends >+ PhotranRefactoringTestSuiteFromMarkers<IfConstructStatementConversionRefactoring> >+{ >+ private static final String DIR = "refactoring-test-code/if-construct-statement-conversion"; >+ >+ public static Test suite() throws Exception >+ { >+ return new IfConstructStatementConversionRefactoringTestSuite(); >+ } >+ >+ public IfConstructStatementConversionRefactoringTestSuite() throws Exception >+ { >+ super(Activator.getDefault(), "Running If Construct Statement Conversion refactoring in", >+ DIR, IfConstructStatementConversionRefactoring.class); >+ } >+ >+ @Override >+ protected boolean configureRefactoring(IfConstructStatementConversionRefactoring refactoring, >+ IFile file, TextSelection selection, String[] markerText) >+ { >+ boolean shouldSucceed = super >+ .configureRefactoring(refactoring, file, selection, markerText); >+ String includeOptionalElse; >+ String testType; >+ testType = markerText[4]; >+ >+ if (testType.equals("IfStmtToIfConstruct")) >+ { >+ includeOptionalElse = markerText[5]; >+ if (includeOptionalElse.equals("TRUE")) refactoring.AddEmptyElseBlock(); >+ } >+ >+ return shouldSucceed; >+ } >+} >#P org.eclipse.photran.ui.vpg >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.ptp/photran/org.eclipse.photran.ui.vpg/plugin.xml,v >retrieving revision 1.78 >diff -u -r1.78 plugin.xml >--- plugin.xml 16 Nov 2010 18:07:25 -0000 1.78 >+++ plugin.xml 9 Dec 2010 19:37:35 -0000 >@@ -102,6 +102,7 @@ > /> > </group> > <group><!-- Refactorings that reformat code --> >+ <editorRefactoring command="org.eclipse.photran.ui.IfConstructStatementConversionRefactoringCommand" /> > <editorRefactoring > class="org.eclipse.photran.internal.core.refactoring.RemoveUnreferencedLabelsRefactoring" > /> >@@ -151,6 +152,11 @@ > categoryId="org.eclipse.photran.ui.RefactoringCategory" > id="org.eclipse.photran.ui.ExtractLocalVariableRefactoringCommand"> > </command> >+ <command >+ name="%command.name.IfConstructStatementConversion" >+ categoryId="org.eclipse.photran.ui.RefactoringCategory" >+ id="org.eclipse.photran.ui.IfConstructStatementConversionRefactoringCommand"> >+ </command> > </extension> > > <!-- 2. Optionally associate the command with an accelerator key --> >@@ -174,6 +180,12 @@ > contextId="org.eclipse.photran.ui.FortranEditorContext" > commandId="org.eclipse.photran.ui.ExtractLocalVariableRefactoringCommand" > /> >+ <key >+ sequence="M3+M2+I" >+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" >+ contextId="org.eclipse.photran.ui.FortranEditorContext" >+ commandId="org.eclipse.photran.ui.IfConstructStatementConversionRefactoringCommand" >+ /> > </extension> > > <!-- 3. Add the command to Photran's Refactoring action set --> >@@ -199,6 +211,11 @@ > definitionId="org.eclipse.photran.ui.ExtractLocalVariableRefactoringCommand" > class="org.eclipse.photran.internal.ui.refactoring.ExtractLocalVariableAction" > id="org.eclipse.photran.ui.ExtractLocalVariableRefactoringAction"/> >+ <action >+ label="%action.label.IfConstructStatementConversion" >+ definitionId="org.eclipse.photran.ui.IfConstructStatementConversionRefactoringCommand" >+ class="org.eclipse.photran.internal.ui.refactoring.IfConstructStatementConversionAction" >+ id="org.eclipse.photran.ui.IfConstructStatementConversionRefactoringAction"/> > </actionSet> > </extension> > >@@ -353,7 +370,7 @@ > id="org.eclipse.photran.ui.Reindenter"> > <action > label="%action.label.reindent.0" >- menubarPath="org.eclipse.photran.ui.source.menu/indentationActions" >+ menubarPath="edit/additions" > definitionId="org.eclipse.photran.ui.ReindenterCommand" > class="org.eclipse.photran.internal.ui.actions.ReindentAction" > id="org.eclipse.photran.ui.ReindenterAction"> >Index: src/org/eclipse/photran/internal/ui/refactoring/IfConstructStatementConversionAction.java >=================================================================== >RCS file: src/org/eclipse/photran/internal/ui/refactoring/IfConstructStatementConversionAction.java >diff -N src/org/eclipse/photran/internal/ui/refactoring/IfConstructStatementConversionAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/photran/internal/ui/refactoring/IfConstructStatementConversionAction.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,137 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Zeeshan Ansari, Mark Chen, Burim Isai, Waseem Sheikh, Mumtaz Vauhkonen. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Zeeshan Ansari >+ * Mark Chen >+ * Burim Isai >+ * Waseem Sheihk >+ * Mumtaz Vauhkonen >+ *******************************************************************************/ >+package org.eclipse.photran.internal.ui.refactoring; >+ >+import java.util.List; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; >+import org.eclipse.photran.core.IFortranAST; >+import org.eclipse.photran.internal.core.lexer.Token; >+import org.eclipse.photran.internal.core.refactoring.IfConstructStatementConversionRefactoring; >+import org.eclipse.photran.internal.core.vpg.PhotranVPG; >+import org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.ui.IEditorActionDelegate; >+import org.eclipse.ui.IWorkbenchWindowActionDelegate; >+ >+/** >+ * Handles the If Statement/Construct action in the Fortran editor's Refactoring popup menu and in >+ * the Refactor menu in the workbench menu bar. >+ * >+ * @author Zeeshan Ansari >+ * @author Mark Chen >+ * @author Mumtaz Vauhkonrn >+ * @author Burim Isai >+ * @author Waseem Sheikh >+ */ >+public class IfConstructStatementConversionAction extends AbstractFortranRefactoringActionDelegate >+ implements IWorkbenchWindowActionDelegate, IEditorActionDelegate >+{ >+ public IfConstructStatementConversionAction() >+ { >+ super(IfConstructStatementConversionRefactoring.class, >+ FortranIfConstructStatementConversionWizard.class); >+ } >+ >+ @Override >+ protected VPGRefactoring<IFortranAST, Token, PhotranVPG> getRefactoring(List<IFile> files) >+ { >+ IfConstructStatementConversionRefactoring r = new IfConstructStatementConversionRefactoring(); >+ r.initialize(getFortranEditor().getIFile(), getFortranEditor().getSelection()); >+ return r; >+ } >+ >+ public static class FortranIfConstructStatementConversionWizard extends >+ AbstractFortranRefactoringWizard >+ { >+ protected IfConstructStatementConversionRefactoring ifConstructStatementConversionRefactoring; >+ >+ public FortranIfConstructStatementConversionWizard( >+ IfConstructStatementConversionRefactoring r) >+ { >+ super(r); >+ this.ifConstructStatementConversionRefactoring = r; >+ } >+ >+ @Override >+ protected void doAddUserInputPages() >+ { >+ if (ifConstructStatementConversionRefactoring.isStmtNode()) >+ { >+ addPage(new UserInputWizardPage(ifConstructStatementConversionRefactoring.getName()) >+ { >+ protected Button shouldAddEmptyElseBlock; >+ >+ public void createControl(Composite parent) >+ { >+ Composite top = new Composite(parent, SWT.NONE); >+ initializeDialogUnits(top); >+ setControl(top); >+ top.setLayout(new GridLayout(2, false)); >+ Composite group = top; >+ new Label(group, SWT.NONE).setText(""); //$NON-NLS-1$ >+ >+ shouldAddEmptyElseBlock = new Button(group, SWT.CHECK); >+ shouldAddEmptyElseBlock >+ .setText(Messages.IfConstructStatementConversionAction_AddEmptyElseBlock); >+ shouldAddEmptyElseBlock.setSelection(false); >+ shouldAddEmptyElseBlock.addSelectionListener(new SelectionListener() >+ { >+ public void widgetDefaultSelected(SelectionEvent e) >+ { >+ widgetSelected(e); >+ } >+ >+ public void widgetSelected(SelectionEvent e) >+ { >+ if (shouldAddEmptyElseBlock.getSelection()) >+ ifConstructStatementConversionRefactoring.AddEmptyElseBlock(); >+ } >+ >+ }); >+ } >+ }); >+ } >+ else >+ { >+ addPage(new UserInputWizardPage(ifConstructStatementConversionRefactoring.getName()) >+ { >+ public void createControl(Composite parent) >+ { >+ Composite top = new Composite(parent, SWT.NONE); >+ initializeDialogUnits(top); >+ setControl(top); >+ >+ top.setLayout(new GridLayout(1, false)); >+ >+ Label lbl = new Label(top, SWT.NONE); >+ lbl.setText(Messages.bind( >+ Messages.RefactoringAction_ClickOKToRunTheRefactoring, >+ ifConstructStatementConversionRefactoring.getName())); >+ } >+ >+ }); >+ } >+ >+ } >+ } >+} >Index: src/org/eclipse/photran/internal/ui/refactoring/Messages.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.ptp/photran/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/Messages.java,v >retrieving revision 1.3 >diff -u -r1.3 Messages.java >--- src/org/eclipse/photran/internal/ui/refactoring/Messages.java 21 Sep 2010 13:26:16 -0000 1.3 >+++ src/org/eclipse/photran/internal/ui/refactoring/Messages.java 9 Dec 2010 19:37:35 -0000 >@@ -82,6 +82,10 @@ > public static String MoveFromModuleInputPage_selectDataMessage; > > public static String RenameAction_MatchExternalSubprograms; >+ >+ public static String IfConstructStatementConversionAction_AddEmptyElseBlock; >+ >+ public static String RefactoringAction_ClickOKToRunTheRefactoring; > > public static String RenameAction_RenameAtoB; > static >Index: src/org/eclipse/photran/internal/ui/refactoring/messages.properties >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.ptp/photran/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/messages.properties,v >retrieving revision 1.2 >diff -u -r1.2 messages.properties >--- src/org/eclipse/photran/internal/ui/refactoring/messages.properties 21 Sep 2010 13:26:16 -0000 1.2 >+++ src/org/eclipse/photran/internal/ui/refactoring/messages.properties 9 Dec 2010 19:37:35 -0000 >@@ -31,3 +31,5 @@ > MoveFromModuleInputPage_selectDataMessage=Please select member data to move from module > RenameAction_MatchExternalSubprograms=Match external subprograms with interfaces and external declarations > RenameAction_RenameAtoB=Rename {0} to >+IfConstructStatementConversionAction_AddEmptyElseBlock=Add an empty else block >+RefactoringAction_ClickOKToRunTheRefactoring=Click OK to run the {0} refactoring.\nTo see what changes will be made, click Preview.
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
com-eclipse-dot-org
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 331880
:
184567
| 184912