### Eclipse Workspace Patch 1.0 #P org.eclipse.photran.core.vpg 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 14 Dec 2010 04:49:33 -0000 @@ -7,6 +7,11 @@ * * Contributors: * UIUC - Initial API and implementation + * Rita Chow - Photran Modifications + * Nicola Hall - Photran Modifications + * Jerry Hsiao - Photran Modifications + * Mark Mozolewski - Photran Modifications + * Chamil Wijenayaka - Photran Modifications *******************************************************************************/ package org.eclipse.photran.internal.core.refactoring; @@ -356,9 +361,37 @@ public static String RemoveArithmeticIfRefactoring_Name; + public static String RemoveBranchToEndIfRefactoring_Name; + + public static String RemoveBranchToEndIfRefactoring_MissingGoToStatement; + + public static String RemoveBranchToEndIfRefactoring_GoToLabelDoesNotMatchAnyEndIfLabel; + + public static String RemoveBranchToEndIfRefactoring_BranchToImmediateEndIf; + + public static String RemoveBranchToEndIfRefactoring_SelectEndIfStatementToRefactor; + + public static String RemoveBranchToEndIfRefactoring_CanNotFindIfConstruct; + + public static String RemoveBranchToEndIfRefactoring_CanNotFindGoToStatementForThisLabel; + public static String RemoveComputedGoToRefactoring_Name; public static String RemoveComputedGoToRefactoring_PleaseSelectComputedGotoStmt; + + public static String RemovePauseStmtRefactoring_Name; + + public static String RemovePauseStmtRefactoring_SelectPauseStmt; + + public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_Name; + + public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_PleaseSelectADoLoop; + + public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_PleaseSelectAControlledDoLoop; + + public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_LoopControlVariableMissingDeclaration; + + public static String RemoveRealAndDoublePrecisionLoopCountersRefactoring_LoopControlVariableNotRealOrDouble; public static String RemoveUnusedVariablesRefactoring_CouldNotCompleteOperation; Index: src/org/eclipse/photran/internal/core/refactoring/RemoveBranchToEndIfRefactoring.java =================================================================== RCS file: src/org/eclipse/photran/internal/core/refactoring/RemoveBranchToEndIfRefactoring.java diff -N src/org/eclipse/photran/internal/core/refactoring/RemoveBranchToEndIfRefactoring.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/photran/internal/core/refactoring/RemoveBranchToEndIfRefactoring.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,564 @@ +/******************************************************************************* + * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka + * 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: + * Rita Chow - Initial Implementation + * Nicola Hall - Initial Implementation + * Jerry Hsiao - Initial Implementation + * Mark Mozolewski - Initial Implementation + * Chamil Wijenayaka - Initial Implementation + *******************************************************************************/ +package org.eclipse.photran.internal.core.refactoring; + +import java.util.LinkedList; +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.analysis.binding.ScopingNode; +import org.eclipse.photran.internal.core.analysis.loops.ASTProperLoopConstructNode; +import org.eclipse.photran.internal.core.analysis.loops.ASTVisitorWithLoops; +import org.eclipse.photran.internal.core.analysis.loops.LoopReplacer; +import org.eclipse.photran.internal.core.parser.*; +import org.eclipse.photran.internal.core.refactoring.infrastructure.FortranEditorRefactoring; + +/** + * Remove branching to END IF statement from outside its IF ... END IF block. Such branching should + * be replaced with branching to CONTINUE statement that immediately follows the END IF statement. + * If the END IF statement is followed by a CONTINUE statement then outside GOTO branches should + * target the CONTINUE statement. If one does not exist the refactoring will insert one and target + * it. GOTOs inside the selected IF block are not re-targeted. + * + * User Selection Requirements: The labeled END IF that they want considered for the refactoring. + * + * @author Rita Chow (chow15), Jerry Hsiao (jhsiao2), Mark Mozolewski (mozolews), Chamil Wijenayaka + * (wijenay2), Nicola Hall (nfhall2) + */ +public class RemoveBranchToEndIfRefactoring extends FortranEditorRefactoring +{ + private IASTNode selectedNode; + + private ASTEndIfStmtNode selectedEndIfNode; + + private ASTIfConstructNode selectedIfConstructNode; + + private LinkedList gotoStatements; + + private LinkedList selectedGotoStatements; + + private ASTContinueStmtNode continueAfterIfStmtNode; + + private LinkedList selectedGotoStatementWithEndIfLabel; + + private LinkedList gotoStatementWithEndIfLabel; + + /** + * Provide GUI refactoring label. + */ + @Override + public String getName() + { + return Messages.RemoveBranchToEndIfRefactoring_Name; + } + + /** + * Preconditions that are checked before the refactoring is applied are: 1) END IF selected must + * be labeled and part of an IF block. 2) GOTO from either inside the selected IF block or + * outside the selected IF block must target the label of the END IF selected. 3) must be more + * GOTOs than just in local selected END IF scope. + * + */ + @Override + protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm) + throws PreconditionFailure + { + ensureProjectHasRefactoringEnabled(status); + + // Check if selected text is a portion within an END IF statement with label. + setSelectedNodeAndEndIfNode(); + if ((selectedEndIfNode == null) || (selectedEndIfNode.getLabel() == null)) + { + System.out + .println(Messages.RemoveBranchToEndIfRefactoring_SelectEndIfStatementToRefactor); + fail(Messages.RemoveBranchToEndIfRefactoring_SelectEndIfStatementToRefactor); + } + + // Check if selected END IF is within an IF block. + setSelectedIfConstructNode(); + if (selectedIfConstructNode == null) + { + System.out.println(Messages.RemoveBranchToEndIfRefactoring_CanNotFindIfConstruct); + fail(Messages.RemoveBranchToEndIfRefactoring_CanNotFindIfConstruct); + } + + // Check if selected scope contains a branch. + setGotoStatements(); + if (gotoStatements.isEmpty()) + { + System.out.println(Messages.RemoveBranchToEndIfRefactoring_MissingGoToStatement); + fail(Messages.RemoveBranchToEndIfRefactoring_MissingGoToStatement); + } + + // Check if contains a GOTO statement with selected END IF label. + setGotoStatementsWithEndIfLabel(); + if (gotoStatementWithEndIfLabel.size() == 0) + { + System.out + .println(Messages.RemoveBranchToEndIfRefactoring_CanNotFindGoToStatementForThisLabel); + fail(Messages.RemoveBranchToEndIfRefactoring_CanNotFindGoToStatementForThisLabel); + } + + // Check to see if there are branches outside of selected if block to selected END IF label. + setSelectedGotoStatementsWithEndIfLabel(); + if (selectedGotoStatementWithEndIfLabel.size() == gotoStatementWithEndIfLabel.size()) + { + System.out.println(Messages.RemoveBranchToEndIfRefactoring_BranchToImmediateEndIf); + fail(Messages.RemoveBranchToEndIfRefactoring_BranchToImmediateEndIf); + } + + setContinueAfterIfStmtNode(); + } + + /** + * There are no final conditions. + */ + @Override + protected void doCheckFinalConditions(RefactoringStatus status, IProgressMonitor pm) + throws PreconditionFailure + { + // No final conditions + } + + /** + * Separate refactroing methods based on if there is a CONTINUE statement after the selected END + * IF (if so target it) or if no CONTINUE statement exists after the END IF block (insert one + * with unique label and have GOTO statements outside the IF block target it.). + */ + @Override + protected void doCreateChange(IProgressMonitor pm) throws CoreException, + OperationCanceledException + { + setAstAndNodes(); + + if (continueAfterIfStmtNode == null) + { + changeNoContinueAfterEndIf(); // User Story #2 + + } + else + { + changeGotoLabelToContinueLabel(); // User Story #1 + } + + // User Story 3 checked in doCheckInitialConditions + + this.addChangeFromModifiedAST(this.fileInEditor, pm); + vpg.releaseAST(this.fileInEditor); + } + + /** + * Sets AST of selected file and nodes used for refactoring. + * + * @param None. + * + * @return None. + */ + private void setAstAndNodes() + { + this.astOfFileInEditor = vpg.acquireTransientAST(fileInEditor); + + // Setup nodes used for refactoring + setSelectedNodeAndEndIfNode(); + setSelectedIfConstructNode(); + setGotoStatements(); + setGotoStatementsWithEndIfLabel(); + setSelectedGotoStatementsWithEndIfLabel(); + setContinueAfterIfStmtNode(); + } + + /** + * Set selected node and selected end if node used for refactoring. + * + * @param None. + * + * @return None. + */ + private void setSelectedNodeAndEndIfNode() + { + selectedNode = findEnclosingNode(this.astOfFileInEditor, this.selectedRegionInEditor); + selectedEndIfNode = (ASTEndIfStmtNode)findEnclosingNodeOfType(selectedNode, + ASTEndIfStmtNode.class); + } + + /** + * Set selected if construct node used for refactoring. + * + * @param None. + * + * @return None. + */ + private void setSelectedIfConstructNode() + { + selectedIfConstructNode = (ASTIfConstructNode)findEnclosingNodeOfType(selectedEndIfNode, + ASTIfConstructNode.class); + } + + /** + * Set goto statements used for refactoring. + * + * @param None. + * + * @return None. + */ + private void setGotoStatements() + { + gotoStatements = getGotoNodes(ScopingNode.getLocalScope(selectedEndIfNode)); + } + + /** + * Set go to statements with end if label used for refactoring. + * + * @param None. + * + * @return None. + */ + private void setGotoStatementsWithEndIfLabel() + { + gotoStatementWithEndIfLabel = findGotoForLabel(gotoStatements, selectedEndIfNode.getLabel() + .getText()); + } + + /** + * Set selected go to statements with end if label used for refactoring. + * + * @param None. + * + * @return None. + */ + private void setSelectedGotoStatementsWithEndIfLabel() + { + selectedGotoStatements = getGotoNodes(selectedIfConstructNode); + selectedGotoStatementWithEndIfLabel = findGotoForLabel(selectedGotoStatements, + selectedEndIfNode.getLabel().getText()); + } + + /** + * Set continue after if statement used for refactoring. + * + * @param None. + * + * @return None. + */ + private void setContinueAfterIfStmtNode() + { + continueAfterIfStmtNode = continueAfterIfStmt(selectedIfConstructNode); + } + + /** + * Main refactoring code for condition when CONTINUE statement follows the END..IF that was + * selected for refactoring. The logic will renumber/retarget any GOTO statements in the GOTO to + * that of the CONINUE label. (Per FORTRAN language standard the CONTINUE statement must have a + * label). If any GOTO statement inside the selected END..IF targets the END..IF selected for + * the Refactoring then the label of the END..IF will not be removed and that inner GOTO will + * still target it. If there are no inner GOTOs targeting the END..IF label then the END..IF + * label will be removed as part of the refactoring. + * + */ + private void changeGotoLabelToContinueLabel() + { + // Check all GOTO statements in the entire PROGRAM to see if they target the END..IF label + // number selected during the Refactoring. If so then retarget/renumber them to the + // CONTINUE block that follows. (Note: Inner GOTO statements that that target the END..IF + // statement are not retargeted/renumbered.) + for (ASTGotoStmtNode gotoNode : gotoStatementWithEndIfLabel) + { + // Do not re-target GOTO statements from within the selected END..IF for refactoring. + if (!selectedGotoStatementWithEndIfLabel.contains(gotoNode)) + { // Goto targeted to our selected IF..ENDIF block + gotoNode.getGotoLblRef().getLabel() + .setText(continueAfterIfStmtNode.getLabel().getText()); // Use existing + } + } + + // Label of selected END..IF for Refactoring is only removed after all other GOTOs have been + // retargeted and if no inner GOTO statements target its label. + if (selectedGotoStatementWithEndIfLabel.isEmpty()) + { + selectedEndIfNode.setLabel(null); + selectedEndIfNode.findFirstToken().setWhiteBefore( + selectedIfConstructNode.findFirstToken().getWhiteBefore()); // reindenter alt. + } + + } + + /** + * Modify Fortran code to add a CONTINUE statement after labeled END IF then remove END IF label + * only if there are no GOTO statements within the selected IF statement that target that END IF + * statement. + * + */ + private void changeNoContinueAfterEndIf() + { + + // build the CONTINUE node + if (continueAfterIfStmtNode != null) { return; } + + @SuppressWarnings("unchecked") + ASTListNode listNode = (ASTListNode)selectedIfConstructNode.getParent(); + + // build the CONTINUE statement program source code + String programString = "program p\n" + selectedEndIfNode.getLabel().getText() + " CONTINUE" //$NON-NLS-1$ //$NON-NLS-2$ + + EOL + "end program"; //$NON-NLS-1$ + ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString); + ASTContinueStmtNode continueStmt = (ASTContinueStmtNode)programNode.getBody().get(0); + + // insert into AST + continueStmt.setParent(selectedIfConstructNode.getParent()); + listNode.insertAfter(selectedIfConstructNode, continueStmt); + + // clear label on END IF statement + if (selectedGotoStatementWithEndIfLabel.size() == 0) + { + selectedEndIfNode.setLabel(null); + // correct indentation + selectedEndIfNode.findFirstToken().setWhiteBefore( + selectedIfConstructNode.findFirstToken().getWhiteBefore()); + } + else + { + // Grab all labels + LinkedList actionStmts = getActionStmts(ScopingNode + .getLocalScope(selectedEndIfNode)); + + // Calculate unique label + String label = getUniqueLabel(actionStmts); + + // Set continue label to new label + continueStmt.getLabel().setText(label); + + // Set all goto statements to new label + for (ASTGotoStmtNode node : gotoStatementWithEndIfLabel) + { + if (!selectedGotoStatementWithEndIfLabel.contains(node)) + { + node.getGotoLblRef().getLabel().setText(label); + } + } + } + } + + /** + * Build a list of all GOTO node types from the starting node. + * + * @param startNode Node to start the search. + * + * @return LinkedList of GOTO nodes. + */ + private LinkedList getGotoNodes(IASTNode startNode) + { + if (startNode == null) { return null; } + + /* + * Unable to find all goto statements when there are do loops in startNode, so need to + * search in the do loops separately. + */ + final LinkedList gotoNodes = getGotoStmtsInAllProperLoopConstructs(startNode); + + startNode.accept(new ASTVisitor() + { + @Override + public void visitASTGotoStmtNode(ASTGotoStmtNode node) + { + gotoNodes.add(node); + } + }); + + return gotoNodes; + } + + /** + * Build a list of all proper-loop-construct node types from the starting node. + * + * @param startNode Node to start the search. + * @return LinkedList of proper-loop-construct nodes. + */ + private LinkedList getGotoStmtsInAllProperLoopConstructs(IASTNode startNode) + { + final LinkedList gotoNodes = new LinkedList(); + final LinkedList loopNodes = getProperLoopConstructs(startNode); + + for (ASTProperLoopConstructNode loop : loopNodes) + { + for (IASTNode node : loop.getBody()) + { + node.accept(new ASTVisitor() + { + @Override + public void visitASTGotoStmtNode(ASTGotoStmtNode node) + { + gotoNodes.add(node); + } + }); + } + } + + return gotoNodes; + } + + /** + * Find GOTO node(s) based on matching label. + * + * @param gotos List of GOTO statements to check for matching label. + * @param label Label to match against. + * @return List of GOTO nodes that target the specified label. + */ + private LinkedList findGotoForLabel(LinkedList gotos, + String label) + { + if (gotos == null) { return new LinkedList(); } + + LinkedList gotoWithLabel = new LinkedList(); + for (ASTGotoStmtNode gotoNode : gotos) + { + if (gotoNode.getGotoLblRef().getLabel().getText().contentEquals(label)) + { + gotoWithLabel.add(gotoNode); + } + } + + return gotoWithLabel; + } + + /** + * Check for CONTINUE statement after a if construct node + * + * @param ifStmt If construct node. + * @return continue statement node or null. + */ + private static ASTContinueStmtNode continueAfterIfStmt(ASTIfConstructNode ifStmt) + { + if (ifStmt == null) { return null; } + + @SuppressWarnings("unchecked") + ASTListNode list = (ASTListNode)ifStmt.getParent(); + + for (int i = 0; i < list.size() - 1; i++) + { + if (list.get(i) != null) + { + if (list.get(i).equals(ifStmt)) + { + if (list.get(i + 1) instanceof ASTContinueStmtNode) { return (ASTContinueStmtNode)list + .get(i + 1); } + } + } + } + + return null; + } + + /** + * Generate a unique label based on the labels passed in (unique in that find the largest and + * add 10) + * + * @param actionStmts List of statements that may be labeled to consider for a unique label. + * @return Unique label value. + */ + private String getUniqueLabel(LinkedList actionStmts) + { + int label = Integer.parseInt(selectedEndIfNode.getLabel().getText()); + for (IActionStmt stmt : actionStmts) + { + if (stmt.getLabel() != null) + { + int currentLabel = Integer.parseInt(stmt.getLabel().getText()); + if (currentLabel > label) + { + label = currentLabel; + } + } + } + label += 10; + + return String.valueOf(label); + } + + /** + * Find Action statement nodes in the tree from the starting search node. + * + * @param startNode Starting node from which to perform the search. + * @return LinkedList of action statement nodes that are found. + */ + private LinkedList getActionStmts(IASTNode startNode) + { + final LinkedList actionStmts = getActionStmtsInAllProperLoopConstructs(); + startNode.accept(new ASTVisitor() + { + @Override + public void visitIActionStmt(IActionStmt node) + { + actionStmts.add(node); + } + }); + + return actionStmts; + } + + /** + * Find Action statement nodes in entire file in editor. + * + * @return LinkedList of action statement nodes found. + */ + private LinkedList getActionStmtsInAllProperLoopConstructs() + { + final LinkedList actionStmts = new LinkedList(); + final LinkedList loopNodes = getProperLoopConstructs(ScopingNode + .getLocalScope(selectedEndIfNode)); + + for (ASTProperLoopConstructNode loop : loopNodes) + { + for (IASTNode node : loop.getBody()) + { + node.accept(new ASTVisitor() + { + @Override + public void visitIActionStmt(IActionStmt node) + { + actionStmts.add(node); + } + }); + } + } + + return actionStmts; + } + + /** + * Find all proper loop constructs in the tree from the starting search node. + * + * @param startNode Starting node from which to perform the search. + * @return LinkedList of proper loop construct nodes found. + */ + private LinkedList getProperLoopConstructs(IASTNode startNode) + { + final LinkedList loopNodes = new LinkedList(); + + // Change AST to represent DO-loops as ASTProperLoopConstructNodes + LoopReplacer.replaceAllLoopsIn(this.astOfFileInEditor.getRoot()); + + startNode.accept(new ASTVisitorWithLoops() + { + @Override + public void visitASTProperLoopConstructNode(ASTProperLoopConstructNode node) + { + loopNodes.add(node); + } + }); + + return loopNodes; + } +} Index: src/org/eclipse/photran/internal/core/refactoring/RemovePauseStmtRefactoring.java =================================================================== RCS file: src/org/eclipse/photran/internal/core/refactoring/RemovePauseStmtRefactoring.java diff -N src/org/eclipse/photran/internal/core/refactoring/RemovePauseStmtRefactoring.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/photran/internal/core/refactoring/RemovePauseStmtRefactoring.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka + * 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: + * Rita Chow - Initial Implementation + * Nicola Hall - Initial Implementation + * Jerry Hsiao - Initial Implementation + * Mark Mozolewski - Initial Implementation + * Chamil Wijenayaka - Initial Implementation + *******************************************************************************/ +package org.eclipse.photran.internal.core.refactoring; + +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.refactoring.infrastructure.FortranEditorRefactoring; +import org.eclipse.photran.internal.core.parser.*; + +/** + * This feature address the replacement of the PAUSE statement with a PRINT and READ statement. + * Execution of a PAUSE statement may be different on different platforms. The refactoring assumes + * the most basic functionality: it replaces the PAUSE statement with a PRINT statement that + * displays the message of the PAUSE statement, immediately followed by a READ statement that waits + * for any input from the user. + * + * User Selection Requirements: The PAUSE statement to be replaced. + * + * @author Rita Chow (chow15), Jerry Hsiao (jhsiao2), Mark Mozolewski (mozolews), Chamil Wijenayaka + * (wijenay2), Nicola Hall (nfhall2) + */ +public class RemovePauseStmtRefactoring extends FortranEditorRefactoring +{ + private IASTNode selectedNode = null; + + private ASTPauseStmtNode selectedPauseStmt = null; + + /** + * Preconditions checks: Check if project has refactoring is enabled. + * Checks that the user selects a PAUSE statement for refactoring. Failure + * to meet these conditions will result in a fail-initial condition. + */ + @Override + protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm) + throws org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring.PreconditionFailure + { + ensureProjectHasRefactoringEnabled(status); + + // Check if selected is a PAUSE statement + setSelectedPauseStmt(); + + if (selectedPauseStmt == null) + { + System.out.println(Messages.RemovePauseStmtRefactoring_SelectPauseStmt); + fail(Messages.RemovePauseStmtRefactoring_SelectPauseStmt); + } + } + + /** + * FinalConditions no final checks required. + */ + @Override + protected void doCheckFinalConditions(RefactoringStatus status, IProgressMonitor pm) + throws org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring.PreconditionFailure + { + } + + /** + * Performs main refactoring (delegated to other methods). + */ + @Override + protected void doCreateChange(IProgressMonitor pm) throws CoreException, + OperationCanceledException + { + changePauseStmt(); + + // Finalize. + this.addChangeFromModifiedAST(this.fileInEditor, pm); + vpg.releaseAST(this.fileInEditor); + } + + /** + * Provide GUI refactoring label. + */ + @Override + public String getName() + { + return Messages.RemovePauseStmtRefactoring_Name; + } + + /** + * Obtains the selected pause statement else sets the member field to null. + */ + private void setSelectedPauseStmt() + { + selectedNode = findEnclosingNode(this.astOfFileInEditor, this.selectedRegionInEditor); + + selectedPauseStmt = (ASTPauseStmtNode)findEnclosingNodeOfType(selectedNode, + ASTPauseStmtNode.class); + } + + /** + * Insert modified PRINT statement and build READ() AST node to insert in to the program after + * the PRINT statement. + */ + private void changePauseStmt() + { + // change to modify the transient AST. + this.astOfFileInEditor = vpg.acquireTransientAST(fileInEditor); + + // check on pause statement performed in initial, should not have changed in final. + setSelectedPauseStmt(); + + String pauseMessage = "\'\'"; //$NON-NLS-1$; + + // Contents of the PRINT statement to maintain. + if (null != selectedPauseStmt.getStringConst()) + { + pauseMessage = selectedPauseStmt.getStringConst().getText(); + } + + // Build new AST node for modified PRINT statement and new READ statement. + String indent = selectedPauseStmt.findFirstToken().getWhiteBefore(); + String programString = "program p" + EOL + //$NON-NLS-1$ + indent + + "PRINT *, " + pauseMessage + selectedPauseStmt.findLastToken().getWhiteBefore() + EOL + //$NON-NLS-1$ + indent + "READ (*, *)" + EOL + //$NON-NLS-1$ + "end program"; //$NON-NLS-1$ + + // Insert new AST node in place of selected PRINT statement. + ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString); + ASTPrintStmtNode printStmt = (ASTPrintStmtNode)programNode.getBody().get(0); + ASTReadStmtNode readStmt = (ASTReadStmtNode)programNode.getBody().get(1); + + @SuppressWarnings("unchecked") + ASTListNode listNode = (ASTListNode)selectedPauseStmt.getParent(); + + selectedPauseStmt.replaceWith(printStmt); + listNode.insertAfter(printStmt, readStmt); + } +} Index: src/org/eclipse/photran/internal/core/refactoring/RemoveRealAndDoublePrecisionLoopCountersRefactoring.java =================================================================== RCS file: src/org/eclipse/photran/internal/core/refactoring/RemoveRealAndDoublePrecisionLoopCountersRefactoring.java diff -N src/org/eclipse/photran/internal/core/refactoring/RemoveRealAndDoublePrecisionLoopCountersRefactoring.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/photran/internal/core/refactoring/RemoveRealAndDoublePrecisionLoopCountersRefactoring.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,392 @@ +/******************************************************************************* + * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka + * 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: + * Rita Chow - Initial Implementation + * Nicola Hall - Initial Implementation + * Jerry Hsiao - Initial Implementation + * Mark Mozolewski - Initial Implementation + * Chamil Wijenayaka - Initial Implementation + *******************************************************************************/ +package org.eclipse.photran.internal.core.refactoring; + +import java.util.LinkedList; +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.analysis.binding.ScopingNode; +import org.eclipse.photran.internal.core.analysis.loops.LoopReplacer; +import org.eclipse.photran.internal.core.parser.*; +import org.eclipse.photran.internal.core.refactoring.infrastructure.FortranEditorRefactoring; +import org.eclipse.photran.internal.core.analysis.loops.ASTProperLoopConstructNode; + +/** + * Remove Real and Double Precision Loop Counter Refactoring: + * + * This refactoring will take a controlled DO loop, i.e. on that specifies the starting and ending + * values for the control loop index and transform it to an uncontrolled do loop where the same loop + * index and values are manually inserted into to the loop. If a explicit step size is specified is + * used, otherwise an implicit one is inserted. The refactoring checks the start/end values of the + * loop control variable to determine if the loop control variable should increment or decrement. + * + * User Selection Requirements: A controlled DO loop statement to be considered for refactoring. + * + * @author Rita Chow (chow15), Nicola Hall (nfhall2), Jerry Hsiao (jhsiao2), Mark Mozolewski + * (mozolews), Chamil Wijenayaka (wijenay2) + */ +public class RemoveRealAndDoublePrecisionLoopCountersRefactoring extends FortranEditorRefactoring +{ + + private IASTNode selectedNode = null; + + private ASTProperLoopConstructNode selectedDoLoopNode = null; + + private LinkedList typeDeclarationsInFile; + + private String doVarName; + + private boolean shouldReplaceWithDoWhileLoop = false; + + /** + * Provide GUI refactoring label. + */ + @Override + public String getName() + { + return Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_Name; + } + + /** + * Set method for DO or DO WHILE refactoring selection variable. + * + * @param value Set tracking variable for DO or DO WHILE refactoring selection. + */ + public void setShouldReplaceWithDoWhileLoop(boolean value) + { + this.shouldReplaceWithDoWhileLoop = value; + } + + /** + * Precondition checks: Check if project has refactoring enabled. + */ + @Override + protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm) + throws PreconditionFailure + { + ensureProjectHasRefactoringEnabled(status); + } + + /** + * The following initial conditions are checked (a failure of any will result in a + * fail-initial): - A controlled DO loop must be selected by the user. - Loop control variables + * of a controlled DO loop must be declared as type REAL or DOUBLE PRECISION only. + */ + @Override + protected void doCheckFinalConditions(RefactoringStatus status, IProgressMonitor pm) + throws PreconditionFailure + { + Boolean doVarNameIsRealOrDouble = false; + + this.astOfFileInEditor = vpg.acquireTransientAST(fileInEditor); + + // Change AST to represent DO-loops as ASTProperLoopConstructNodes + LoopReplacer.replaceAllLoopsIn(this.astOfFileInEditor.getRoot()); + + // Identify selected DO loop. + selectedNode = findEnclosingNode(this.astOfFileInEditor, this.selectedRegionInEditor); + selectedDoLoopNode = (ASTProperLoopConstructNode)findEnclosingNodeOfType(selectedNode, + ASTProperLoopConstructNode.class); + + // Check for invalid selection (DO statement not selected) + if (selectedDoLoopNode == null) + { + fail(Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_PleaseSelectADoLoop); + } + + // Check uncontrolled DO loop selected. + if (selectedDoLoopNode.getLoopHeader().getLoopControl() == null) + { + fail(Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_PleaseSelectAControlledDoLoop); + } + + // Find all REAL and DOUBLE declared variables. + doVarName = selectedDoLoopNode.getLoopHeader().getLoopControl().getVariableName().getText() + .toString(); + typeDeclarationsInFile = getTypeDeclarations(this.astOfFileInEditor.getRoot()); + + if (typeDeclarationsInFile == null) + { + fail(Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_LoopControlVariableMissingDeclaration); + } + + // Search all type declarations of the PROGRAM to find DO loop control variable name and + // REAL or DOUBLE variable type. + for (ASTTypeDeclarationStmtNode typeDeclaration : typeDeclarationsInFile) + { + + if (typeDeclaration.getTypeSpec().isReal() || typeDeclaration.getTypeSpec().isDouble()) + { + + // Search all variable names for this REAL/DOUBLE variable declaration. + for (ASTEntityDeclNode entityDeclaration : typeDeclaration.getEntityDeclList()) + { + + if (entityDeclaration.getObjectName().getObjectName().getText() + .equals(doVarName)) + { + doVarNameIsRealOrDouble = true; + break; + } + } + + } + } + + if (!doVarNameIsRealOrDouble) + { + fail(Messages.RemoveRealAndDoublePrecisionLoopCountersRefactoring_LoopControlVariableNotRealOrDouble); + } + } + + /** + * After initial conditions checks pass there is a proper controlled DO loop variable to + * refactor. The refactoring consists of building a number of AST node elements and inserting + * them in to the program to do the work that the controlled DO loop would have done. This + * includes: 1) Initial loop control variable assignment (starting value). 2) + * Increment/Decrement control variable by specified amount (implicit or explicit step size) 3) + * Check inside DO loop to see if loop variable limit specified is exceeded. + */ + @Override + protected void doCreateChange(IProgressMonitor pm) throws CoreException, + OperationCanceledException + { + String ifCheckLb = selectedDoLoopNode.getLoopHeader().getLoopControl().getLb().toString(); + String ifCheckUb = selectedDoLoopNode.getLoopHeader().getLoopControl().getUb().toString(); + String ifCheckVar = selectedDoLoopNode.getLoopHeader().getLoopControl().getVariableName() + .getText().toString(); + + // Implicit step size check. + String ifCheckStep = null; + if (selectedDoLoopNode.getLoopHeader().getLoopControl().getStep() != null) + { + ifCheckStep = selectedDoLoopNode.getLoopHeader().getLoopControl().getStep().toString(); + } + else + { + ifCheckStep = " 1"; //$NON-NLS-1$ + } + + String ifCheckIncrDecr = ""; //$NON-NLS-1$ + String ifCheckStr = ""; //$NON-NLS-1$ + + // Work with both as double type. + double dLb = Double.valueOf(ifCheckLb.trim()).doubleValue(); + double dUb = Double.valueOf(ifCheckUb.trim()).doubleValue(); + + // Check for > or < IF check. + if (dLb < dUb) + { + if (shouldReplaceWithDoWhileLoop) + ifCheckStr = ifCheckVar + " <=" + ifCheckUb; //$NON-NLS-1$ + else + ifCheckStr = ifCheckVar + " >" + ifCheckUb; //$NON-NLS-1$ + ifCheckIncrDecr = " +"; //$NON-NLS-1$ + } + else + { + if (shouldReplaceWithDoWhileLoop) + ifCheckStr = ifCheckVar + " >=" + ifCheckUb; //$NON-NLS-1$ + else + ifCheckStr = ifCheckVar + " <" + ifCheckUb; //$NON-NLS-1$ + ifCheckIncrDecr = " -"; //$NON-NLS-1$ + } + + // AST modification for refactoring. + if (shouldReplaceWithDoWhileLoop) + { + insertNewDoWhileLoop(ifCheckLb, ifCheckVar, ifCheckStep, ifCheckIncrDecr, ifCheckStr); + } + else + { + insertNewDoLoop(ifCheckLb, ifCheckVar, ifCheckStep, ifCheckIncrDecr, ifCheckStr); + } + + // Finalize + this.addChangeFromModifiedAST(this.fileInEditor, pm); + vpg.releaseAST(this.fileInEditor); + } + + /** + * With provided strings this method builds the new AST nodes for the initial variable + * assignment, increment/decrement statement, and IF DO loop break statement. They are then + * inserted in to the proper hierarchy of the program AST structure. (See main refactoring + * comments at the top of the file for a list of steps performed.) + * + * @param ifCheckLb Lower bound (starting value) of loop variable. + * @param ifCheckVar Loop control variable name. + * @param ifCheckStep Loop counter variable step size (implicitly or explicitly declared) + * @param ifCheckIncrDecr (+/-) Depending on loop variable count direction. + * @param ifCheckStr The IF check condition to break the DO loop. + */ + private void insertNewDoLoop(String ifCheckLb, String ifCheckVar, String ifCheckStep, + String ifCheckIncrDecr, String ifCheckStr) + { + // Build initial value assignment node. + insertInitialCounterAssignment(ifCheckVar, ifCheckLb); + + // Remove DO control + int sizeOfLoopControlString = selectedDoLoopNode.getLoopHeader().getLoopControl() + .toString().length(); + String replaceLoopControlStringWith = ""; //$NON-NLS-1$ + for (int i = 0; i < sizeOfLoopControlString; i++) + { + replaceLoopControlStringWith += " "; //$NON-NLS-1$ + } + selectedDoLoopNode.getLoopHeader().setLoopControl(null); + selectedDoLoopNode + .getLoopHeader() + .findLastToken() + .setWhiteBefore( + replaceLoopControlStringWith + + selectedDoLoopNode.getLoopHeader().findLastToken().getWhiteBefore()); + + // Build increment assignment node. + ASTAssignmentStmtNode incrDecrNode = insertCounterAssignment(ifCheckVar, ifCheckIncrDecr, + ifCheckStep); + + // Build IF node for checking DO limits. + IExecutionPartConstruct lastNodeInDoLoopBody = selectedDoLoopNode.getBody().get( + selectedDoLoopNode.getBody().size() - 1); + String initialIndent = ScopingNode.getLocalScope(selectedDoLoopNode).getBody() + .findFirstToken().getWhiteBefore(); + String programString = ""; //$NON-NLS-1$ + programString = "program p\n" + lastNodeInDoLoopBody.findFirstToken().getWhiteBefore() //$NON-NLS-1$ + + "IF(" + ifCheckStr + ") THEN\n" //$NON-NLS-1$ //$NON-NLS-2$ + + lastNodeInDoLoopBody.findFirstToken().getWhiteBefore() + + initialIndent + + "EXIT\n" //$NON-NLS-1$ + + lastNodeInDoLoopBody.findFirstToken().getWhiteBefore() + + "END IF" + EOL + "end program"; //$NON-NLS-1$ //$NON-NLS-2$ + ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString); + ASTIfConstructNode ifNode = (ASTIfConstructNode)programNode.getBody().get(0); + + // Insert IF node into AST + ifNode.setParent(selectedDoLoopNode.getParent()); + selectedDoLoopNode.getBody().insertAfter(incrDecrNode, ifNode); + } + + /** + * With provided strings this method builds the new AST nodes for the initial variable + * assignment, increment/decrement statement, and DO WHILE loop check statement. They are then + * inserted in to the proper hierarchy of the program AST structure. (See main refactoring + * comments at the top of the file for a list of steps performed.) + * + * @param ifCheckLb Lower bound (starting value) of loop variable. + * @param ifCheckVar Loop control variable name. + * @param ifCheckStep Loop counter variable step size (implicitly or explicitly declared) + * @param ifCheckIncrDecr (+/-) Depending on loop variable count direction. + * @param ifCheckStr The IF check condition to break the DO loop. + */ + @SuppressWarnings("nls") + private void insertNewDoWhileLoop(String ifCheckLb, String ifCheckVar, String ifCheckStep, + String ifCheckIncrDecr, String ifCheckStr) + { + // Build initial value assignment node. + insertInitialCounterAssignment(ifCheckVar, ifCheckLb); + + // Build increment assignment node. + insertCounterAssignment(ifCheckVar, ifCheckIncrDecr, ifCheckStep); + + // Change do loop to while do loop + String programString = ""; + programString = "program p\n" + + selectedDoLoopNode.getLoopHeader().findFirstToken().getWhiteBefore() + "DO WHILE (" + + ifCheckStr + ")" + + selectedDoLoopNode.getLoopHeader().findLastToken().getWhiteBefore() + EOL + + "EXIT\nENDDO" + EOL + "end program"; + + ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString); + ASTDoConstructNode doConstructNode = (ASTDoConstructNode)programNode.getBody().get(0); + selectedDoLoopNode.setLoopHeader(doConstructNode.getLabelDoStmt()); + selectedDoLoopNode.getLoopHeader().findLastToken() + .setWhiteBefore(selectedDoLoopNode.getLoopHeader().findLastToken().getWhiteBefore()); + } + + /** + * Creates an assignment statement node for the initial loop counter value assignment and + * inserts it before the selected DO loop of the refactoring. + * + * @param ifCheckVar Loop control variable name. + * @param ifCheckLb Lower bound (starting value) of loop variable. + */ + private void insertInitialCounterAssignment(String ifCheckVar, String ifCheckLb) + { + String programString = "program p\n" + selectedDoLoopNode.findFirstToken().getWhiteBefore() + ifCheckVar + //$NON-NLS-1$ + " =" + ifCheckLb + EOL + "end program"; //$NON-NLS-1$ //$NON-NLS-2$ + ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString); + ASTAssignmentStmtNode initValNode = (ASTAssignmentStmtNode)programNode.getBody().get(0); + + // Insert initial value assignment node into AST + initValNode.setParent(selectedDoLoopNode.getParent()); + @SuppressWarnings("unchecked") + ASTListNode doNode = (ASTListNode)selectedDoLoopNode.getParent(); + doNode.insertBefore(selectedDoLoopNode, initValNode); + } + + /** + * Creates an assignment statement node for the loop counter variable assignment and inserts it + * after the selected DO loop of the refactoring. + * + * @param ifCheckVar Loop control variable name. + * @param ifCheckIncrDecr (+/-) Depending on loop variable count direction. + * @param ifCheckStep Loop counter variable step size (implicitly or explicitly declared) + */ + private ASTAssignmentStmtNode insertCounterAssignment(String ifCheckVar, + String ifCheckIncrDecr, String ifCheckStep) + { + IExecutionPartConstruct lastNodeInDoLoopBody = selectedDoLoopNode.getBody().get( + selectedDoLoopNode.getBody().size() - 1); + String programString = ""; //$NON-NLS-1$ + programString = "program p\n" + lastNodeInDoLoopBody.findFirstToken().getWhiteBefore() + ifCheckVar + //$NON-NLS-1$ + " = " + ifCheckVar + ifCheckIncrDecr + ifCheckStep + EOL + "end program"; //$NON-NLS-1$ //$NON-NLS-2$ + ASTMainProgramNode programNode = (ASTMainProgramNode)parseLiteralProgramUnit(programString); + ASTAssignmentStmtNode incrDecrNode = (ASTAssignmentStmtNode)programNode.getBody().get(0); + + // Insert increment/decrement assignment node into AST + incrDecrNode.setParent(selectedDoLoopNode.getParent()); + + selectedDoLoopNode.getBody().insertAfter(lastNodeInDoLoopBody, incrDecrNode); + + return incrDecrNode; + } + + /** + * Get all variable type declarations in the program. + * + * @param startNode node to start search. + * + * @return LinkedList of type declarations nodes. + */ + private LinkedList getTypeDeclarations(IASTNode startNode) + { + if (startNode == null) { return null; } + + final LinkedList typeDeclarations = new LinkedList(); + + startNode.accept(new ASTVisitor() + { + @Override + public void visitASTTypeDeclarationStmtNode(ASTTypeDeclarationStmtNode node) + { + typeDeclarations.add(node); + } + }); + + return typeDeclarations; + } +} \ No newline at end of file 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 14 Dec 2010 04:49:34 -0000 @@ -7,6 +7,11 @@ * * Contributors: * UIUC - Initial API and implementation + * Rita Chow - Photran Modifications + * Nicola Hall - Photran Modifications + * Jerry Hsiao - Photran Modifications + * Mark Mozolewski - Photran Modifications + * Chamil Wijenayaka - Photran Modifications *******************************************************************************/ package org.eclipse.photran.internal.core.refactoring.infrastructure; @@ -373,6 +378,27 @@ return null; } + /** + * Get node based on type. + * + * @param startNode node to start search. + * @param typeChecker instance type to search. + * + * @return node if found else null. + */ + protected IASTNode findEnclosingNodeOfType(IASTNode startNode, Class classType) + { + if(startNode == null) { return null; } + + IASTNode node = startNode; + while ((node != null) && (node.getClass() != classType)) + { + node = node.getParent(); + } + + return node; + } + protected static boolean nodeExactlyEnclosesRegion(IASTNode parent, Token firstToken, Token lastToken) { return parent.findFirstToken() == firstToken && parent.findLastToken() == lastToken; #P org.eclipse.photran.core.vpg.tests Index: src/org/eclipse/photran/internal/tests/refactoring/RemoveBranchToEndIfTestSuite.java =================================================================== RCS file: src/org/eclipse/photran/internal/tests/refactoring/RemoveBranchToEndIfTestSuite.java diff -N src/org/eclipse/photran/internal/tests/refactoring/RemoveBranchToEndIfTestSuite.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/photran/internal/tests/refactoring/RemoveBranchToEndIfTestSuite.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka + * 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: + * Rita Chow - Initial Implementation + * Nicola Hall - Initial Implementation + * Jerry Hsiao - Initial Implementation + * Mark Mozolewski - Initial Implementation + * Chamil Wijenayaka - Initial Implementation + *******************************************************************************/ +package org.eclipse.photran.internal.tests.refactoring; + +import junit.framework.Test; + +import org.eclipse.photran.internal.core.refactoring.RemoveBranchToEndIfRefactoring; +import org.eclipse.photran.internal.tests.Activator; +import org.eclipse.photran.internal.tests.PhotranRefactoringTestSuiteFromMarkers; + +/** + * Unit tests for the Remove Branch To End If Refactoring. + * + * @author + */ +public class RemoveBranchToEndIfTestSuite extends PhotranRefactoringTestSuiteFromMarkers +{ + private static final String DIR = "refactoring-test-code/remove-branch-to-end-if"; + + public static Test suite() throws Exception + { + return new RemoveBranchToEndIfTestSuite(); + } + + public RemoveBranchToEndIfTestSuite() throws Exception + { + super(Activator.getDefault(), + "Running Remove Branch To End If Refactoring in", + DIR, + RemoveBranchToEndIfRefactoring.class); + } + +} Index: src/org/eclipse/photran/internal/tests/refactoring/RemovePauseStmtTestSuite.java =================================================================== RCS file: src/org/eclipse/photran/internal/tests/refactoring/RemovePauseStmtTestSuite.java diff -N src/org/eclipse/photran/internal/tests/refactoring/RemovePauseStmtTestSuite.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/photran/internal/tests/refactoring/RemovePauseStmtTestSuite.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka + * 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: + * Rita Chow - Initial Implementation + * Nicola Hall - Initial Implementation + * Jerry Hsiao - Initial Implementation + * Mark Mozolewski - Initial Implementation + * Chamil Wijenayaka - Initial Implementation + *******************************************************************************/ +package org.eclipse.photran.internal.tests.refactoring; + +import junit.framework.Test; + +import org.eclipse.photran.internal.core.refactoring.RemovePauseStmtRefactoring; +import org.eclipse.photran.internal.tests.Activator; +import org.eclipse.photran.internal.tests.PhotranRefactoringTestSuiteFromMarkers; + +/** + * Unit tests for the Remove Pause Statement Refractoring. + * + * @author + */ +public class RemovePauseStmtTestSuite extends PhotranRefactoringTestSuiteFromMarkers +{ + private static final String DIR = "refactoring-test-code/remove-pause-stmt"; + + public static Test suite() throws Exception + { + return new RemovePauseStmtTestSuite(); + } + + public RemovePauseStmtTestSuite() throws Exception + { + super(Activator.getDefault(), + "Running Remove Pause Stmt Refactoring in", + DIR, + RemovePauseStmtRefactoring.class); + } + +} Index: src/org/eclipse/photran/internal/tests/refactoring/RemoveRealAndDoublePrecisionLoopCountersTestSuite.java =================================================================== RCS file: src/org/eclipse/photran/internal/tests/refactoring/RemoveRealAndDoublePrecisionLoopCountersTestSuite.java diff -N src/org/eclipse/photran/internal/tests/refactoring/RemoveRealAndDoublePrecisionLoopCountersTestSuite.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/photran/internal/tests/refactoring/RemoveRealAndDoublePrecisionLoopCountersTestSuite.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2010 Rita Chow, Nicola Hall, Jerry Hsiao, Mark Mozolewski, Chamil Wijenayaka + * 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: + * Rita Chow - Initial Implementation + * Nicola Hall - Initial Implementation + * Jerry Hsiao - Initial Implementation + * Mark Mozolewski - Initial Implementation + * Chamil Wijenayaka - Initial Implementation + *******************************************************************************/ +package org.eclipse.photran.internal.tests.refactoring; + +import junit.framework.Test; + +import org.eclipse.core.resources.IFile; +import org.eclipse.jface.text.TextSelection; +import org.eclipse.photran.internal.core.refactoring.RemoveRealAndDoublePrecisionLoopCountersRefactoring; +import org.eclipse.photran.internal.tests.Activator; +import org.eclipse.photran.internal.tests.PhotranRefactoringTestSuiteFromMarkers; + +/** + * Unit tests for the Remove Branch To End If Refactoring. + * + * @author + */ +public class RemoveRealAndDoublePrecisionLoopCountersTestSuite extends PhotranRefactoringTestSuiteFromMarkers +{ + private static final String DIR = "refactoring-test-code/remove-real-and-double-precision-loop-counters"; + + public static Test suite() throws Exception + { + return new RemoveRealAndDoublePrecisionLoopCountersTestSuite(); + } + + public RemoveRealAndDoublePrecisionLoopCountersTestSuite() throws Exception + { + super(Activator.getDefault(), + "Running Remove Real and Double Precision Loop Counters Refactoring in", + DIR, + RemoveRealAndDoublePrecisionLoopCountersRefactoring.class); + } + + @Override + protected boolean configureRefactoring(RemoveRealAndDoublePrecisionLoopCountersRefactoring refactoring, + IFile file, + TextSelection selection, + String[] markerText) + { + boolean shouldSucceed = super.configureRefactoring(refactoring, file, selection, markerText); + + boolean shouldReplaceWithDoWhileLoop; + if(markerText[4].equals("1")) + shouldReplaceWithDoWhileLoop = true; + else + shouldReplaceWithDoWhileLoop = false; + refactoring.setShouldReplaceWithDoWhileLoop(shouldReplaceWithDoWhileLoop); + + 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 14 Dec 2010 04:49:35 -0000 @@ -83,6 +83,16 @@ + + + +{ + protected Button doWhileLoop; + protected Button doLoop; + + @Override + public void createControl(Composite parent) + { + Composite top = new Composite(parent, SWT.NONE); + initializeDialogUnits(top); + setControl(top); + + top.setLayout(new GridLayout(1, false)); + + Composite group = top; + Label instr = new Label(group, SWT.NONE); + instr.setText(Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceRealDoublePrecisionLoopCounter); + + doWhileLoop = new Button(group, SWT.RADIO); + doWhileLoop.setText(Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoLoop); + doWhileLoop.setSelection(true); + doWhileLoop.addSelectionListener(new SelectionListener() + { + public void widgetDefaultSelected(SelectionEvent e) + { + widgetSelected(e); + } + + public void widgetSelected(SelectionEvent e) + { + boolean isChecked = doLoop.getSelection(); + getRefactoring().setShouldReplaceWithDoWhileLoop(isChecked); + } + }); + + doLoop = new Button(group, SWT.RADIO); + doLoop.setText(Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoWhileLoop); + + Label ok = new Label(group, SWT.NONE); + ok.setText("\n" + Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickOKMessage); //$NON-NLS-1$ + Label preview = new Label(group, SWT.NONE); + preview.setText(Messages.RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickPreviewMessage); + } +} 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 14 Dec 2010 04:49:36 -0000 @@ -31,3 +31,8 @@ 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 +RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceRealDoublePrecisionLoopCounter=Replace real/double precision loop counter with: +RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoLoop=DO Loop +RemoveRealAndDoublePrecisionLoopCountersInputPage_ReplaceWithDoWhileLoop=DO WHILE Loop +RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickOKMessage=Click OK to replace the real/double precision loop counter. +RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickPreviewMessage=To see what the changes will be made, click Preview.