bug 478849 IndentAction: Adding ScriptFormatterExtension2 initialization

Change-Id: I2c3a3352d51d2f5527385fad4ed35137fec37c9b
Signed-off-by: Eriky Raggeoto Kashivagui <mushira4@gmail.com>
diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/actions/IndentAction.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/actions/IndentAction.java
index d7c9d79..22de784 100644
--- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/actions/IndentAction.java
+++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/actions/IndentAction.java
@@ -16,8 +16,7 @@
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.Assert;
-import org.eclipse.dltk.core.IModelElement;
-import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.ISourceModule;
 import org.eclipse.dltk.core.PreferencesLookupDelegate;
 import org.eclipse.dltk.core.ScriptUtils;
 import org.eclipse.dltk.internal.ui.editor.EditorUtility;
@@ -26,6 +25,7 @@
 import org.eclipse.dltk.ui.formatter.FormatterException;
 import org.eclipse.dltk.ui.formatter.IScriptFormatter;
 import org.eclipse.dltk.ui.formatter.IScriptFormatterExtension;
+import org.eclipse.dltk.ui.formatter.IScriptFormatterExtension2;
 import org.eclipse.dltk.ui.formatter.IScriptFormatterFactory;
 import org.eclipse.dltk.ui.formatter.ScriptFormatterManager;
 import org.eclipse.dltk.ui.text.util.AutoEditUtils;
@@ -81,18 +81,6 @@
 		fIsTabAction = isTabAction;
 	}
 
-	private IProject getProject() {
-		final IModelElement input = EditorUtility.getEditorInputModelElement(
-				getTextEditor(), false);
-		if (input != null) {
-			final IScriptProject scriptProject = input.getScriptProject();
-			if (scriptProject != null) {
-				return scriptProject.getProject();
-			}
-		}
-		return null;
-	}
-
 	/*
 	 * @see org.eclipse.jface.action.Action#run()
 	 */
@@ -147,7 +135,15 @@
 					}
 					return;
 				}
-				final IProject project = getProject();
+
+				IProject project = null;
+				final ISourceModule sourceModule = EditorUtility
+						.getEditorInputModelElement(getTextEditor(), false);
+				if (sourceModule != null
+						&& sourceModule.getScriptProject() != null) {
+					project = sourceModule.getScriptProject().getProject();
+				}
+
 				final IScriptFormatterFactory factory = ScriptFormatterManager
 						.getSelected(ScriptUtils.getNatureId(getTextEditor()),
 								project);
@@ -165,6 +161,12 @@
 						((IScriptFormatterExtension) formatter)
 								.initialize(project);
 					}
+					if (sourceModule != null
+							&& formatter instanceof IScriptFormatterExtension2) {
+						((IScriptFormatterExtension2) formatter)
+								.initialize(sourceModule);
+					}
+
 					final Position end = new Position(offset + length);
 					document.addPosition(end);
 					if (indentLines(document, startLine, lastLine, formatter)) {
@@ -435,4 +437,4 @@
 		return TextSelection.emptySelection();
 	}
 
-}
+}
\ No newline at end of file