Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Overbey2011-03-16 21:00:12 +0000
committerJeffrey Overbey2011-03-16 21:00:12 +0000
commit156ff6053e0d938989f41512b59389f2c4867aa2 (patch)
tree739af15be1155bd7fd85644f5e1acc54b8d6ccb1
parentca6ae6b0ac64e98edf0790f350efbe374bbaee32 (diff)
downloadorg.eclipse.photran-156ff6053e0d938989f41512b59389f2c4867aa2.tar.gz
org.eclipse.photran-156ff6053e0d938989f41512b59389f2c4867aa2.tar.xz
org.eclipse.photran-156ff6053e0d938989f41512b59389f2c4867aa2.zip
Bug 332596 - Refactoring [427]: Add Subroutine Parameter
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test1-basic/add_subroutine_parameter_1.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test1-basic/add_subroutine_parameter_1.f90.result7
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test10-fail-invalidtype/add_subroutine_parameter_10.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test11-updatecallsitewhenvariablenamesaddedincall/add_subroutine_parameter_11.f907
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test11-updatecallsitewhenvariablenamesaddedincall/add_subroutine_parameter_11.f90.result8
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test12-includevalidattributes/add_subroutine_parameter_12.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test12-includevalidattributes/add_subroutine_parameter_12.f90.result7
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test13-fail-invalidattribute/add_subroutine_parameter_13.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test14-fail-conflictingattributes/add_subroutine_parameter_14.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test15-fail-conflictingvariablenames/add_subroutine_parameter_15.f907
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test16-fail-whitespacevariablename/add_subroutine_parameter_16.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test17-fail-parameternamebeginswithnumber/add_subroutine_parameter_17.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test18-fail-defaultvalueisvariablestartingwithnumber/add_subroutine_parameter_18.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test19-fail-defaultvalueisrealwhentypeisinteger/add_subroutine_parameter_19.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test2-updatecallsite/add_subroutine_parameter_2.f907
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test2-updatecallsite/add_subroutine_parameter_2.f90.result8
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test20-fail-defaultvalueisnumberwhentypeisnonnumber/add_subroutine_parameter_20.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test21-fail-defaultvalueisnullwhentypeisnotpointer/add_subroutine_parameter_21.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test22-basicpointer/add_subroutine_parameter_22.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test22-basicpointer/add_subroutine_parameter_22.f90.result7
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test3-updatecallsitewithorder/add_subroutine_parameter_3.f907
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test3-updatecallsitewithorder/add_subroutine_parameter_3.f90.result8
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test4-fail-negativeposition/add_subroutine_parameter_4.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test5-fail-outofboundsposition/add_subroutine_parameter_5.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test6-fail-whitespacedefaultvalue/add_subroutine_parameter_6.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test7-basicarray/add_subroutine_parameter_7.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test7-basicarray/add_subroutine_parameter_7.f90.result7
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test8-logicalbasic/add_subroutine_parameter_8.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test8-logicalbasic/add_subroutine_parameter_8.f90.result7
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test9-dontsetvariabletype/add_subroutine_parameter_9.f906
-rw-r--r--org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test9-dontsetvariabletype/add_subroutine_parameter_9.f90.result7
-rw-r--r--org.eclipse.photran.core.vpg.tests/src/org/eclipse/photran/internal/tests/refactoring/AddSubroutineParameterTestSuite.java53
-rw-r--r--org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/AddSubroutineParameterRefactoring.java653
-rw-r--r--org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/Messages.java16
-rw-r--r--org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/messages.properties8
-rw-r--r--org.eclipse.photran.ui.vpg/OSGI-INF/l10n/bundle.properties4
-rw-r--r--org.eclipse.photran.ui.vpg/plugin.xml25
-rw-r--r--org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/AddSubroutineParameterAction.java175
-rw-r--r--org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/Messages.java6
-rw-r--r--org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/messages.properties3
40 files changed, 1140 insertions, 5 deletions
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test1-basic/add_subroutine_parameter_1.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test1-basic/add_subroutine_parameter_1.f90
new file mode 100644
index 00000000..6434c526
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test1-basic/add_subroutine_parameter_1.f90
@@ -0,0 +1,6 @@
+program basic ! basic test, adding an integer with intent in, default value 0, at position 0.
+
+end program basic
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer; intent(in) :: y, 0, 0, pass
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test1-basic/add_subroutine_parameter_1.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test1-basic/add_subroutine_parameter_1.f90.result
new file mode 100644
index 00000000..974b32c4
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test1-basic/add_subroutine_parameter_1.f90.result
@@ -0,0 +1,7 @@
+program basic ! basic test, adding an integer with intent in, default value 0, at position 0.
+
+end program basic
+subroutine sub(y,z) !<<<<< 4, 1, 4, 5, integer; intent(in) :: y, 0, 0, pass
+ integer, intent(in) :: y
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test10-fail-invalidtype/add_subroutine_parameter_10.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test10-fail-invalidtype/add_subroutine_parameter_10.f90
new file mode 100644
index 00000000..cb501f4b
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test10-fail-invalidtype/add_subroutine_parameter_10.f90
@@ -0,0 +1,6 @@
+program invalidtype ! Fails because the type specified is invalid in the declaration line.
+
+end program invalidtype
+subroutine sub(z) !<<<<< 4, 1, 4, 5, invalidtype :: y, 0, 0, fail-final
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test11-updatecallsitewhenvariablenamesaddedincall/add_subroutine_parameter_11.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test11-updatecallsitewhenvariablenamesaddedincall/add_subroutine_parameter_11.f90
new file mode 100644
index 00000000..30773eba
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test11-updatecallsitewhenvariablenamesaddedincall/add_subroutine_parameter_11.f90
@@ -0,0 +1,7 @@
+program variablenameaddedincallsite ! Tests that when y is added, the call site adds y=0
+ implicit none
+ call sub(z=2)
+end program variablenameaddedincallsite
+subroutine sub(z) !<<<<< 5, 1, 5, 5, integer; intent(in) :: y, 1, 0, pass
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test11-updatecallsitewhenvariablenamesaddedincall/add_subroutine_parameter_11.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test11-updatecallsitewhenvariablenamesaddedincall/add_subroutine_parameter_11.f90.result
new file mode 100644
index 00000000..30a77224
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test11-updatecallsitewhenvariablenamesaddedincall/add_subroutine_parameter_11.f90.result
@@ -0,0 +1,8 @@
+program variablenameaddedincallsite ! Tests that when y is added, the call site adds y=0
+ implicit none
+ call sub(z=2,y=0)
+end program variablenameaddedincallsite
+subroutine sub(z,y) !<<<<< 5, 1, 5, 5, integer; intent(in) :: y, 1, 0, pass
+ integer, intent(in) :: y
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test12-includevalidattributes/add_subroutine_parameter_12.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test12-includevalidattributes/add_subroutine_parameter_12.f90
new file mode 100644
index 00000000..de084a3d
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test12-includevalidattributes/add_subroutine_parameter_12.f90
@@ -0,0 +1,6 @@
+program validattributes ! Tests that valid attributes (intent(inout)) are allowed.
+
+end program validattributes
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer; intent(inout) :: y, 0, 0, pass
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test12-includevalidattributes/add_subroutine_parameter_12.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test12-includevalidattributes/add_subroutine_parameter_12.f90.result
new file mode 100644
index 00000000..46c97da6
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test12-includevalidattributes/add_subroutine_parameter_12.f90.result
@@ -0,0 +1,7 @@
+program validattributes ! Tests that valid attributes (intent(inout)) are allowed.
+
+end program validattributes
+subroutine sub(y,z) !<<<<< 4, 1, 4, 5, integer; intent(inout) :: y, 0, 0, pass
+ integer, intent(inout) :: y
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test13-fail-invalidattribute/add_subroutine_parameter_13.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test13-fail-invalidattribute/add_subroutine_parameter_13.f90
new file mode 100644
index 00000000..250e531a
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test13-fail-invalidattribute/add_subroutine_parameter_13.f90
@@ -0,0 +1,6 @@
+program invalidvalidattributes ! Tests that invalid attributes fail
+
+end program invalidvalidattributes
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer; intent(inoot) :: y, 0, 0, fail-final
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test14-fail-conflictingattributes/add_subroutine_parameter_14.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test14-fail-conflictingattributes/add_subroutine_parameter_14.f90
new file mode 100644
index 00000000..5e5bd5dc
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test14-fail-conflictingattributes/add_subroutine_parameter_14.f90
@@ -0,0 +1,6 @@
+program conflictingattributes ! Tests that conflicting attributes (two types) fail.
+
+end program conflictingattributes
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer; real; intent(out) :: y, 0, 0, fail-final
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test15-fail-conflictingvariablenames/add_subroutine_parameter_15.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test15-fail-conflictingvariablenames/add_subroutine_parameter_15.f90
new file mode 100644
index 00000000..25b2a261
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test15-fail-conflictingvariablenames/add_subroutine_parameter_15.f90
@@ -0,0 +1,7 @@
+program conflictingvariablenames ! Tests that a parameter cannot be given the same name as another in scope.
+
+end program conflictingvariablenames
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer; intent(in) :: alreadyused, 0, 0, fail-final
+ real :: alreadyused
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test16-fail-whitespacevariablename/add_subroutine_parameter_16.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test16-fail-whitespacevariablename/add_subroutine_parameter_16.f90
new file mode 100644
index 00000000..ec2f8079
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test16-fail-whitespacevariablename/add_subroutine_parameter_16.f90
@@ -0,0 +1,6 @@
+program whitespacevariablename ! Tests that a variable name cannot be set to just white space.
+
+end program whitespacevariablename
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer; intent(inout) :: , 0, 0, fail-final
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test17-fail-parameternamebeginswithnumber/add_subroutine_parameter_17.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test17-fail-parameternamebeginswithnumber/add_subroutine_parameter_17.f90
new file mode 100644
index 00000000..bd0d49ec
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test17-fail-parameternamebeginswithnumber/add_subroutine_parameter_17.f90
@@ -0,0 +1,6 @@
+program parameternamebeginswithnumber ! Tests that the variable name cannot begin with a number
+
+end program parameternamebeginswithnumber
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer :: 1y, 0, 0, fail-final
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test18-fail-defaultvalueisvariablestartingwithnumber/add_subroutine_parameter_18.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test18-fail-defaultvalueisvariablestartingwithnumber/add_subroutine_parameter_18.f90
new file mode 100644
index 00000000..3a81081d
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test18-fail-defaultvalueisvariablestartingwithnumber/add_subroutine_parameter_18.f90
@@ -0,0 +1,6 @@
+program defaultvalueisvariablestartingwithnumber ! Tests that the default value cannot be set to an invalid variable name
+
+end program defaultvalueisvariablestartingwithnumber
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer :: y, 0, 1defval, fail-final
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test19-fail-defaultvalueisrealwhentypeisinteger/add_subroutine_parameter_19.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test19-fail-defaultvalueisrealwhentypeisinteger/add_subroutine_parameter_19.f90
new file mode 100644
index 00000000..d4d2534b
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test19-fail-defaultvalueisrealwhentypeisinteger/add_subroutine_parameter_19.f90
@@ -0,0 +1,6 @@
+program defaultvalueisrealforinteger ! Tests that an integer cannot be given a real default value.
+
+end program defaultvalueisrealforinteger
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer :: y, 0, 1.7, fail-final
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test2-updatecallsite/add_subroutine_parameter_2.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test2-updatecallsite/add_subroutine_parameter_2.f90
new file mode 100644
index 00000000..9f7df918
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test2-updatecallsite/add_subroutine_parameter_2.f90
@@ -0,0 +1,7 @@
+program updatecallsite ! Tests that the call site is updated appropriately - basic.
+ implicit none
+ call sub(2)
+end program updatecallsite
+subroutine sub(z) !<<<<< 5, 1, 5, 5, integer; intent(in) :: y, 0, 0, pass
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test2-updatecallsite/add_subroutine_parameter_2.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test2-updatecallsite/add_subroutine_parameter_2.f90.result
new file mode 100644
index 00000000..80ad088b
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test2-updatecallsite/add_subroutine_parameter_2.f90.result
@@ -0,0 +1,8 @@
+program updatecallsite ! Tests that the call site is updated appropriately - basic.
+ implicit none
+ call sub(0,2)
+end program updatecallsite
+subroutine sub(y,z) !<<<<< 5, 1, 5, 5, integer; intent(in) :: y, 0, 0, pass
+ integer, intent(in) :: y
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test20-fail-defaultvalueisnumberwhentypeisnonnumber/add_subroutine_parameter_20.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test20-fail-defaultvalueisnumberwhentypeisnonnumber/add_subroutine_parameter_20.f90
new file mode 100644
index 00000000..9374ac3a
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test20-fail-defaultvalueisnumberwhentypeisnonnumber/add_subroutine_parameter_20.f90
@@ -0,0 +1,6 @@
+program defaultvalueisnumberfornonnumbertype ! Tests that non number types cannot be given a number as a default value.
+
+end program defaultvalueisnumberfornonnumbertype
+subroutine sub(z) !<<<<< 4, 1, 4, 5, logical :: y, 0, 1, fail-final
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test21-fail-defaultvalueisnullwhentypeisnotpointer/add_subroutine_parameter_21.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test21-fail-defaultvalueisnullwhentypeisnotpointer/add_subroutine_parameter_21.f90
new file mode 100644
index 00000000..efe67856
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test21-fail-defaultvalueisnullwhentypeisnotpointer/add_subroutine_parameter_21.f90
@@ -0,0 +1,6 @@
+program defaultvalueisnullfornonpointer ! Tests that null cannot be the default value for a non pointer
+
+end program defaultvalueisnullfornonpointer
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer :: y, 0, null, fail-final
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test22-basicpointer/add_subroutine_parameter_22.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test22-basicpointer/add_subroutine_parameter_22.f90
new file mode 100644
index 00000000..e7b08404
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test22-basicpointer/add_subroutine_parameter_22.f90
@@ -0,0 +1,6 @@
+program basicpointer ! Tests that pointers can be passed as a parameter.
+
+end program basicpointer
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer; intent(in); pointer :: y, 0, null, pass
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test22-basicpointer/add_subroutine_parameter_22.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test22-basicpointer/add_subroutine_parameter_22.f90.result
new file mode 100644
index 00000000..61a51df7
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test22-basicpointer/add_subroutine_parameter_22.f90.result
@@ -0,0 +1,7 @@
+program basicpointer ! Tests that pointers can be passed as a parameter.
+
+end program basicpointer
+subroutine sub(y,z) !<<<<< 4, 1, 4, 5, integer; intent(in); pointer :: y, 0, null, pass
+ integer, intent(in), pointer :: y
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test3-updatecallsitewithorder/add_subroutine_parameter_3.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test3-updatecallsitewithorder/add_subroutine_parameter_3.f90
new file mode 100644
index 00000000..fad689b3
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test3-updatecallsitewithorder/add_subroutine_parameter_3.f90
@@ -0,0 +1,7 @@
+program updatecallsitewithorder ! Tests that the position of the parameter is correctly set.
+ implicit none
+ call sub(2)
+end program updatecallsitewithorder
+subroutine sub(z) !<<<<< 5, 1, 5, 5, integer; intent(in) :: y, 1, 0, pass
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test3-updatecallsitewithorder/add_subroutine_parameter_3.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test3-updatecallsitewithorder/add_subroutine_parameter_3.f90.result
new file mode 100644
index 00000000..d6a7c87b
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test3-updatecallsitewithorder/add_subroutine_parameter_3.f90.result
@@ -0,0 +1,8 @@
+program updatecallsitewithorder ! Tests that the position of the parameter is correctly set.
+ implicit none
+ call sub(2,0)
+end program updatecallsitewithorder
+subroutine sub(z,y) !<<<<< 5, 1, 5, 5, integer; intent(in) :: y, 1, 0, pass
+ integer, intent(in) :: y
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test4-fail-negativeposition/add_subroutine_parameter_4.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test4-fail-negativeposition/add_subroutine_parameter_4.f90
new file mode 100644
index 00000000..5c385577
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test4-fail-negativeposition/add_subroutine_parameter_4.f90
@@ -0,0 +1,6 @@
+program negativeposition ! Tests that the refactoring fails with negative positions requested.
+
+end program negativeposition
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer; intent(in) :: y, -1, 0, fail-final
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test5-fail-outofboundsposition/add_subroutine_parameter_5.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test5-fail-outofboundsposition/add_subroutine_parameter_5.f90
new file mode 100644
index 00000000..0f8e0e45
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test5-fail-outofboundsposition/add_subroutine_parameter_5.f90
@@ -0,0 +1,6 @@
+program outofbounds ! Tests that the refactoring fails for requests to place the new parameter in a position that is out of bounds.
+
+end program outofbounds
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer; intent(in) :: y, 3, 0, fail-final
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test6-fail-whitespacedefaultvalue/add_subroutine_parameter_6.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test6-fail-whitespacedefaultvalue/add_subroutine_parameter_6.f90
new file mode 100644
index 00000000..da6ea2bf
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test6-fail-whitespacedefaultvalue/add_subroutine_parameter_6.f90
@@ -0,0 +1,6 @@
+program whitespacedefaultvalue ! Tests that the refactoring does not allow the default value to be white space
+
+end program whitespacedefaultvalue
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer; intent(in) :: y, 0, , fail-final
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test7-basicarray/add_subroutine_parameter_7.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test7-basicarray/add_subroutine_parameter_7.f90
new file mode 100644
index 00000000..88457cf0
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test7-basicarray/add_subroutine_parameter_7.f90
@@ -0,0 +1,6 @@
+program basicarray ! Tests that arrays can be passed.
+
+end program basicarray
+subroutine sub(z) !<<<<< 4, 1, 4, 5, integer; intent(in); dimension(2) :: y, 0, (/ 2; 3 /), pass
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test7-basicarray/add_subroutine_parameter_7.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test7-basicarray/add_subroutine_parameter_7.f90.result
new file mode 100644
index 00000000..eb316a09
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test7-basicarray/add_subroutine_parameter_7.f90.result
@@ -0,0 +1,7 @@
+program basicarray ! Tests that arrays can be passed.
+
+end program basicarray
+subroutine sub(y,z) !<<<<< 4, 1, 4, 5, integer; intent(in); dimension(2) :: y, 0, (/ 2; 3 /), pass
+ integer, intent(in), dimension(2) :: y
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test8-logicalbasic/add_subroutine_parameter_8.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test8-logicalbasic/add_subroutine_parameter_8.f90
new file mode 100644
index 00000000..c29c9294
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test8-logicalbasic/add_subroutine_parameter_8.f90
@@ -0,0 +1,6 @@
+program logicalbasic ! Tests that logical parameters work correctly.
+
+end program logicalbasic
+subroutine sub(z) !<<<<< 4, 1, 4, 5, logical; intent(in) :: y, 0, .true., pass
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test8-logicalbasic/add_subroutine_parameter_8.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test8-logicalbasic/add_subroutine_parameter_8.f90.result
new file mode 100644
index 00000000..8e0040f1
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test8-logicalbasic/add_subroutine_parameter_8.f90.result
@@ -0,0 +1,7 @@
+program logicalbasic ! Tests that logical parameters work correctly.
+
+end program logicalbasic
+subroutine sub(y,z) !<<<<< 4, 1, 4, 5, logical; intent(in) :: y, 0, .true., pass
+ logical, intent(in) :: y
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test9-dontsetvariabletype/add_subroutine_parameter_9.f90 b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test9-dontsetvariabletype/add_subroutine_parameter_9.f90
new file mode 100644
index 00000000..94c832bf
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test9-dontsetvariabletype/add_subroutine_parameter_9.f90
@@ -0,0 +1,6 @@
+program dontsetvariabletype ! Tests that the default variable type is set to real
+
+end program dontsetvariabletype
+subroutine sub(z) !<<<<< 4, 1, 4, 5, intent(in) :: y, 0, 3, pass
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test9-dontsetvariabletype/add_subroutine_parameter_9.f90.result b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test9-dontsetvariabletype/add_subroutine_parameter_9.f90.result
new file mode 100644
index 00000000..e200fa0f
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/refactoring-test-code/add-subroutine-parameter/test9-dontsetvariabletype/add_subroutine_parameter_9.f90.result
@@ -0,0 +1,7 @@
+program dontsetvariabletype ! Tests that the default variable type is set to real
+
+end program dontsetvariabletype
+subroutine sub(y,z) !<<<<< 4, 1, 4, 5, intent(in) :: y, 0, 3, pass
+ real, intent(in) :: y
+ integer, intent(in) :: z
+end subroutine
diff --git a/org.eclipse.photran.core.vpg.tests/src/org/eclipse/photran/internal/tests/refactoring/AddSubroutineParameterTestSuite.java b/org.eclipse.photran.core.vpg.tests/src/org/eclipse/photran/internal/tests/refactoring/AddSubroutineParameterTestSuite.java
new file mode 100644
index 00000000..354d3cf9
--- /dev/null
+++ b/org.eclipse.photran.core.vpg.tests/src/org/eclipse/photran/internal/tests/refactoring/AddSubroutineParameterTestSuite.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Joe Handzik, Joe Gonzales, Marc Celani, and Jason Patel.
+ * 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:
+ * Joe Handzik, Joe Gonzales, Marc Celani, and Jason Patel - Initial API and 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.AddSubroutineParameterRefactoring;
+import org.eclipse.photran.internal.tests.Activator;
+import org.eclipse.photran.internal.tests.PhotranRefactoringTestSuiteFromMarkers;
+
+/**
+ *
+ * @author Marc Celani, Joe Handzik, Joe Gonzalez, Jason Patel
+ */
+public class AddSubroutineParameterTestSuite extends
+ PhotranRefactoringTestSuiteFromMarkers<AddSubroutineParameterRefactoring>
+{
+ private static final String DIR = "refactoring-test-code/add-subroutine-parameter";
+
+ public static Test suite() throws Exception
+ {
+ return new AddSubroutineParameterTestSuite();
+ }
+
+ public AddSubroutineParameterTestSuite() throws Exception
+ {
+ super(Activator.getDefault(), "Running Add Subroutine Parameter refactoring in", DIR,
+ AddSubroutineParameterRefactoring.class);
+ }
+
+ @Override
+ protected boolean configureRefactoring(AddSubroutineParameterRefactoring refactoring,
+ IFile file, TextSelection selection, String[] markerText)
+ {
+ boolean shouldSucceed = super
+ .configureRefactoring(refactoring, file, selection, markerText);
+ refactoring.setDeclaration(markerText[4].replaceAll(";", ","));
+ refactoring.setPosition(Integer.parseInt(markerText[5]));
+ if (!markerText[6].equals("_dont_call")) refactoring.setDefaultValue(markerText[6]);
+
+ return shouldSucceed;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/AddSubroutineParameterRefactoring.java b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/AddSubroutineParameterRefactoring.java
new file mode 100644
index 00000000..7b9eb7cc
--- /dev/null
+++ b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/AddSubroutineParameterRefactoring.java
@@ -0,0 +1,653 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Joe Handzik, Joe Gonzales, Marc Celani, and Jason Patel.
+ * 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:
+ * Joe Handzik, Joe Gonzales, Marc Celani, and Jason Patel - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.photran.internal.core.refactoring;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+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.ltk.core.refactoring.RefactoringStatusContext;
+import org.eclipse.photran.internal.core.analysis.binding.Definition;
+import org.eclipse.photran.internal.core.analysis.binding.ScopingNode;
+import org.eclipse.photran.internal.core.lexer.Terminal;
+import org.eclipse.photran.internal.core.lexer.Token;
+import org.eclipse.photran.internal.core.parser.ASTCallStmtNode;
+import org.eclipse.photran.internal.core.parser.ASTEntityDeclNode;
+import org.eclipse.photran.internal.core.parser.ASTIntConstNode;
+import org.eclipse.photran.internal.core.parser.ASTListNode;
+import org.eclipse.photran.internal.core.parser.ASTSeparatedListNode;
+import org.eclipse.photran.internal.core.parser.ASTSubroutineArgNode;
+import org.eclipse.photran.internal.core.parser.ASTSubroutineParNode;
+import org.eclipse.photran.internal.core.parser.ASTSubroutineStmtNode;
+import org.eclipse.photran.internal.core.parser.ASTSubroutineSubprogramNode;
+import org.eclipse.photran.internal.core.parser.ASTTypeDeclarationStmtNode;
+import org.eclipse.photran.internal.core.parser.IASTListNode;
+import org.eclipse.photran.internal.core.parser.IASTNode;
+import org.eclipse.photran.internal.core.parser.IBodyConstruct;
+import org.eclipse.photran.internal.core.refactoring.infrastructure.FortranEditorRefactoring;
+import org.eclipse.photran.internal.core.reindenter.Reindenter;
+import org.eclipse.photran.internal.core.vpg.PhotranTokenRef;
+import org.eclipse.photran.internal.core.vpg.PhotranVPG;
+
+/**
+ *
+ *
+ * This refactoring allows a user to select a subroutine and to add a new parameter to the list. The
+ * refactoring will ask for a declaration line for the parameter, a default value with which to
+ * update all callers of the subroutine, and a position in the list at which to add the new
+ * parameter. The refactoring ensures that the declaration line is valid, contains some logic to
+ * ensure that the default value matches the appropriate type, and ensures that the position is in
+ * bounds. It then updates the subroutine signature and updates the callers of the subroutine. If
+ * the callers specify the variable name in the call list, the refactoring will match this pattern.
+ *
+ * @author Joe Handzik, Joe Gonzales, Marc Celani, Jason Patel
+ */
+public class AddSubroutineParameterRefactoring extends FortranEditorRefactoring
+{
+ private ASTSubroutineStmtNode selectedSubroutine;
+
+ private List<ASTSubroutineParNode> oldParameterList;
+
+ private List<ASTSubroutineParNode> newParameterList;
+
+ private int position = 0;
+
+ private String parameterName = null;
+
+ private String declaration = "integer, intent(in) :: newName"; //$NON-NLS-1$
+
+ private String defaultValue = "0"; //$NON-NLS-1$
+
+ private ASTTypeDeclarationStmtNode declStmt = null;
+
+ private String type = "integer"; //$NON-NLS-1$
+
+ public List<ASTSubroutineParNode> getOldParameterList()
+ {
+ return oldParameterList;
+ }
+
+ public String getDeclaration()
+ {
+ assert declaration != null;
+ return this.declaration;
+ }
+
+ public int getPosition()
+ {
+ return this.position;
+ }
+
+ public String getDefault()
+ {
+ assert defaultValue != null;
+ return this.defaultValue;
+ }
+
+ public void setPosition(int position)
+ {
+ this.position = position;
+ }
+
+ /*
+ * Sets the declaration member, but first checks that an appropriate type is at the beggining of
+ * the declaration. If not, it assumes that "real" should be prepended. The type member is then
+ * set to this type.
+ *
+ * @param declaration The declaration to be set.
+ */
+ public void setDeclaration(String declaration)
+ {
+ // Add "real" to all declaration lines that do not specify a type to avoid parser errors.
+
+ String[] declArgs = declaration.split(","); //$NON-NLS-1$
+ String[] validTypes = { "integer", "real", "logical", "double", "character" }; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ boolean hasTypeDefined = false;
+ for (int i = 0; i < validTypes.length; i++)
+ {
+ if (validTypes[i].equals(declArgs[0]))
+ {
+ hasTypeDefined = true;
+ type = declArgs[0];
+ break;
+ }
+ }
+
+ if (!hasTypeDefined)
+ {
+ type = "real"; //$NON-NLS-1$
+ if (declArgs.length == 1)
+ declaration = "real, " + declaration; //$NON-NLS-1$
+ else
+ declaration = "real" + " :: " + declaration; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ this.declaration = declaration;
+ }
+
+ public void setDefaultValue(String defValue)
+ {
+ defaultValue = defValue;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring#doCheckInitialConditions(
+ * org.eclipse.ltk.core.refactoring.RefactoringStatus,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm)
+ throws org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring.PreconditionFailure
+ {
+ ensureProjectHasRefactoringEnabled(status);
+
+ ensureSubroutineIsSelected();
+
+ if (!matchingDeclarationsInInterfacesUniquelyBind())
+ status
+ .addWarning(Messages.AddSubroutineParameterRefactoring_matchingDeclarationsDoNotUniquelyBind);
+
+ oldParameterList = getSubroutineParameters();
+ }
+
+ /*
+ * By looking at the AST tree, starting at the node supplied to the refactoring as the selected
+ * node, this method determines if a subroutine node has been selected or not.
+ */
+ private void ensureSubroutineIsSelected()
+ throws org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring.PreconditionFailure
+ {
+ IASTNode temporaryNode = findEnclosingNode(astOfFileInEditor, selectedRegionInEditor);
+
+ if (temporaryNode == null)
+ fail(Messages.AddSubroutineParameterRefactoring_selectSubroutineError);
+
+ if (temporaryNode instanceof ASTSubroutineSubprogramNode)
+ selectedSubroutine = ((ASTSubroutineSubprogramNode)temporaryNode).getSubroutineStmt();
+ else if (temporaryNode instanceof ASTSubroutineStmtNode)
+ {
+ if (temporaryNode.findNearestAncestor(ASTSubroutineSubprogramNode.class) == null)
+ fail(Messages.AddSubroutineParameterRefactoring_selectSubroutineError);
+ selectedSubroutine = (ASTSubroutineStmtNode)temporaryNode;
+ }
+ else
+ fail(Messages.AddSubroutineParameterRefactoring_selectSubroutineError);
+ }
+
+ /*
+ * This method determines if a matching declaration already exists in scope, and if so, will
+ * fail the refactoring.
+ */
+ private boolean matchingDeclarationsInInterfacesUniquelyBind()
+ {
+ for (Definition declaration : getInterfaceDeclarations())
+ if (declaration.resolveInterfaceBinding().size() != 1) return false;
+
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring#doCheckFinalConditions(org
+ * .eclipse.ltk.core.refactoring.RefactoringStatus, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ protected void doCheckFinalConditions(RefactoringStatus status, IProgressMonitor pm)
+ throws org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring.PreconditionFailure
+ {
+ ensureDeclarationIsValid();
+
+ parameterName = declStmt.getEntityDeclList().get(0).getObjectName().getObjectName()
+ .getText();
+
+ ensurePositionIsValid();
+
+ ensureDefaultValueIsValid();
+
+ checkForConflictingBindings(pm, status);
+ }
+
+ /*
+ * This method ensures that the default value supplied is valid by applying logic that tests
+ * whether or not the default type supplied matches the type supplied in the declaration line.
+ * For example, .true. and .false. are reserved for logical types. This method also ensures that
+ * the default value is not a variable name beginning with a number.
+ */
+ private void ensureDefaultValueIsValid()
+ throws org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring.PreconditionFailure
+ {
+ if (defaultValue == null || defaultValue.equals("") || //$NON-NLS-1$
+ isWhiteSpace(defaultValue) || isVariableNameBeginningWithNumber(defaultValue)
+ || (isTrueOrFalse(defaultValue) && !type.equals("logical")) || //$NON-NLS-1$
+ (isANumber(defaultValue) && (!type.equals("integer") && !type.equals("real"))) || //$NON-NLS-1$//$NON-NLS-2$
+ (isRealAndNotInteger(defaultValue) && type.equals("integer")) || //$NON-NLS-1$
+ (defaultValue.equals("null") && !declaration.contains("pointer"))) //$NON-NLS-1$ //$NON-NLS-2$
+ fail(Messages.AddSubroutineParameterRefactoring_InvalidDefaultValue);
+ }
+
+ /*
+ * @param str A string to be tested
+ *
+ * @return <code> true </code> if the selected string is a real number, and <code> false </code>
+ * if the selected string is ann integer or not a number.
+ */
+ private boolean isRealAndNotInteger(String str)
+ {
+ if (isANumber(str))
+ {
+ try
+ {
+ Integer.parseInt(str);
+ }
+ catch (NumberFormatException e)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /*
+ * @param str A string to be tested
+ *
+ * @return <code> true </code> if the selected string is ".true." or ".false.", and <code> false
+ * </code> if the selected string is anything else.
+ */
+ private boolean isTrueOrFalse(String str)
+ {
+ if (str == null) return false;
+ return str.equals(".true.") || str.equals(".false."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /*
+ * @param str A string to be tested
+ *
+ * @return <code> true </code> if the string begins with a number but is not a number (hence, a
+ * variable name beginning with a number) and <code> false </code> otherwise.
+ */
+ private boolean isVariableNameBeginningWithNumber(String str)
+ {
+ if (str != null)
+ {
+ if (str.length() != 0)
+ {
+ if (isANumber(str.substring(0, 1)))
+ {
+ if (!isANumber(str)) return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /*
+ * @param str A string
+ *
+ * @return <code> true </code> if str is a number.
+ */
+ private boolean isANumber(String str)
+ {
+ try
+ {
+ Double.parseDouble(str);
+ }
+ catch (NumberFormatException e)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ /*
+ * This function ensures that the position given to the refactoring is in bounds for the current
+ * size of the list, and if not, fails the refactoring.
+ */
+ private void ensurePositionIsValid()
+ throws org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring.PreconditionFailure
+ {
+ if (position > oldParameterList.size() || position < 0)
+ fail(Messages.AddSubroutineParameterRefactoring_InvalidParameterPosition);
+ }
+
+ /*
+ * This function attempts to produce a declaration node by passing the declaration line on to a
+ * parser. If this node is returned as an error node, the refactoring fails.
+ */
+ private void ensureDeclarationIsValid()
+ throws org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring.PreconditionFailure
+ {
+ IBodyConstruct decl = parseLiteralStatementNoFail(declaration);
+ if (decl == null || !(decl instanceof ASTTypeDeclarationStmtNode))
+ fail(Messages.AddSubroutineParameterRefactoring_InvalidDeclaration);
+ declStmt = (ASTTypeDeclarationStmtNode)decl;
+ IASTListNode<ASTEntityDeclNode> entityDeclList = declStmt.getEntityDeclList();
+ if (entityDeclList == null)
+ {
+ fail(Messages.AddSubroutineParameterRefactoring_InvalidDeclaration);
+ }
+ }
+
+ /*
+ * This function checks to see whether or not the variable name supplied to the refactoring is
+ * already in scope in the subroutine.
+ */
+ private void checkForConflictingBindings(IProgressMonitor pm, RefactoringStatus status)
+ {
+ Definition def = arbitraryDefinitionInScope();
+ if (def == null) return; // No declarations in scope, so the new one can't conflict
+
+ checkForConflictingBindings(pm, new ConflictingBindingErrorHandler(status), def,
+ Collections.<PhotranTokenRef> emptyList(), parameterName);
+ }
+
+ /*
+ * This function returns an arbitrary definition line in scope of the current node. It is used
+ * to iterate through the declarations to see if there are any conflicts.
+ */
+ private Definition arbitraryDefinitionInScope()
+ {
+ ScopingNode enclosingScope = selectedSubroutine.findNearestAncestor(ScopingNode.class);
+ List<Definition> allDefs = enclosingScope.getAllDefinitions();
+ if (allDefs.isEmpty())
+ return null;
+ else
+ return allDefs.get(0);
+ }
+
+ /*
+ * @param str A string
+ *
+ * @return <code> true </code> if str is only white space. This is used to test if default
+ * values are nothing but white space.
+ */
+ private boolean isWhiteSpace(String str)
+ {
+ return str.replace(" ", "").replace("\t", "").equals(""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.rephraserengine.core.vpg.refactoring.VPGRefactoring#doCreateChange(org.eclipse
+ * .core.runtime.IProgressMonitor)
+ */
+ @Override
+ protected void doCreateChange(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException
+ {
+
+ buildNewParameterListWithNewParameter();
+
+ // Change the arguments list to the new list
+ permuteArgumentList(selectedSubroutine);
+
+ addArgumentDeclaration(selectedSubroutine);
+
+ permuteCallSites();
+
+ addChangeFromModifiedAST(fileInEditor, pm);
+ vpg.releaseAST(fileInEditor);
+
+ }
+
+ /*
+ * This function adds the declaration line to the subroutine.
+ */
+ private void addArgumentDeclaration(ASTSubroutineStmtNode subroutineStatement)
+ {
+ ASTSubroutineSubprogramNode subroutine = (ASTSubroutineSubprogramNode)subroutineStatement
+ .getParent();
+
+ IASTListNode<IBodyConstruct> statements = subroutine.getBody();
+ if (statements == null)
+ {
+ statements = new ASTListNode<IBodyConstruct>();
+ subroutine.setBody(statements);
+ }
+
+ statements.add(0, declStmt);
+ Reindenter.reindent(declStmt, astOfFileInEditor);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ltk.core.refactoring.Refactoring#getName()
+ */
+ @Override
+ public String getName()
+ {
+ return Messages.AddSubroutineParameterRefactoring_Name;
+ }
+
+ /*
+ * This function returns the list of subroutine parameters from the selected subroutine node.
+ */
+ public List<ASTSubroutineParNode> getSubroutineParameters()
+ {
+ if (selectedSubroutine.getSubroutinePars() != null)
+ return selectedSubroutine.getSubroutinePars();
+
+ return new ArrayList<ASTSubroutineParNode>();
+ }
+
+ /*
+ * This function returns a collection of interface declarations.
+ */
+ private Collection<Definition> getInterfaceDeclarations()
+ {
+ List<Definition> subroutineDefinitions = selectedSubroutine.getSubroutineName()
+ .getSubroutineName().resolveBinding();
+
+ if (subroutineDefinitions.size() != 1) return new ArrayList<Definition>();
+
+ return subroutineDefinitions.get(0).findMatchingDeclarationsInInterfaces();
+ }
+
+ /*
+ * This function builds the new parameter list to be supplied to the subroutine node by adding
+ * the new parameter to the list in the appropriate position.
+ */
+ public void buildNewParameterListWithNewParameter()
+ {
+ // Create new variable
+ ASTSubroutineParNode newParameter = new ASTSubroutineParNode();
+ Token variableName = generateVariableName();
+ newParameter.setVariableName(variableName);
+
+ // Create new list
+ newParameterList = new ArrayList<ASTSubroutineParNode>(oldParameterList);
+ newParameterList.add(position, newParameter);
+
+ }
+
+ /*
+ * This function returns a token for a variable with the name of the new parameter name.
+ */
+ private Token generateVariableName()
+ {
+ Token variableName = new Token(Terminal.T_IDENT, parameterName);
+ return variableName;
+ }
+
+ /*
+ * This function changes the argument list of the subroutine statement node to the new list
+ * generated in buildNewParameterListWithNewParameter()
+ */
+ protected void permuteArgumentList(ASTSubroutineStmtNode node)
+ {
+ ASTSeparatedListNode<ASTSubroutineParNode> newParameterList = new ASTSeparatedListNode<ASTSubroutineParNode>(
+ new Token(Terminal.T_COMMA, ","), this.newParameterList); //$NON-NLS-1$
+ node.setSubroutinePars(newParameterList);
+ }
+
+ /*
+ * This function changes all call sites to be updated to have the new argument in place, and
+ * will match any calling pattern currently used.
+ */
+ private void permuteCallSites()
+ {
+ for (ASTCallStmtNode callStmt : getCallSites())
+ {
+ int previousArgumentListSize = 0;
+
+ if (callStmt.getArgList() != null)
+ {
+ previousArgumentListSize = callStmt.getArgList().size();
+ }
+
+ // Generate new IExpression Node for the default value
+ ASTIntConstNode expr = new ASTIntConstNode();
+ expr.setIntConst(new Token(Terminal.T_ICON, defaultValue));
+ ASTSubroutineArgNode addedParArg = new ASTSubroutineArgNode();
+ addedParArg.setExpr(expr);
+
+ // Test to see if the call site is using the
+ // "(variableName = value, variablename = value)" pattern, or simply the
+ // "(value, value)" pattern
+ // The new parameter should follow this pattern at the call site, and should assume the
+ // (value) pattern if the list was previously empty.
+ if (previousArgumentListSize > 0)
+ {
+ int positionToCompareTo = Math.min(position, previousArgumentListSize - 1);
+ ASTSubroutineParNode firstParameter = oldParameterList.get(positionToCompareTo);
+ ASTSubroutineArgNode firstParameterArgument = getActualArgFromCallStmt(callStmt,
+ firstParameter.getVariableName(), positionToCompareTo);
+ if (firstParameterArgument.getName() != null)
+ addedParArg.setName(new Token(Terminal.T_IDENT, parameterName));
+ }
+
+ ArrayList<ASTSubroutineArgNode> newParameterListForCallSite = new ArrayList<ASTSubroutineArgNode>();
+
+ for (int i = 0; i < previousArgumentListSize; i++)
+ {
+ ASTSubroutineParNode desiredPar = oldParameterList.get(i);
+ ASTSubroutineArgNode desiredParArgument = getActualArgFromCallStmt(callStmt,
+ desiredPar.getVariableName(), i);
+ newParameterListForCallSite.add(desiredParArgument);
+ }
+
+ newParameterListForCallSite.add(position, addedParArg);
+
+ ASTSeparatedListNode<ASTSubroutineArgNode> newArgList = new ASTSeparatedListNode<ASTSubroutineArgNode>(
+ new Token(Terminal.T_COMMA, ","), newParameterListForCallSite); //$NON-NLS-1$
+ callStmt.setArgList(newArgList);
+ }
+ }
+
+ /*
+ * This function returns the set of call sites for the subroutine that was selected.
+ */
+ private Set<ASTCallStmtNode> getCallSites()
+ {
+ List<Definition> subroutineDefinitions = selectedSubroutine.getSubroutineName()
+ .getSubroutineName().resolveBinding();
+ HashSet<ASTCallStmtNode> result = new HashSet<ASTCallStmtNode>();
+
+ if (subroutineDefinitions.size() != 1) return result;
+
+ for (PhotranTokenRef tokenRef : subroutineDefinitions.get(0).findAllReferences(true))
+ {
+ Token token = tokenRef.findToken();
+
+ ASTCallStmtNode callStmtNode = token.findNearestAncestor(ASTCallStmtNode.class);
+
+ if (callStmtNode != null) result.add(callStmtNode);
+ }
+
+ return result;
+ }
+
+ /*
+ * This function gets an argument from a call statement, in order to check if it follows the
+ * pattern of "Variablename = Value".
+ */
+ private ASTSubroutineArgNode getActualArgFromCallStmt(ASTCallStmtNode callStmt,
+ Token desiredParName, int desiredParIndex)
+ {
+ for (int i = 0; i < callStmt.getArgList().size(); i++)
+ {
+ ASTSubroutineArgNode argument = callStmt.getArgList().get(i);
+ if (argument.getName() == null || desiredParName == null)
+ {
+ if (i == desiredParIndex) return argument;
+ }
+ else
+ {
+ String argumentName = PhotranVPG.canonicalizeIdentifier(argument.getName()
+ .getText());
+ String parameterName = PhotranVPG.canonicalizeIdentifier(desiredParName.getText());
+ if (argumentName.equals(parameterName)) return argument;
+ }
+ }
+ return null;
+ }
+
+ /*
+ * This class handles all error cases for conflicting variable names or bindings.
+ */
+ private final class ConflictingBindingErrorHandler implements IConflictingBindingCallback
+ {
+ private final RefactoringStatus status;
+
+ private ConflictingBindingErrorHandler(RefactoringStatus status)
+ {
+ this.status = status;
+ }
+
+ public void addConflictError(List<Conflict> conflictingDef)
+ {
+ Conflict conflict = conflictingDef.get(0);
+
+ String msg = Messages.bind(
+ Messages.AddSubroutineParameterRefactoring_NameConflictsWith, conflict.name,
+ vpg.getDefinitionFor(conflict.tokenRef));
+ RefactoringStatusContext context = createContext(conflict.tokenRef); // Highlights
+ // problematic
+ // definition
+ status.addError(msg, context);
+ }
+
+ public void addConflictWarning(List<Conflict> conflictingDef)
+ {
+ Conflict conflict = conflictingDef.get(0);
+
+ String msg = Messages.bind(
+ Messages.AddSubroutineParameterRefactoring_NameMightConflictWithSubprogram,
+ conflict.name);
+ RefactoringStatusContext context = createContext(conflict.tokenRef); // Highlights
+ // problematic
+ // definition
+ status.addWarning(msg, context);
+ }
+
+ public void addReferenceWillChangeError(String newName, Token reference)
+ {
+ throw new IllegalStateException();
+ }
+ }
+
+}
diff --git a/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/Messages.java b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/Messages.java
index cb39b8d0..8e51bfaf 100644
--- a/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/Messages.java
+++ b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/Messages.java
@@ -64,6 +64,22 @@ public class Messages extends NLS
public static String AddOnlyToUseStmtRefactoring_ProjectDoesNotExist;
public static String AddOnlyToUseStmtRefactoring_SelectModuleName;
+
+ public static String AddSubroutineParameterRefactoring_InvalidDeclaration;
+
+ public static String AddSubroutineParameterRefactoring_InvalidDefaultValue;
+
+ public static String AddSubroutineParameterRefactoring_InvalidParameterPosition;
+
+ public static String AddSubroutineParameterRefactoring_matchingDeclarationsDoNotUniquelyBind;
+
+ public static String AddSubroutineParameterRefactoring_Name;
+
+ public static String AddSubroutineParameterRefactoring_NameConflictsWith;
+
+ public static String AddSubroutineParameterRefactoring_NameMightConflictWithSubprogram;
+
+ public static String AddSubroutineParameterRefactoring_selectSubroutineError;
public static String EncapsulateVariableRefactoring_CannotEncapsulateArrays;
diff --git a/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/messages.properties b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/messages.properties
index cf0ad070..3de7224c 100644
--- a/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/messages.properties
+++ b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/messages.properties
@@ -21,6 +21,14 @@ AddOnlyToUseStmtRefactoring_Parsing=Parsing
AddOnlyToUseStmtRefactoring_PleaseSelectModuleName=Please select a module name.
AddOnlyToUseStmtRefactoring_ProjectDoesNotExist=Project does not exist\!
AddOnlyToUseStmtRefactoring_SelectModuleName=Please select the name of the module in the USE statement.
+AddSubroutineParameterRefactoring_InvalidDeclaration=Invalid declaration line for new parameter.
+AddSubroutineParameterRefactoring_InvalidDefaultValue=Invalid default value for this parameter for all callers of this subroutine.
+AddSubroutineParameterRefactoring_InvalidParameterPosition=Parameter position is out of bounds.
+AddSubroutineParameterRefactoring_matchingDeclarationsDoNotUniquelyBind=Matching declarations in interface blocks do not uniquely bind to the selected subroutine.
+AddSubroutineParameterRefactoring_Name=Add Subroutine Parameter
+AddSubroutineParameterRefactoring_NameConflictsWith=The name "{0}" conflicts with {1}
+AddSubroutineParameterRefactoring_NameMightConflictWithSubprogram=Name might have conflict with subprogram.
+AddSubroutineParameterRefactoring_selectSubroutineError=Please select a subroutine definition.
PermuteSubroutineArgsRefactoring_matchingDeclarationsDoNotUniquelyBind=Matching declarations in interface blocks do not uniquely bind to the selected subroutine.
PermuteSubroutineArgsRefactoring_name=Permute Subroutine Arguments
PermuteSubroutineArgsRefactoring_selectedTextNotSubroutine=The selected text is not a subroutine. Please select a subroutine.
diff --git a/org.eclipse.photran.ui.vpg/OSGI-INF/l10n/bundle.properties b/org.eclipse.photran.ui.vpg/OSGI-INF/l10n/bundle.properties
index bfaced73..f4ea318b 100644
--- a/org.eclipse.photran.ui.vpg/OSGI-INF/l10n/bundle.properties
+++ b/org.eclipse.photran.ui.vpg/OSGI-INF/l10n/bundle.properties
@@ -3,19 +3,19 @@ category.name = Fortran Refactoring Commands
command.name = Rename...
command.name.0 = Extract Procedure...
command.name.1 = Extract Local Variable...
+command.name.21 = Add Subroutine Parameter...
actionSet.description = Fortran Refactorings
actionSet.label = Fortran Refactorings
action.label = Re&name...
action.label.0 = E&xtract Procedure...
action.label.1 = Extract &Local Variable...
+action.label.21 = Add Subrouti&ne Parameter...
page.name = Analysis/Refactoring
category.description = Navigation
category.name.0 = Navigation
command.description = Open Declaration
-command.name.2 = Open Declaration
actionSet.description.0 = Fortran Analysis Actions
actionSet.label.0 = Fortran Analysis Actions
-action.label.2 = &Open Declaration
action.label.3 = &Open Declaration
extension.name = Fortran Search
page.label = Fortran Search
diff --git a/org.eclipse.photran.ui.vpg/plugin.xml b/org.eclipse.photran.ui.vpg/plugin.xml
index 03b68e1c..2c3231aa 100644
--- a/org.eclipse.photran.ui.vpg/plugin.xml
+++ b/org.eclipse.photran.ui.vpg/plugin.xml
@@ -24,11 +24,14 @@
<group>
<submenu name="Subprogram"><!-- Refactorings that change subprograms -->
<editorRefactoring
- class = "org.eclipse.photran.internal.core.refactoring.SafeDeleteInternalSubprogramRefactoring"
+ command="org.eclipse.photran.ui.AddSubroutineParameterRefactoringCommand"
+ />
+ <editorRefactoring
+ class="org.eclipse.photran.internal.core.refactoring.PermuteSubroutineArgsRefactoring"
+ inputPage="org.eclipse.photran.internal.ui.refactoring.PermuteSubroutineArgsInputPage"
/>
<editorRefactoring
- class="org.eclipse.photran.internal.core.refactoring.PermuteSubroutineArgsRefactoring"
- inputPage="org.eclipse.photran.internal.ui.refactoring.PermuteSubroutineArgsInputPage"
+ class = "org.eclipse.photran.internal.core.refactoring.SafeDeleteInternalSubprogramRefactoring"
/>
</submenu>
</group>
@@ -190,6 +193,11 @@
id="org.eclipse.photran.ui.RemoveAssignedGotoRefactoringCommand"
name="Remove Assigned Goto...">
</command>
+ <command
+ name="%command.name.21"
+ categoryId="org.eclipse.photran.ui.RefactoringCategory"
+ id="org.eclipse.photran.ui.AddSubroutineParameterRefactoringCommand">
+ </command>
</extension>
<!-- 2. Optionally associate the command with an accelerator key -->
@@ -219,6 +227,12 @@
contextId="org.eclipse.photran.ui.FortranEditorContext"
commandId="org.eclipse.photran.ui.IfConstructStatementConversionRefactoringCommand"
/>
+ <key
+ sequence="M3+M2+P"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ contextId="org.eclipse.photran.ui.FortranEditorContext"
+ commandId="org.eclipse.photran.ui.AddSubroutineParameterRefactoringCommand"
+ />
</extension>
<!-- 3. Add the command to Photran's Refactoring action set -->
@@ -254,6 +268,11 @@
definitionId="org.eclipse.photran.ui.RemoveAssignedGotoRefactoringCommand"
class="org.eclipse.photran.internal.ui.refactoring.RemoveAssignedGotoAction"
id="org.eclipse.photran.ui.RemoveAssignedGotoAction"/>
+ <action
+ label="%action.label.21"
+ definitionId="org.eclipse.photran.ui.AddSubroutineParameterRefactoringCommand"
+ class="org.eclipse.photran.internal.ui.refactoring.AddSubroutineParameterAction"
+ id="org.eclipse.photran.ui.AddSubroutineParameterRefactoringAction"/>
</actionSet>
</extension>
diff --git a/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/AddSubroutineParameterAction.java b/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/AddSubroutineParameterAction.java
new file mode 100644
index 00000000..193efefa
--- /dev/null
+++ b/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/AddSubroutineParameterAction.java
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Joe Handzik, Joe Gonzales, Marc Celani, and Jason Patel.
+ * 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:
+ * Joe Handzik, Joe Gonzales, Marc Celani, and Jason Patel - Initial API and implementation
+ *******************************************************************************/
+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.parser.ASTSubroutineParNode;
+import org.eclipse.photran.internal.core.refactoring.AddSubroutineParameterRefactoring;
+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.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IEditorActionDelegate;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+
+/**
+ * Handles the Add Subroutine Parameter action in the Fortran editor's Refactoring popup menu and in
+ * the Refactor menu in the workbench menu bar.
+ *
+ * @author Joe Handzik, Joe Gonzales, Marc Celani, Jason Patel
+ */
+public class AddSubroutineParameterAction extends AbstractFortranRefactoringActionDelegate
+ implements IWorkbenchWindowActionDelegate, IEditorActionDelegate
+{
+ public AddSubroutineParameterAction()
+ {
+ super(AddSubroutineParameterRefactoring.class,
+ FortranAddSubroutineParameterRefactoringWizard.class);
+ }
+
+ @Override
+ protected VPGRefactoring<IFortranAST, Token, PhotranVPG> getRefactoring(List<IFile> files)
+ {
+ AddSubroutineParameterRefactoring r = new AddSubroutineParameterRefactoring();
+ r.initialize(getFortranEditor().getIFile(), getFortranEditor().getSelection());
+ return r;
+ }
+
+ public static class FortranAddSubroutineParameterRefactoringWizard extends
+ AbstractFortranRefactoringWizard
+ {
+ protected AddSubroutineParameterRefactoring addSubRefactoring;
+
+ public FortranAddSubroutineParameterRefactoringWizard(AddSubroutineParameterRefactoring r)
+ {
+ super(r);
+ this.addSubRefactoring = r;
+ }
+
+ @Override
+ protected void doAddUserInputPages()
+ {
+ addPage(new UserInputWizardPage(addSubRefactoring.getName())
+ {
+ protected Text declField;
+
+ protected Text locationField;
+
+ protected Text defaultField;
+
+ public void createControl(Composite parent)
+ {
+ Composite group = new Composite(parent, SWT.NONE);
+ initializeDialogUnits(group);
+ setControl(group);
+ group.setLayout(new GridLayout(3, false));
+
+ GridData threeCol = new GridData();
+ threeCol.horizontalSpan = 3;
+
+ Label lbl = new Label(group, SWT.NONE);
+ lbl.setText(Messages.AddSubroutineParameterAction_DeclarationLabel);
+ Label lbl3 = new Label(group, SWT.NONE);
+ lbl3.setText(Messages.AddSubroutineParameterAction_DefaultLabel);
+ Label lbl2 = new Label(group, SWT.NONE);
+ lbl2.setText(Messages.AddSubroutineParameterAction_LocationLabel);
+
+ declField = new Text(group, SWT.BORDER);
+ declField.setText(addSubRefactoring.getDeclaration());
+ declField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ declField.selectAll();
+ declField.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ addSubRefactoring.setDeclaration(declField.getText());
+ }
+ });
+
+ defaultField = new Text(group, SWT.BORDER);
+ defaultField.setText(addSubRefactoring.getDefault());
+ defaultField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ defaultField.selectAll();
+ defaultField.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ addSubRefactoring.setDefaultValue(defaultField.getText());
+ }
+ });
+
+ locationField = new Text(group, SWT.BORDER);
+ locationField.setText(String.valueOf(addSubRefactoring.getPosition()));
+ locationField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ locationField.selectAll();
+ locationField.addModifyListener(new ModifyListener()
+ {
+ public void modifyText(ModifyEvent e)
+ {
+ addSubRefactoring.setPosition(Integer.parseInt(locationField.getText()));
+ }
+ });
+
+ // creates the table that lists the variables that exist in the subroutine
+ List<ASTSubroutineParNode> parList = addSubRefactoring.getOldParameterList();
+
+ GridData gridData = new GridData(GridData.VERTICAL_ALIGN_END);
+ gridData.horizontalSpan = 3;
+ gridData.horizontalAlignment = GridData.FILL;
+
+ Table table = new Table(group, SWT.BORDER);
+ table.setLinesVisible(true);
+ table.setHeaderVisible(true);
+ table.setLayoutData(gridData);
+ for (int i = 0; i < parList.size(); i++)
+ {
+ TableColumn column = new TableColumn(table, SWT.NONE);
+ column.setText(String.valueOf(i));
+ }
+ TableItem item = new TableItem(table, SWT.NONE);
+ for (int i = 0; i < parList.size(); i++)
+ {
+ item.setText(i, parList.get(i).getVariableName().getText());
+ }
+ for (int i = 0; i < parList.size(); i++)
+ {
+ table.getColumn(i).pack();
+ }
+
+ // Call once for sure, just in case the user doesn't modify the text
+ // addSubRefactoring.setDeclaration(declField.getText());
+
+ int offset = declField.getText().indexOf(":: "); //$NON-NLS-1$
+ if (offset < 0)
+ offset = 0;
+ else
+ offset = offset + ":: ".length(); //$NON-NLS-1$
+ declField.setSelection(offset, declField.getText().length());
+ declField.setFocus();
+ }
+ });
+ }
+ }
+}
diff --git a/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/Messages.java b/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/Messages.java
index b9771c72..e85cb8ad 100644
--- a/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/Messages.java
+++ b/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/Messages.java
@@ -111,6 +111,12 @@ public class Messages extends NLS
public static String RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickOKMessage;
public static String RemoveRealAndDoublePrecisionLoopCountersInputPage_ClickPreviewMessage;
+
+ public static String AddSubroutineParameterAction_DefaultLabel;
+
+ public static String AddSubroutineParameterAction_DeclarationLabel;
+
+ public static String AddSubroutineParameterAction_LocationLabel;
static
{
diff --git a/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/messages.properties b/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/messages.properties
index 164f6931..ae79f19d 100644
--- a/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/messages.properties
+++ b/org.eclipse.photran.ui.vpg/src/org/eclipse/photran/internal/ui/refactoring/messages.properties
@@ -41,3 +41,6 @@ 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.
+AddSubroutineParameterAction_DeclarationLabel=Declaration:
+AddSubroutineParameterAction_LocationLabel=Position:
+AddSubroutineParameterAction_DefaultLabel=Default Value:

Back to the top