diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/api/ui/JavaRefactoringActionsFactory.java b/refactoring.java/src/org/netbeans/modules/refactoring/java/api/ui/JavaRefactoringActionsFactory.java
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/api/ui/JavaRefactoringActionsFactory.java
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/api/ui/JavaRefactoringActionsFactory.java
@@ -45,6 +45,7 @@
import org.netbeans.modules.refactoring.java.ui.EncapsulateFieldAction;
import org.netbeans.modules.refactoring.java.ui.ExtractInterfaceAction;
import org.netbeans.modules.refactoring.java.ui.ExtractSuperclassAction;
+import org.netbeans.modules.refactoring.java.ui.InlineAction;
import org.netbeans.modules.refactoring.java.ui.InnerToOuterAction;
import org.netbeans.modules.refactoring.java.ui.PullUpAction;
import org.netbeans.modules.refactoring.java.ui.PushDownAction;
@@ -127,4 +128,12 @@
public static ContextAwareAction extractInterfaceAction() {
return ExtractInterfaceAction.findObject(ExtractInterfaceAction.class, true);
}
+
+ /**
+ * Factory method for InlineAction
+ * @return an instance of InlineAction
+ */
+ public static ContextAwareAction inlineAction() {
+ return InlineAction.findObject(InlineAction.class, true);
+ }
}
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/Bundle.properties b/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/Bundle.properties
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/Bundle.properties
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/Bundle.properties
@@ -238,3 +238,8 @@
ERR_VarargsFinalPosition=Varargs can be used only in the final argument position.
ERR_FindUsagesArrayType=Cannot perform find usages on []
+
+ERR_InlineWrongType=Cannot inline this type of object. A field or local variable has to be selected.
+ERR_InlineFieldWrongModifiers=Cannot inline this field. A field must be final and static.
+ERR_InlineInForLoop=Cannot inline a variable from a for statement.
+ERR_InlineAssignedMoreThanOnce=Variable is assigned to more than once.
\ No newline at end of file
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavaRefactoringsFactory.java b/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavaRefactoringsFactory.java
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavaRefactoringsFactory.java
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/JavaRefactoringsFactory.java
@@ -49,6 +49,7 @@
import org.netbeans.modules.refactoring.java.api.EncapsulateFieldRefactoring;
import org.netbeans.modules.refactoring.java.api.ExtractInterfaceRefactoring;
import org.netbeans.modules.refactoring.java.api.ExtractSuperclassRefactoring;
+import org.netbeans.modules.refactoring.java.api.InlineRefactoring;
import org.netbeans.modules.refactoring.java.api.InnerToOuterRefactoring;
import org.netbeans.modules.refactoring.java.api.PullUpRefactoring;
import org.netbeans.modules.refactoring.java.api.PushDownRefactoring;
@@ -121,6 +122,8 @@
return new EncapsulateFieldRefactoringPlugin((EncapsulateFieldRefactoring) refactoring);
} else if (refactoring instanceof EncapsulateFieldsRefactoring) {
return new EncapsulateFieldsPlugin((EncapsulateFieldsRefactoring) refactoring);
+ } else if (refactoring instanceof InlineRefactoring) {
+ return new InlineRefactoringPlugin((InlineRefactoring) refactoring);
}
}
return null;
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/resources/mf-layer.xml b/refactoring.java/src/org/netbeans/modules/refactoring/java/resources/mf-layer.xml
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/resources/mf-layer.xml
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/resources/mf-layer.xml
@@ -110,6 +110,10 @@
+
+
+
+
@@ -166,6 +170,9 @@
+
+
+
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/spi/ui/JavaActionsImplementationProvider.java b/refactoring.java/src/org/netbeans/modules/refactoring/java/spi/ui/JavaActionsImplementationProvider.java
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/spi/ui/JavaActionsImplementationProvider.java
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/spi/ui/JavaActionsImplementationProvider.java
@@ -197,6 +197,22 @@
*/
public void doExtractInterface(Lookup lookup) {
new UnsupportedOperationException("Not implemented"); // NOI18N
- }
-
+ }
+
+
+ /**
+ * @param lookup
+ * @return true if provider can handle inline
+ */
+ public boolean canInline(Lookup lookup) {
+ return false;
+ }
+
+ /**
+ * implementation of "invoke Inline"
+ * @param lookup
+ */
+ public void doInline(Lookup lookup) {
+ new UnsupportedOperationException("Not implemented"); // NOI18N
+ }
}
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/Bundle.properties b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/Bundle.properties
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/Bundle.properties
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/Bundle.properties
@@ -57,6 +57,11 @@
LBL_EncapsulateFields=Encapsulate Fields
DSC_EncapsulateFields=Encapsulate fields in class {0}
+LBL_InlineAction=Inline...
+LBL_InlineRefactoring=Inline
+DSC_Inline=Inline
+InlineRefactoringPanel.jLabel1.text=Found {0} occurences of {1}. Do you want to inline them?
+
LBL2_MoveClass=Move source to package "{0}"
LBL2_MoveObject=Move "{0}" to package "{1}"
LBL2_MovePackage=Move to "{0}" package
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/JavaActionsImplementationFactory.java b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/JavaActionsImplementationFactory.java
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/JavaActionsImplementationFactory.java
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/JavaActionsImplementationFactory.java
@@ -197,5 +197,21 @@
return false;
}
-
+ public static void doInline(Lookup lookup) {
+ for (JavaActionsImplementationProvider rafi: implementations.allInstances()) {
+ if (rafi.canInline(lookup)) {
+ rafi.doInline(lookup);
+ return;
+ }
+ }
+ }
+
+ public static boolean canInline(Lookup lookup) {
+ for (JavaActionsImplementationProvider rafi: implementations.allInstances()) {
+ if (rafi.canInline(lookup)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/JavaRefactoringActionsProvider.java b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/JavaRefactoringActionsProvider.java
--- a/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/JavaRefactoringActionsProvider.java
+++ b/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/JavaRefactoringActionsProvider.java
@@ -584,6 +584,66 @@
}
RetoucheUtils.invokeAfterScanFinished(task, RefactoringActionsProvider.getActionName(JavaRefactoringActionsFactory.encapsulateFieldsAction()));
}
+
+ @Override
+ public boolean canInline(Lookup lookup) {
+ Collection extends Node> nodes = new HashSet(lookup.lookupAll(Node.class));
+ if (nodes.size() != 1) {
+ return false;
+ }
+ Node n = nodes.iterator().next();
+ TreePathHandle tph = n.getLookup().lookup(TreePathHandle.class);
+ if (tph != null) {
+ if (RetoucheUtils.isRefactorable(tph.getFileObject())) {
+ return true;
+ }
+ }
+ DataObject dob = n.getCookie(DataObject.class);
+ if (dob == null) {
+ return false;
+ }
+ FileObject fo = dob.getPrimaryFile();
+ if (!RetoucheUtils.isRefactorable(fo)) { //NOI18N
+ return false;
+ }
+ if (RefactoringActionsProvider.isFromEditor(lookup.lookup(EditorCookie.class))) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void doInline(Lookup lookup) {
+ Runnable task;
+ EditorCookie ec = lookup.lookup(EditorCookie.class);
+ if (ec != null) {
+ task = new RefactoringActionsProvider.TextComponentTask(ec) {
+ protected RefactoringUI createRefactoringUI(TreePathHandle selectedElement,
+ int startOffset,
+ int endOffset,
+ CompilationInfo info) {
+ Element selected = selectedElement.resolveElement(info);
+ return InlineRefactoringUI.create(selectedElement, info);
+ }
+ };
+ } else {
+ task = new TreePathHandleTask(new HashSet(lookup.lookupAll(Node.class)), true) {
+
+ RefactoringUI ui;
+
+ @Override
+ protected void treePathHandleResolved(TreePathHandle handle, CompilationInfo javac) {
+ ui = InlineRefactoringUI.create(handle, javac);
+ }
+
+ @Override
+ protected RefactoringUI createRefactoringUI(Collection handles) {
+ return ui;
+ }
+ };
+ }
+ RetoucheUtils.invokeAfterScanFinished(task, RefactoringActionsProvider.getActionName(JavaRefactoringActionsFactory.changeParametersAction()));
+ }
private static TreePathHandle findSelectedClassMemberDeclaration(TreePathHandle path, final CompilationInfo info) {
TreePath resolved = path.resolve(info);