You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2013/04/29 16:51:06 UTC

svn commit: r1477113 [7/18] - in /uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide: ./ core/ core/builder/ core/codeassist/ core/extensions/ core/packages/ core/parser/ core/search/ debug/ debug/ui/ debug/ui/handlers/ debug/ui...

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launchConfiguration/RutaRemoteTab.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launchConfiguration/RutaRemoteTab.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launchConfiguration/RutaRemoteTab.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launchConfiguration/RutaRemoteTab.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.ruta.ide.debug.ui.launchConfiguration;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
+import org.eclipse.dltk.launching.ScriptLaunchConfigurationConstants;
+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.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class RutaRemoteTab extends AbstractLaunchConfigurationTab {
+  private static final int DEFAULT_PORT = 9000;
+
+  private static final String DEFAULT_SESSION_ID = "ruta_debug";
+
+  private static final int DEFAULT_TIMEOUT = 30 * 1000; // 30 min
+
+  private Text portText;
+
+  private Text sessionIdText;
+
+  private Text timeoutText;
+
+  private int getPort() {
+    return Integer.parseInt(portText.getText());
+  }
+
+  private void setPort(int port) {
+    portText.setText(Integer.toString(port));
+  }
+
+  private String getSessionId() {
+    return sessionIdText.getText();
+  }
+
+  private void setSessionId(String id) {
+    sessionIdText.setText(id);
+  }
+
+  private int getTimeout() {
+    return Integer.parseInt(timeoutText.getText());
+  }
+
+  private void setTimeout(int timeout) {
+    timeoutText.setText(Integer.toString(timeout));
+  }
+
+  protected void createInstruction(Composite parent, Object data) {
+    Label instruction = new Label(parent, SWT.NONE);
+    instruction.setLayoutData(data);
+    instruction.setText("To start Ruta debugging engine use this command temlate:");
+  }
+
+  protected void createPathTemplate(Composite parent, Object data) {
+    Text text = new Text(parent, SWT.NONE);
+    text
+            .setText("${DEBUGGIN_ENGINE} -host-ide ${HOST} -port-ide ${PORT} -app-shell ${TM_INTERPRETER} -ide-key ${SESSION_ID} -app-file {TM_FILE}");
+  }
+
+  protected void createConnectionPropertiesGroup(Composite parent, Object data) {
+    Group group = new Group(parent, SWT.NONE);
+    group.setText("Connection Properties");
+    group.setLayoutData(data);
+
+    GridLayout layout = new GridLayout();
+    layout.numColumns = 2;
+    group.setLayout(layout);
+
+    // Local port
+    Label portLabel = new Label(group, SWT.NONE);
+    portLabel.setText("Local port:");
+
+    portText = new Text(group, SWT.BORDER);
+    portText.addModifyListener(new ModifyListener() {
+      public void modifyText(ModifyEvent e) {
+
+        updateLaunchConfigurationDialog();
+      }
+    });
+    portText.setLayoutData(new GridData(GridData.FILL, SWT.NONE, true, false));
+
+    // Id string
+    Label idLabel = new Label(group, SWT.NONE);
+    idLabel.setText("Connection id:");
+
+    sessionIdText = new Text(group, SWT.BORDER);
+    sessionIdText.addModifyListener(new ModifyListener() {
+      public void modifyText(ModifyEvent e) {
+        updateLaunchConfigurationDialog();
+      }
+    });
+
+    sessionIdText.setLayoutData(new GridData(GridData.FILL, SWT.NONE, true, false));
+
+    // Timeout
+    Label timeoutLabel = new Label(group, SWT.NONE);
+    timeoutLabel.setText("Waiting timeout:");
+
+    timeoutText = new Text(group, SWT.BORDER);
+    timeoutText.addModifyListener(new ModifyListener() {
+      public void modifyText(ModifyEvent e) {
+        updateLaunchConfigurationDialog();
+      }
+    });
+
+    timeoutText.setLayoutData(new GridData(GridData.FILL, SWT.NONE, true, false));
+  }
+
+  public void createControl(Composite parent) {
+    Composite composite = new Composite(parent, SWT.NONE);
+    setControl(composite);
+
+    GridLayout layout = new GridLayout();
+    layout.numColumns = 1;
+    composite.setLayout(layout);
+
+    createConnectionPropertiesGroup(composite, new GridData(GridData.FILL, SWT.NONE, true, false));
+
+    createInstruction(composite, new GridData(GridData.FILL, SWT.NONE, true, false));
+
+    createPathTemplate(composite, new GridData(GridData.FILL, SWT.NONE, true, false));
+  }
+
+  public String getName() {
+    return "Ruta Remote Properties";
+  }
+
+  public void initializeFrom(ILaunchConfiguration configuration) {
+    try {
+      // Port
+      int port = configuration.getAttribute(ScriptLaunchConfigurationConstants.ATTR_DLTK_DBGP_PORT,
+              -1);
+
+      setPort(port != -1 ? port : DEFAULT_PORT);
+
+      // Session id
+      String sessionId = configuration.getAttribute(
+              ScriptLaunchConfigurationConstants.ATTR_DLTK_DBGP_SESSION_ID, (String) null);
+
+      setSessionId(sessionId != null ? sessionId : DEFAULT_SESSION_ID);
+
+      // Timeout
+      int timeout = configuration.getAttribute(
+              ScriptLaunchConfigurationConstants.ATTR_DLTK_DBGP_WAITING_TIMEOUT, -1);
+      setTimeout(timeout != -1 ? timeout : DEFAULT_TIMEOUT);
+    } catch (CoreException e) {
+      // TODO: Log this
+    }
+  }
+
+  public void performApply(ILaunchConfigurationWorkingCopy configuration) {
+    try {
+      setErrorMessage(null);
+
+      configuration.setAttribute(ScriptLaunchConfigurationConstants.ATTR_DLTK_DBGP_REMOTE, true);
+
+      configuration.setAttribute(ScriptLaunchConfigurationConstants.ATTR_DLTK_DBGP_PORT, getPort());
+
+      configuration.setAttribute(ScriptLaunchConfigurationConstants.ATTR_DLTK_DBGP_SESSION_ID,
+              getSessionId());
+
+      configuration.setAttribute(ScriptLaunchConfigurationConstants.ATTR_DLTK_DBGP_WAITING_TIMEOUT,
+              getTimeout());
+    } catch (NumberFormatException e) {
+      setErrorMessage("Should be a number instead of string");
+    }
+  }
+
+  public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
+    configuration
+            .setAttribute(ScriptLaunchConfigurationConstants.ATTR_DLTK_DBGP_PORT, DEFAULT_PORT);
+
+    configuration.setAttribute(ScriptLaunchConfigurationConstants.ATTR_DLTK_DBGP_SESSION_ID,
+            DEFAULT_SESSION_ID);
+
+    configuration.setAttribute(ScriptLaunchConfigurationConstants.ATTR_DLTK_DBGP_WAITING_TIMEOUT,
+            DEFAULT_TIMEOUT);
+  }
+}

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launchConfiguration/RutaRemoteTabGroup.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launchConfiguration/RutaRemoteTabGroup.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launchConfiguration/RutaRemoteTabGroup.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launchConfiguration/RutaRemoteTabGroup.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.ruta.ide.debug.ui.launchConfiguration;
+
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
+import org.eclipse.debug.ui.ILaunchConfigurationDialog;
+import org.eclipse.debug.ui.ILaunchConfigurationTab;
+
+public class RutaRemoteTabGroup extends AbstractLaunchConfigurationTabGroup {
+
+  public RutaRemoteTabGroup() {
+  }
+
+  public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
+    ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { new RutaRemoteTab() };
+    setTabs(tabs);
+  }
+
+}

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launchConfiguration/RutaTabGroup.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launchConfiguration/RutaTabGroup.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launchConfiguration/RutaTabGroup.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launchConfiguration/RutaTabGroup.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.debug.ui.launchConfiguration;
+
+import org.apache.uima.ruta.ide.debug.ui.interpreters.RutaInterpreterTab;
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
+import org.eclipse.debug.ui.EnvironmentTab;
+import org.eclipse.debug.ui.ILaunchConfigurationDialog;
+import org.eclipse.debug.ui.ILaunchConfigurationTab;
+import org.eclipse.dltk.debug.ui.launchConfigurations.ScriptCommonTab;
+import org.eclipse.jdt.debug.ui.launchConfigurations.JavaClasspathTab;
+import org.eclipse.jdt.debug.ui.launchConfigurations.JavaJRETab;
+
+public class RutaTabGroup extends AbstractLaunchConfigurationTabGroup {
+  public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
+    RutaMainLaunchConfigurationTab main = new RutaMainLaunchConfigurationTab(mode);
+    ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { main, new JavaJRETab(),
+        new JavaClasspathTab(), new RutaArgumentsTab(), new RutaInterpreterTab(main),
+        new EnvironmentTab(), new ScriptCommonTab(main) };
+    setTabs(tabs);
+  }
+}

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launcher/RutaLaunchShortcut.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launcher/RutaLaunchShortcut.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launcher/RutaLaunchShortcut.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/launcher/RutaLaunchShortcut.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.ruta.ide.debug.ui.launcher;
+
+import org.apache.uima.ruta.ide.core.RutaNature;
+import org.apache.uima.ruta.ide.launching.RutaLaunchConfigurationConstants;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.dltk.internal.debug.ui.launcher.AbstractScriptLaunchShortcut;
+
+public class RutaLaunchShortcut extends AbstractScriptLaunchShortcut {
+  @Override
+  protected ILaunchConfigurationType getConfigurationType() {
+    return getLaunchManager().getLaunchConfigurationType(
+            RutaLaunchConfigurationConstants.ID_TM_SCRIPT);
+  }
+
+  @Override
+  protected String getNatureId() {
+    return RutaNature.NATURE_ID;
+  }
+}

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/preferences/RutaDebugPreferenceMessages.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/preferences/RutaDebugPreferenceMessages.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/preferences/RutaDebugPreferenceMessages.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/preferences/RutaDebugPreferenceMessages.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.debug.ui.preferences;
+
+import org.eclipse.osgi.util.NLS;
+
+public class RutaDebugPreferenceMessages extends NLS {
+  private static String BUNDLE_NAME = "org.apache.uima.ruta.ide.debug.ui.preferences.RutaDebugPreferenceMessages";
+
+  static {
+    NLS.initializeMessages(BUNDLE_NAME, RutaDebugPreferenceMessages.class);
+  }
+
+  public static String RutaDebugPreferencePage_description;
+
+  public static String RutaDebugEnginePreferencePage_description;
+}

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/preferences/RutaDebugPreferencePage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/preferences/RutaDebugPreferencePage.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/preferences/RutaDebugPreferencePage.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/preferences/RutaDebugPreferencePage.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.debug.ui.preferences;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.dltk.debug.core.DLTKDebugPreferenceConstants;
+import org.eclipse.dltk.debug.ui.preferences.AbstractDebuggingOptionsBlock;
+import org.eclipse.dltk.ui.PreferencesAdapter;
+import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage;
+import org.eclipse.dltk.ui.preferences.AbstractOptionsBlock;
+import org.eclipse.dltk.ui.preferences.PreferenceKey;
+import org.eclipse.dltk.ui.util.IStatusChangeListener;
+import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
+
+public class RutaDebugPreferencePage extends
+        AbstractConfigurationBlockPropertyAndPreferencePage {
+
+  private static PreferenceKey BREAK_ON_FIRST_LINE = new PreferenceKey(
+          RutaIdePlugin.PLUGIN_ID, DLTKDebugPreferenceConstants.PREF_DBGP_BREAK_ON_FIRST_LINE);
+
+  private static PreferenceKey ENABLE_DBGP_LOGGING = new PreferenceKey(
+          RutaIdePlugin.PLUGIN_ID, DLTKDebugPreferenceConstants.PREF_DBGP_ENABLE_LOGGING);
+
+  private static String PREFERENCE_PAGE_ID = "org.apache.uima.ruta.ide.preferences.debug";
+
+  private static String PROPERTY_PAGE_ID = "org.apache.uima.ruta.ide.propertyPage.debug";
+
+  @Override
+  protected AbstractOptionsBlock createOptionsBlock(IStatusChangeListener newStatusChangedListener,
+          IProject project, IWorkbenchPreferenceContainer container) {
+    return new AbstractDebuggingOptionsBlock(newStatusChangedListener, project, getKeys(),
+            container) {
+
+      @Override
+      protected PreferenceKey getBreakOnFirstLineKey() {
+        return BREAK_ON_FIRST_LINE;
+      }
+
+      @Override
+      protected PreferenceKey getDbgpLoggingEnabledKey() {
+        return ENABLE_DBGP_LOGGING;
+      }
+    };
+  }
+
+  /*
+   * @see
+   * org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage#getHelpId()
+   */
+  @Override
+  protected String getHelpId() {
+    return null;
+  }
+
+  /*
+   * @see org.eclipse.dltk.internal.ui.preferences.PropertyAndPreferencePage#getPreferencePageId()
+   */
+  @Override
+  protected String getPreferencePageId() {
+    return PREFERENCE_PAGE_ID;
+  }
+
+  /*
+   * @seeorg.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage#
+   * getProjectHelpId()
+   */
+  @Override
+  protected String getProjectHelpId() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  /*
+   * @see org.eclipse.dltk.internal.ui.preferences.PropertyAndPreferencePage#getPropertyPageId()
+   */
+  @Override
+  protected String getPropertyPageId() {
+    return PROPERTY_PAGE_ID;
+  }
+
+  /*
+   * @see
+   * org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage#setDescription
+   * ()
+   */
+  @Override
+  protected void setDescription() {
+    setDescription(RutaDebugPreferenceMessages.RutaDebugPreferencePage_description);
+  }
+
+  /*
+   * @seeorg.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage#
+   * setPreferenceStore()
+   */
+  @Override
+  protected void setPreferenceStore() {
+    setPreferenceStore(new PreferencesAdapter(RutaIdePlugin.getDefault()
+            .getPluginPreferences()));
+  }
+
+  private PreferenceKey[] getKeys() {
+    return new PreferenceKey[] { BREAK_ON_FIRST_LINE, ENABLE_DBGP_LOGGING };
+  }
+}

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/preferences/RutaDebuggingEnginePreferencePage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/preferences/RutaDebuggingEnginePreferencePage.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/preferences/RutaDebuggingEnginePreferencePage.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debug/ui/preferences/RutaDebuggingEnginePreferencePage.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.debug.ui.preferences;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.apache.uima.ruta.ide.core.RutaNature;
+import org.apache.uima.ruta.ide.debug.RutaDebugConstants;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.dltk.debug.ui.preferences.AbstractDebuggingEngineOptionsBlock;
+import org.eclipse.dltk.ui.PreferencesAdapter;
+import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage;
+import org.eclipse.dltk.ui.preferences.AbstractOptionsBlock;
+import org.eclipse.dltk.ui.preferences.PreferenceKey;
+import org.eclipse.dltk.ui.util.IStatusChangeListener;
+import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
+
+public class RutaDebuggingEnginePreferencePage extends
+        AbstractConfigurationBlockPropertyAndPreferencePage {
+
+  private static PreferenceKey DEBUGGING_ENGINE = new PreferenceKey(RutaIdePlugin.PLUGIN_ID,
+          RutaDebugConstants.DEBUGGING_ENGINE_ID_KEY);
+
+  private static final String PREFERENCE_PAGE_ID = "org.apache.uima.ruta.ide.preferences.debug.engines";
+
+  private static final String PROPERTY_PAGE_ID = "org.apache.uima.ruta.ide.propertyPage.debug.engines";
+
+  @Override
+  protected AbstractOptionsBlock createOptionsBlock(IStatusChangeListener newStatusChangedListener,
+          IProject project, IWorkbenchPreferenceContainer container) {
+    return new AbstractDebuggingEngineOptionsBlock(newStatusChangedListener, project, getKeys(),
+            container) {
+
+      @Override
+      protected String getNatureId() {
+        return RutaNature.NATURE_ID;
+      }
+
+      @Override
+      protected PreferenceKey getSavedContributionKey() {
+        return DEBUGGING_ENGINE;
+      }
+    };
+  }
+
+  /*
+   * @see
+   * org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage#getHelpId()
+   */
+  @Override
+  protected String getHelpId() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  /*
+   * @see org.eclipse.dltk.internal.ui.preferences.PropertyAndPreferencePage#getPreferencePageId()
+   */
+  @Override
+  protected String getPreferencePageId() {
+    return PREFERENCE_PAGE_ID;
+  }
+
+  /*
+   * @seeorg.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage#
+   * getProjectHelpId()
+   */
+  @Override
+  protected String getProjectHelpId() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  /*
+   * @see org.eclipse.dltk.internal.ui.preferences.PropertyAndPreferencePage#getPropertyPageId()
+   */
+  @Override
+  protected String getPropertyPageId() {
+    return PROPERTY_PAGE_ID;
+  }
+
+  /*
+   * @see
+   * org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage#setDescription
+   * ()
+   */
+  @Override
+  protected void setDescription() {
+    setDescription(RutaDebugPreferenceMessages.RutaDebugEnginePreferencePage_description);
+  }
+
+  /*
+   * @seeorg.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage#
+   * setPreferenceStore()
+   */
+  @Override
+  protected void setPreferenceStore() {
+    setPreferenceStore(new PreferencesAdapter(RutaIdePlugin.getDefault()
+            .getPluginPreferences()));
+  }
+
+  private PreferenceKey[] getKeys() {
+    return new PreferenceKey[] { DEBUGGING_ENGINE };
+  }
+}

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/RutaDebuggerRunner.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/RutaDebuggerRunner.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/RutaDebuggerRunner.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/RutaDebuggerRunner.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.debugger;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.apache.uima.ruta.ide.debug.RutaDebugConstants;
+import org.apache.uima.ruta.ide.launching.IConfigurableRunner;
+import org.apache.uima.ruta.ide.launching.IRutaInterpreterRunnerConfig;
+import org.apache.uima.ruta.ide.launching.RutaInterpreterRunner;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.dltk.core.PreferencesLookupDelegate;
+import org.eclipse.dltk.launching.DebuggingEngineRunner;
+import org.eclipse.dltk.launching.IInterpreterInstall;
+import org.eclipse.dltk.launching.InterpreterConfig;
+
+public class RutaDebuggerRunner extends DebuggingEngineRunner implements IConfigurableRunner {
+
+  private static String ENGINE_ID = "org.apache.uima.ruta.ide.debugger.preferences.RutaDebuggerRunnerFactory";
+
+  IRutaInterpreterRunnerConfig runnerconfig = RutaInterpreterRunner.DEFAULT_CONFIG;
+
+  public RutaDebuggerRunner(IInterpreterInstall install) {
+    super(install);
+  }
+
+  @Override
+  public String getDebugModelId() {
+    return RutaDebugConstants.DEBUG_MODEL_ID;
+  }
+
+  @Override
+  public void run(InterpreterConfig config, ILaunch launch, IProgressMonitor monitor)
+          throws CoreException {
+    initializeLaunch(launch, config, createPreferencesLookupDelegate(launch));
+    RutaInterpreterRunner.doRunImpl(config, launch, this.runnerconfig, monitor);
+  }
+
+  public void setRunnerConfig(IRutaInterpreterRunnerConfig config) {
+    this.runnerconfig = config;
+  }
+
+  @Override
+  protected String getDebuggingEngineId() {
+    return ENGINE_ID;
+  }
+
+  @Override
+  protected String getDebugPreferenceQualifier() {
+    return RutaIdePlugin.PLUGIN_ID;
+  }
+
+  @Override
+  protected String getDebuggingEnginePreferenceQualifier() {
+    return RutaIdePlugin.PLUGIN_ID;
+  }
+
+  protected String getLoggingEnabledPreferenceKey() {
+    // not yet supported...
+    return null;
+  }
+
+  @Override
+  protected String getLogFileNamePreferenceKey() {
+    // not yet supported...
+    return null;
+  }
+
+  protected String getLogFilePathPreferenceKey() {
+    // not yet supported...
+    return null;
+  }
+
+  @Override
+  protected InterpreterConfig addEngineConfig(InterpreterConfig config,
+          PreferencesLookupDelegate delegate, ILaunch launch) throws CoreException {
+    return config;
+  }
+}

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/RutaDebuggerRunnerFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/RutaDebuggerRunnerFactory.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/RutaDebuggerRunnerFactory.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/RutaDebuggerRunnerFactory.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.ruta.ide.debugger;
+
+import org.eclipse.dltk.launching.IInterpreterInstall;
+import org.eclipse.dltk.launching.IInterpreterRunner;
+import org.eclipse.dltk.launching.IInterpreterRunnerFactory;
+
+public class RutaDebuggerRunnerFactory implements IInterpreterRunnerFactory {
+
+  /*
+   * @see
+   * org.eclipse.dltk.launching.IInterpreterRunnerFactory#createRunner(org.eclipse.dltk.launching
+   * .IInterpreterInstall)
+   */
+  public IInterpreterRunner createRunner(IInterpreterInstall install) {
+    return new RutaDebuggerRunner(install);
+  }
+}

Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/preferences/PreferenceMessages.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/preferences/PreferenceMessages.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/preferences/PreferenceMessages.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/preferences/PreferenceMessages.java Mon Apr 29 14:50:56 2013
@@ -17,12 +17,12 @@
  * under the License.
  */
 
-package org.apache.uima.textmarker.ide.debugger.preferences;
+package org.apache.uima.ruta.ide.debugger.preferences;
 
 import org.eclipse.osgi.util.NLS;
 
 public class PreferenceMessages {
-  private static final String BUNDLE_NAME = "org.apache.uima.textmarker.ide.debugger.preferences.PreferenceMessages";
+  private static final String BUNDLE_NAME = "org.apache.uima.ruta.ide.debugger.preferences.PreferenceMessages";
 
   static {
     NLS.initializeMessages(BUNDLE_NAME, PreferenceMessages.class);

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/preferences/RutaDebuggerPreferencePage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/preferences/RutaDebuggerPreferencePage.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/preferences/RutaDebuggerPreferencePage.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/debugger/preferences/RutaDebuggerPreferencePage.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.debugger.preferences;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage;
+import org.eclipse.dltk.ui.preferences.AbstractOptionsBlock;
+import org.eclipse.dltk.ui.preferences.PreferenceKey;
+import org.eclipse.dltk.ui.util.IStatusChangeListener;
+import org.eclipse.dltk.ui.util.SWTFactory;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
+
+public class RutaDebuggerPreferencePage extends
+        AbstractConfigurationBlockPropertyAndPreferencePage {
+
+  private static String PREFERENCE_PAGE_ID = "org.apache.uima.ruta.ide.preferences.debug.engines.debugger";
+
+  private static String PROPERTY_PAGE_ID = "org.apache.uima.ruta.ide.propertyPage.debug.engines.debugger";
+
+  /*
+   * @seeorg.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage#
+   * createOptionsBlock(org.eclipse.dltk.ui.util.IStatusChangeListener,
+   * org.eclipse.core.resources.IProject, org.eclipse.ui.preferences.IWorkbenchPreferenceContainer)
+   */
+  @Override
+  protected AbstractOptionsBlock createOptionsBlock(IStatusChangeListener newStatusChangedListener,
+          IProject project, IWorkbenchPreferenceContainer container) {
+    return new AbstractOptionsBlock(newStatusChangedListener, project, new PreferenceKey[] {},
+            container) {
+
+      @Override
+      protected Control createOptionsBlock(Composite parent) {
+        Composite composite = SWTFactory.createComposite(parent, parent.getFont(), 1, 1,
+                GridData.FILL);
+        SWTFactory.createLabel(composite, PreferenceMessages.NoSettingsAvailable, 1);
+        return composite;
+      }
+    };
+  }
+
+  /*
+   * @see
+   * org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage#getHelpId()
+   */
+  @Override
+  protected String getHelpId() {
+    return null;
+  }
+
+  /*
+   * @see org.eclipse.dltk.internal.ui.preferences.PropertyAndPreferencePage#getPreferencePageId()
+   */
+  @Override
+  protected String getPreferencePageId() {
+    return PREFERENCE_PAGE_ID;
+  }
+
+  /*
+   * @seeorg.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage#
+   * getProjectHelpId()
+   */
+  @Override
+  protected String getProjectHelpId() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  /*
+   * @see org.eclipse.dltk.internal.ui.preferences.PropertyAndPreferencePage#getPropertyPageId()
+   */
+  @Override
+  protected String getPropertyPageId() {
+    return PROPERTY_PAGE_ID;
+  }
+
+  /*
+   * @see
+   * org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage#setDescription
+   * ()
+   */
+  @Override
+  protected void setDescription() {
+    setDescription(PreferenceMessages.PreferencesDescription);
+  }
+
+  /*
+   * @seeorg.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage#
+   * setPreferenceStore()
+   */
+  @Override
+  protected void setPreferenceStore() {
+    setPreferenceStore(RutaIdePlugin.getDefault().getPreferenceStore());
+  }
+}

Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/Messages.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/Messages.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/Messages.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/Messages.java Mon Apr 29 14:50:56 2013
@@ -17,14 +17,14 @@
  * under the License.
  */
 
-package org.apache.uima.textmarker.ide.formatter;
+package org.apache.uima.ruta.ide.formatter;
 
 import org.eclipse.osgi.util.NLS;
 
 public class Messages extends NLS {
-  private static final String BUNDLE_NAME = "org.apache.uima.textmarker.ide.formatter.internal.messages"; //$NON-NLS-1$
+  private static final String BUNDLE_NAME = "org.apache.uima.ruta.ide.formatter.internal.messages"; //$NON-NLS-1$
 
-  public static String TextMarkerFormatter_contentCorrupted;
+  public static String RutaFormatter_contentCorrupted;
   static {
     // initialize resource bundle
     NLS.initializeMessages(BUNDLE_NAME, Messages.class);

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormattedPrinter.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormattedPrinter.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormattedPrinter.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormattedPrinter.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,814 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.formatter;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.antlr.runtime.CommonToken;
+import org.apache.uima.ruta.ide.parser.ast.ComposedRuleElement;
+import org.apache.uima.ruta.ide.parser.ast.TMConditionConstants;
+import org.apache.uima.ruta.ide.parser.ast.RutaAbstractDeclaration;
+import org.apache.uima.ruta.ide.parser.ast.RutaAction;
+import org.apache.uima.ruta.ide.parser.ast.RutaBinaryArithmeticExpression;
+import org.apache.uima.ruta.ide.parser.ast.RutaBlock;
+import org.apache.uima.ruta.ide.parser.ast.RutaBooleanNumberExpression;
+import org.apache.uima.ruta.ide.parser.ast.RutaCondition;
+import org.apache.uima.ruta.ide.parser.ast.RutaDeclarationsStatement;
+import org.apache.uima.ruta.ide.parser.ast.RutaDeclareDeclarationsStatement;
+import org.apache.uima.ruta.ide.parser.ast.RutaExpression;
+import org.apache.uima.ruta.ide.parser.ast.RutaFeatureDeclaration;
+import org.apache.uima.ruta.ide.parser.ast.RutaListExpression;
+import org.apache.uima.ruta.ide.parser.ast.RutaLogAction;
+import org.apache.uima.ruta.ide.parser.ast.RutaPackageDeclaration;
+import org.apache.uima.ruta.ide.parser.ast.RutaQuantifierLiteralExpression;
+import org.apache.uima.ruta.ide.parser.ast.RutaRule;
+import org.apache.uima.ruta.ide.parser.ast.RutaRuleElement;
+import org.apache.uima.ruta.ide.parser.ast.RutaStringExpression;
+import org.apache.uima.ruta.ide.parser.ast.RutaStructureAction;
+import org.apache.uima.ruta.ide.parser.ast.RutaTypeDeclaration;
+import org.apache.uima.ruta.ide.parser.ast.RutaVariableReference;
+import org.eclipse.dltk.ast.ASTListNode;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.declarations.Declaration;
+import org.eclipse.dltk.ast.declarations.MethodDeclaration;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.ast.declarations.TypeDeclaration;
+import org.eclipse.dltk.ast.expressions.Expression;
+import org.eclipse.dltk.ast.expressions.StringLiteral;
+import org.eclipse.dltk.ast.statements.Block;
+import org.eclipse.dltk.ast.statements.Statement;
+import org.eclipse.dltk.formatter.FormatterDocument;
+import org.eclipse.dltk.formatter.IFormatterIndentGenerator;
+
+/**
+ * Formats a document.<br>
+ * Use the append methods within the visit methods to preserve the comments.
+ * 
+ * 
+ */
+public class RutaFormattedPrinter extends ASTVisitor {
+
+  private FormatterDocument document;
+
+  private String lineDelimiter;
+
+  private static final String SEMI = ";";
+
+  private static final String CONCAT = " + ";
+
+  private static final String COMMA = ",";
+
+  private static final int NL_DECLS_COUNT = 2;
+
+  private static final String CURLY_OPEN = "{";
+
+  private static final String CURLY_CLOSE = "}";
+
+  private static final String BRACK_OPEN = "[";
+
+  private static final String BRACK_CLOSE = "]";
+
+  private static final String THEN = "->";
+
+  private static final String PAR_OPEN = "(";
+
+  private static final String PAR_CLOSE = ")";
+
+  private static final String EQUALS = " = ";
+
+  private IFormatterIndentGenerator indentGenerator;
+
+  private StringBuilder output;
+
+  private List<CommonToken> comments;
+
+  private Iterator<CommonToken> iterator;
+
+  private CommonToken currentComment;
+
+  private int indentLevel = 0;
+
+  private int lines_before_long_declarations;
+
+  private int maxLineLength;
+
+  private boolean inBlockDeclaration = false;
+
+  private Map<Integer, Object> lastStatements = new HashMap<Integer, Object>();
+
+  private int commentLineSince = 0;
+
+  // hotfix: 0 = false, 1 = first rule element, 3 = not first rule element
+  private int inLargeRule = 0;
+
+  private boolean retainLB = true;
+
+  public RutaFormattedPrinter(FormatterDocument document, String lineDelimiter,
+          IFormatterIndentGenerator indentGenerator, List<CommonToken> comments,
+          RutaFormatter tmf) {
+    this.document = document;
+    this.lineDelimiter = lineDelimiter;
+    this.indentGenerator = indentGenerator;
+    this.output = new StringBuilder();
+
+    // read format preferences
+    this.lines_before_long_declarations = tmf
+            .getInt(RutaFormatterConstants.LINES_BEFORE_LONG_DECLARATIONS);
+    this.maxLineLength = tmf.getInt(RutaFormatterConstants.MAX_LINE_LENGTH);
+
+    // comments
+    this.comments = comments == null ? new ArrayList<CommonToken>() : comments;
+    iterator = this.comments.iterator();
+    this.currentComment = iterator.hasNext() ? iterator.next() : null;
+  }
+
+  public String getOutput() {
+    appendLeftComments();
+    return this.output.toString();
+  }
+
+  @Override
+  public boolean visit(Statement s) throws Exception {
+
+    appendComments(s);
+    fillNewLines(s);
+
+    if (s instanceof RutaDeclarationsStatement) {
+      // append new lines before LONG DECLARATIONS
+      RutaDeclarationsStatement decls = (RutaDeclarationsStatement) s;
+      // if (decls.getDeclarationsCount() > NL_DECLS_COUNT) {
+      // for (int i = 0; i < lines_before_long_declarations; i++) {
+      // appendNewLine();
+      // }
+      // }
+      // format declarations:
+      // print type token
+      appendIntoNewLine(document.get(decls.getTypeTokenStart(), decls.getTypeTokenEnd()) + " ");
+      // print parent if available
+      if (s instanceof RutaDeclareDeclarationsStatement) {
+        RutaDeclareDeclarationsStatement dds = (RutaDeclareDeclarationsStatement) s;
+        ASTNode p = dds.getParent();
+        if (p != null) {
+          append(p);
+          append(" ");
+        }
+      }
+      // print identifiers
+      List<RutaAbstractDeclaration> declarations = decls.getDeclarations();
+      traverseAstNodes(declarations);
+      // print init expr
+      if (decls.getInitExpr() != null) {
+        append(EQUALS);
+        decls.getInitExpr().traverse(this);
+      }
+      appendStatementEnd();
+      return false;
+    }
+    if (s instanceof RutaRule) {
+      // traverse into container RutaRule to format RuleElements
+      if (!inBlockDeclaration) {
+        appendNewLine();
+      }
+      // Rules always just consists of RuleElements: whitespace separation
+      if (s.sourceEnd() - s.sourceStart() > 2 * maxLineLength) {
+        inLargeRule = 1;
+        indentLevel++;
+      }
+      RutaRule rule = (RutaRule) s;
+      List<Expression> expressions = rule.getExpressions();
+      traverseAstNodes(expressions, "");
+      if (!inBlockDeclaration) {
+        appendStatementEnd();
+      }
+      if (inLargeRule > 0) {
+        indentLevel--;
+        inLargeRule = 0;
+      }
+      return false;
+      // return true;
+    }
+    // if (s instanceof RutaVariableDeclaration && s.getKind() ==
+    // TMTypeConstants.TM_TYPE_WL ||
+    // s.getKind() == TMTC)
+    // special format for declaration statements (they're wrapped in a
+    // declarations-statement)
+    if (s instanceof RutaTypeDeclaration) {
+      append(s);
+      List<RutaFeatureDeclaration> features = ((RutaTypeDeclaration) s).getFeatures();
+      if (features != null && !features.isEmpty()) {
+        append(PAR_OPEN);
+        for (RutaFeatureDeclaration each : features) {
+          append(each.getType());
+          append(" ");
+          append(each.getName());
+          if (features.indexOf(each) < features.size() - 1) {
+            append(COMMA + " ");
+          }
+        }
+        append(PAR_CLOSE);
+      }
+      return false;
+    }
+
+    if (s instanceof Declaration && !(s instanceof RutaPackageDeclaration)) {
+      append(s);
+      return false;
+    }
+    if (s instanceof RutaPackageDeclaration) {
+      append(s);
+      appendStatementEnd();
+      return false;
+    }
+    // append SEMIs for all other statements
+    appendIntoNewLine(s);
+    appendStatementEnd();
+    return false;
+  }
+
+  private void fillNewLines(Object s) {
+    Object last = lastStatements.get(indentLevel);
+    // if (last == null && indentLevel > 0) {
+    // last = lastStatements.get(indentLevel - 1);
+    // }
+    if (last != null && retainLB) {
+      int start = 0;
+      int end = 0;
+      if (s instanceof Statement) {
+        end = ((ASTNode) s).sourceStart();
+      } else if (s instanceof CommonToken) {
+        end = ((CommonToken) s).getStartIndex();
+      }
+      if (last instanceof Statement) {
+        start = ((ASTNode) last).sourceEnd() + 1;
+      } else if (last instanceof CommonToken) {
+        start = ((CommonToken) last).getStopIndex();
+      }
+
+      if (start < end) {
+        String string = document.get(start, end);
+        String replaceAll = string.replaceAll(lineDelimiter, "");
+        double d = (string.length() - replaceAll.length()) / lineDelimiter.length()
+                - commentLineSince;
+        if (s instanceof CommonToken && commentLineSince == 0) {
+          d++;
+        }
+        for (int i = 1; i < d; i++) {
+          appendNewLine();
+        }
+        if (d < 2 && s instanceof RutaDeclarationsStatement && !(last instanceof Declaration)) {
+          appendNewLine();
+        }
+        commentLineSince = 0;
+      }
+    } else if (inBlockDeclaration || s instanceof CommonToken) {
+      appendNewLine();
+    }
+    lastStatements.put(indentLevel, s);
+  }
+
+  @Override
+  public boolean endvisit(Statement s) throws Exception {
+    // if (s instanceof RutaRule) {
+    // append(SEMI);
+    // return true;
+    // }
+    return super.endvisit(s);
+  }
+
+  @Override
+  public boolean visit(Expression s) throws Exception {
+    // traverse Block (first child of root element:
+    if (s instanceof Block) {
+      return true;
+    }
+    if (s instanceof ComposedRuleElement) {
+      ComposedRuleElement cre = (ComposedRuleElement) s;
+      List<Expression> elements = cre.getElements();
+      // int length = cre.sourceEnd() - cre.sourceStart();
+      if (inLargeRule == 2) {
+        inLargeRule = 4;
+      }
+      append(PAR_OPEN);
+      traverseAstNodes(elements, cre.isDisjunctive() ? " |" : "");
+      append(PAR_CLOSE);
+      appendRuleElement(cre);
+      if (inLargeRule == 4) {
+        inLargeRule = 1;
+      }
+      return false;
+    }
+    // special format for RuleElements:
+    if (s instanceof RutaRuleElement) {
+      RutaRuleElement ruleEl = (RutaRuleElement) s;
+      if (inLargeRule == 2) {
+        appendNewLine();
+      } else if (inLargeRule == 1) {
+        inLargeRule = 2;
+      }
+      appendRuleElement(ruleEl);
+      return false;
+    }
+    // special format for actions
+    if (s instanceof RutaAction) {
+      RutaAction a = (RutaAction) s;
+      String name = document.get(a.getNameStart(), a.getNameEnd());
+      append(name);
+      List<? extends ASTNode> childs = a.getChilds();
+      if (childs != null && !childs.isEmpty()) {
+        append(PAR_OPEN);
+        // special format for create
+        if (a instanceof RutaStructureAction) {
+          if (name.equals("TRIE")) {
+            printStructureAction2(a);
+          } else {
+            printStructureAction(a);
+          }
+        } else {
+          traverseAstNodes(childs);
+        }
+        // special format for log
+        if (a instanceof RutaLogAction && ((RutaLogAction) a).isLogLevelAssigned()) {
+          appendSeparator(COMMA);
+          RutaLogAction logAction = (RutaLogAction) a;
+          append(logAction.getLogLevelStart(), logAction.getLogLevelEnd());
+        }
+        append(PAR_CLOSE);
+      }
+      return false;
+    }
+    // special format for conditions
+    if (s instanceof RutaCondition) {
+      RutaCondition c = (RutaCondition) s;
+      append(document.get(c.getNameStart(), c.getNameEnd()));
+      List<? extends ASTNode> childs = c.getChilds();
+      // minus is a condition without parameter parantheses:
+      if (s.getKind() != TMConditionConstants.COND_MINUS && childs != null && !childs.isEmpty()) {
+        append(PAR_OPEN);
+      }
+      traverseAstNodes(childs);
+      if (s.getKind() != TMConditionConstants.COND_MINUS && childs != null && !childs.isEmpty()) {
+        append(PAR_CLOSE);
+      }
+      return false;
+    }
+    // special format for boolean number expressions
+    if (s instanceof RutaBooleanNumberExpression) {
+      RutaBooleanNumberExpression tmbne = (RutaBooleanNumberExpression) s;
+      append(PAR_OPEN);
+      if (tmbne.getE1() != null) {
+        tmbne.getE1().traverse(this);
+      }
+      append(tmbne.getOperator());
+      if (tmbne.getE2() != null) {
+        tmbne.getE2().traverse(this);
+      }
+      append(PAR_CLOSE);
+      return false;
+    }
+    // special format for string expressions
+    if (s instanceof RutaStringExpression
+            && ((RutaExpression) s).getExpression() != null) {
+      RutaStringExpression tmse = (RutaStringExpression) s;
+      List<?> childs = tmse.getExpression().getChilds();
+      Object object2 = childs.get(0);
+      if (object2 instanceof ASTNode) {
+        ASTNode astnode = (ASTNode) object2;
+        List<?> childs2 = astnode.getChilds();
+        for (Object object : childs2) {
+          if (object instanceof RutaExpression) {
+            RutaExpression expr = (RutaExpression) object;
+            // if (expr.isInParantheses()) {
+            // append(PAR_OPEN);
+            // append(expr);
+            // append(PAR_CLOSE);
+            // } else {
+            append(expr);
+            // }
+          } else if (object instanceof StringLiteral) {
+            StringLiteral sl = (StringLiteral) object;
+            String value = sl.getValue();
+            append(value);
+          } else if (object instanceof RutaVariableReference) {
+            RutaVariableReference vr = (RutaVariableReference) object;
+            append(vr.getName());
+          }
+          if (childs2.indexOf(object) < childs2.size() - 1) {
+            append(CONCAT);
+          }
+        }
+      } else {
+        append(s);
+      }
+      return false;
+    }
+    if (s instanceof RutaListExpression) {
+      RutaListExpression le = (RutaListExpression) s;
+      append(CURLY_OPEN);
+      ASTListNode exprs = le.getExprs();
+      traverseAstNodes(exprs.getChilds());
+      append(CURLY_CLOSE);
+      return false;
+    }
+
+    // special format for paranthesed expressions: (expression)
+    // if (s instanceof RutaExpression && ((RutaExpression) s).isInParantheses()) {
+    // append(PAR_OPEN);
+    // append(s);
+    // append(PAR_CLOSE);
+    // return false;
+    // }
+    if (s instanceof RutaBinaryArithmeticExpression) {
+      RutaBinaryArithmeticExpression ba = (RutaBinaryArithmeticExpression) s;
+      String operator = ba.getOperator();
+      append(operator);
+      append(PAR_OPEN);
+      traverseAstNodes(ba.getChilds());
+      append(PAR_CLOSE);
+    }
+    append(s);
+    return false;
+  }
+
+  /**
+   * structure actions like CREATE, FILL with assignments.
+   * 
+   * @param a
+   */
+  private void printStructureAction(RutaAction a) {
+    RutaStructureAction tmca = (RutaStructureAction) a;
+    // structure
+    if (tmca.getStructure() != null) {
+      append(tmca.getStructure());
+    }
+    append(COMMA);
+    append(" ");
+    // number expressions
+    List<Expression> indices = tmca.getExpressions();
+    if (indices != null) {
+      traverseAstNodes(indices);
+    }
+    if (!indices.isEmpty()) {
+      append(COMMA);
+      append(" ");
+    }
+    // assignments
+    Map<Expression, Expression> assignments = tmca.getAssignments();
+    Iterator it = assignments.entrySet().iterator();
+    while (it.hasNext()) {
+      if (assignments.size() > 3) {
+        appendNewLineAndIndent();
+      }
+      Map.Entry pairs = (Map.Entry) it.next();
+      try {
+        ((Expression) pairs.getKey()).traverse(this);
+      } catch (Exception e) {
+        e.printStackTrace();
+      }
+      append(EQUALS);
+      try {
+        ((Expression) pairs.getValue()).traverse(this);
+      } catch (Exception e) {
+        e.printStackTrace();
+      }
+      if (it.hasNext()) {
+        output.append(COMMA);
+        append(" ");
+      }
+    }
+  }
+
+  private void printStructureAction2(RutaAction a) {
+    RutaStructureAction tmca = (RutaStructureAction) a;
+
+    Map<Expression, Expression> assignments = tmca.getAssignments();
+    Iterator it = assignments.entrySet().iterator();
+    while (it.hasNext()) {
+      if (assignments.size() > 3) {
+        appendNewLineAndIndent();
+      }
+      Map.Entry pairs = (Map.Entry) it.next();
+      try {
+        ((Expression) pairs.getKey()).traverse(this);
+      } catch (Exception e) {
+        e.printStackTrace();
+      }
+      append(EQUALS);
+      try {
+        ((Expression) pairs.getValue()).traverse(this);
+      } catch (Exception e) {
+        e.printStackTrace();
+      }
+      output.append(COMMA);
+      append(" ");
+    }
+    // structure
+    if (tmca.getStructure() != null) {
+      append(tmca.getStructure());
+    }
+    append(COMMA);
+    append(" ");
+    // number expressions
+    List<Expression> indices = tmca.getExpressions();
+    if (indices != null) {
+      traverseAstNodes(indices);
+    }
+    // assignments
+
+  }
+
+  @Override
+  public boolean endvisit(Expression s) throws Exception {
+    return super.endvisit(s);
+  }
+
+  /**
+   * @param ruleEl
+   * @param conditions
+   * @param actions
+   */
+  private void appendRuleElement(RutaRuleElement ruleEl) {
+    // if (ruleEl instanceof ComposedRuleElement) {
+    // ComposedRuleElement cre = (ComposedRuleElement) ruleEl;
+    // List<Expression> elements = cre.getElements();
+    // append(PAR_OPEN);
+    // for (Expression expression : elements) {
+    //
+    // if (expression instanceof RutaRuleElement) {
+    // RutaRuleElement re = (RutaRuleElement) expression;
+    // appendRuleElement(re);
+    // }
+    // if (elements.indexOf(expression) < elements.size() - 1) {
+    // append(" ");
+    // }
+    //
+    // }
+    // append(PAR_CLOSE);
+    // } else
+    if (ruleEl.getHead() != null) {
+      append(ruleEl.getHead());
+    }
+    List<RutaCondition> conditions = ruleEl.getConditions();
+    List<RutaAction> actions = ruleEl.getActions();
+    // don't print {->} for empty rule elements
+
+    // print Quantifiers
+    List<? extends ASTNode> quantifierExpressions = ruleEl.getQuantifierExpressions();
+    if (quantifierExpressions != null && !quantifierExpressions.isEmpty()) {
+      if (quantifierExpressions.size() == 1) {
+        ASTNode astNode = quantifierExpressions.get(0);
+        if (astNode instanceof RutaQuantifierLiteralExpression) {
+          append(astNode);
+        } else {
+          append(BRACK_OPEN);
+          append(astNode);
+          append(BRACK_CLOSE);
+        }
+      } else if (quantifierExpressions.size() == 2) {
+        if (quantifierExpressions.get(1) instanceof RutaQuantifierLiteralExpression) {
+          append(BRACK_OPEN);
+          append(quantifierExpressions.get(0));
+          append(BRACK_CLOSE);
+          append(quantifierExpressions.get(1));
+        } else {
+          append(BRACK_OPEN);
+          append(quantifierExpressions.get(0));
+          append(COMMA + " ");
+          append(quantifierExpressions.get(1));
+          append(BRACK_CLOSE);
+        }
+      } else if (quantifierExpressions.size() == 3) {
+        append(BRACK_OPEN);
+        append(quantifierExpressions.get(0));
+        append(COMMA + " ");
+        append(quantifierExpressions.get(1));
+        append(BRACK_CLOSE);
+        append(quantifierExpressions.get(2));
+      }
+    }
+    if (!inBlockDeclaration && conditions == null && actions == null) {
+      return;
+    }
+
+    if (!inBlockDeclaration
+            && ((conditions == null && actions.isEmpty()) || actions == null
+                    && (conditions != null) && conditions.isEmpty())) {
+      return;
+    }
+    append(CURLY_OPEN);
+    // print Conditions
+    if (conditions != null && !conditions.isEmpty()) {
+      traverseAstNodes(conditions);
+    }
+    if (conditions != null && !conditions.isEmpty()) {
+    }
+    // print Actions
+    if (actions != null && !actions.isEmpty()) {
+      if (conditions != null && !conditions.isEmpty()) {
+        append(" " + THEN + " ");
+      } else {
+        append(THEN + " ");
+      }
+      traverseAstNodes(actions);
+    }
+    append(CURLY_CLOSE);
+  }
+
+  /**
+   * @param astnodes
+   */
+  @SuppressWarnings("unchecked")
+  private void traverseAstNodes(List<? extends ASTNode> astnodes) {
+    traverseAstNodes(astnodes, COMMA);
+  }
+
+  /**
+   * @param astnodes
+   */
+  @SuppressWarnings("unchecked")
+  private void traverseAstNodes(List<? extends ASTNode> astnodes, String separator) {
+    if (astnodes == null) {
+      return;
+    }
+    Iterator iterator2 = astnodes.iterator();
+    while (iterator2.hasNext()) {
+      ASTNode node = (ASTNode) iterator2.next();
+      try {
+        node.traverse(this);
+      } catch (Exception e) {
+        e.printStackTrace();
+      }
+      if (iterator2.hasNext()) {
+        appendSeparator(separator);
+      }
+    }
+  }
+
+  private void appendSeparator(String separator) {
+    output.append(separator);
+    append(" ");
+  }
+
+  @Override
+  public boolean visit(MethodDeclaration s) throws Exception {
+    appendComments(s);
+    fillNewLines(s);
+
+    // Statement last = lastStatements.get(indentLevel);
+    // // if (last == null && indentLevel > 0) {
+    // // last = lastStatements.get(indentLevel - 1);
+    // // }
+    // if (last != null && retainLB) {
+    // int start = last.sourceEnd() + 1;
+    // int end = s.sourceStart();
+    // if (start < end) {
+    // String string = document.get(start, end);
+    // String replaceAll = string.replaceAll(lineDelimiter, "");
+    // double d = (string.length() - replaceAll.length()) / lineDelimiter.length()
+    // - commentLineSince;
+    // for (int i = 1; i < d; i++) {
+    // appendNewLine();
+    // }
+    // commentLineSince = 0;
+    // }
+    // }
+
+    if (s instanceof RutaBlock) {
+      RutaBlock b = (RutaBlock) s;
+      appendIntoNewLine("BLOCK(");
+      append(b.getName());
+      append(") ");
+      this.inBlockDeclaration = true;
+      if (b.getRule() != null) {
+        b.getRule().traverse(this);
+      }
+      this.inBlockDeclaration = false;
+      append(" {");
+      indentLevel++;
+      b.getBody().traverse(this);
+      lastStatements.put(indentLevel, null);
+      indentLevel--;
+      lastStatements.put(indentLevel, s);
+      appendIntoNewLine("}");
+      appendNewLine();
+      return false;
+    }
+    return super.visit(s);
+  }
+
+  @Override
+  public boolean visit(ModuleDeclaration s) throws Exception {
+    return true;
+  }
+
+  @Override
+  public boolean visit(TypeDeclaration s) throws Exception {
+    return super.visit(s);
+  }
+
+  @Override
+  public boolean visitGeneral(ASTNode node) throws Exception {
+    return super.visitGeneral(node);
+  }
+
+  private void append(int begin, int end) {
+    append(document.get(begin, end));
+  }
+
+  private void append(String string) {
+    if (outputPosInLine() + string.length() > maxLineLength) {
+      appendNewLine();
+      indentGenerator.generateIndent(1, output);
+    }
+    output.append(string);
+  }
+
+  private void appendIntoNewLine(String string) {
+    appendNewLine();
+    output.append(string);
+  }
+
+  private void append(ASTNode s) {
+    appendComments(s);
+    // this.output.
+    append(document.get(s.sourceStart(), s.sourceEnd()));
+  }
+
+  private void appendIntoNewLine(ASTNode s) {
+    appendComments(s);
+    appendNewLine();
+    append(s);
+  }
+
+  private void appendNewLine() {
+    output.append(lineDelimiter);
+    indentGenerator.generateIndent(indentLevel, output);
+  }
+
+  private void appendNewLineAndIndent() {
+    output.append(lineDelimiter);
+    indentGenerator.generateIndent(indentLevel + 1, output);
+  }
+
+  private void appendStatementEnd() {
+    output.append(SEMI);
+  }
+
+  /**
+   * @param s
+   * @return
+   */
+  private int appendComments(ASTNode s) {
+    return appendComments(s.sourceStart());
+  }
+
+  /**
+   * @param start
+   * @return
+   */
+  private int appendComments(int start) {
+    while (currentComment != null && currentComment.getStartIndex() < start) {
+      String text = currentComment.getText().trim();
+      fillNewLines(currentComment);
+      append("" + text);
+      currentComment = iterator.hasNext() ? iterator.next() : null;
+      commentLineSince++;
+    }
+    return start;
+  }
+
+  private void appendLeftComments() {
+    while (currentComment != null) {
+      append(currentComment.getText());
+      currentComment = iterator.hasNext() ? iterator.next() : null;
+    }
+  }
+
+  private int outputPosInLine() {
+    String out = output.toString();
+    int lastIndexOf = out.lastIndexOf("\n");
+    return out.length() - lastIndexOf;
+  }
+
+}

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatter.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatter.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatter.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatter.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.formatter;
+
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.Reader;
+import java.util.List;
+import java.util.Map;
+
+import org.antlr.runtime.BitSet;
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.CommonTokenStream;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.uima.ruta.ide.core.parser.RutaSourceParser;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.ast.parser.IModuleDeclaration;
+import org.eclipse.dltk.compiler.problem.IProblem;
+import org.eclipse.dltk.compiler.problem.IProblemReporter;
+import org.eclipse.dltk.formatter.AbstractScriptFormatter;
+import org.eclipse.dltk.formatter.FormatterDocument;
+import org.eclipse.dltk.ui.formatter.FormatterException;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.eclipse.text.edits.ReplaceEdit;
+import org.eclipse.text.edits.TextEdit;
+
+public class RutaFormatter extends AbstractScriptFormatter {
+
+  class DummyReporter implements IProblemReporter {
+
+    private boolean gotProblems = false;
+
+
+    public void reportProblem(IProblem problem) {
+      setProblems(true);
+    }
+
+    public void setProblems(boolean gotProblems) {
+      this.gotProblems = gotProblems;
+    }
+
+    public boolean gotProblems() {
+      return gotProblems;
+    }
+  };
+
+  protected static final String[] INDENTING = { RutaFormatterConstants.INDENT_BLOCK,
+      RutaFormatterConstants.INDENT_STRUCTURE };
+
+  // protected static final String[] BLANK_LINES = { };
+
+  private final String lineDelimiter;
+
+  public RutaFormatter(String lineDelimiter, Map preferences) {
+    super(preferences);
+    this.lineDelimiter = lineDelimiter;
+  }
+
+  public TextEdit format(String source, int offset, int length, int indent)
+          throws FormatterException {
+    String input = source;
+    // TODO implement useful format for code snippets
+    // final String input = source.substring(offset, offset + length);
+    if (StringUtils.isEmpty(input)) {
+      return null;
+    }
+    RutaSourceParser tmsp = new RutaSourceParser();
+
+    DummyReporter reporter = new DummyReporter();
+    IModuleDeclaration md = tmsp.parse("format.tm", source, reporter);
+    CommonTokenStream tokenStream = tmsp.getTokenStream();
+
+    if (!reporter.gotProblems()) {
+
+      BitSet bs = new BitSet();
+      bs.add(org.apache.uima.ruta.parser.RutaParser.LINE_COMMENT);
+      bs.add(org.apache.uima.ruta.parser.RutaParser.COMMENT);
+      List<CommonToken> comments = tokenStream.getTokens(0, tokenStream.size(), bs);
+
+      final String output = format(input, (ModuleDeclaration)md, comments, indent);
+      if (output != null) {
+        if (!input.equals(output)) {
+          return new ReplaceEdit(0, source.length(), output);
+          // return new ReplaceEdit(offset, length, output);
+          // if (!equalsIgnoreBlanks(new StringReader(input), new StringReader(output))) {
+          // // return new MultiTextEdit();
+          // return new ReplaceEdit(offset, length, output);
+          // } else {
+          // // TODO reset throwing exception
+          // return new MultiTextEdit();
+          // // throw new IllegalArgumentException("illegal format context");
+          // // System.err.println("illegal format context");
+          // }
+        } else {
+          return new MultiTextEdit();
+        }
+      }
+    }
+    return null;
+  }
+
+  /**
+   * @param input
+   * @param md
+   * @param indent
+   * @return the formatted code
+   */
+  private String format(String input, ModuleDeclaration md, List<CommonToken> comments, int indent) {
+    final FormatterDocument document = createDocument(input);
+
+    // compute new (formatted) document structure
+    RutaFormattedPrinter tmfp = new RutaFormattedPrinter(document, lineDelimiter,
+            createIndentGenerator(), comments, this);
+    try {
+      md.traverse(tmfp);
+    } catch (Exception e) {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+    }
+    return tmfp.getOutput();
+
+    // // compute new (formatted) document structure
+    // final RutaFormatterNodeBuilder builder = new RutaFormatterNodeBuilder();
+    // IFormatterContainerNode root = builder.build(md, document);
+    // // new RutaFormatterNodeRewriter(result, document).rewrite(root);
+    // IFormatterContext context = new FormatterContext(indent);
+    // FormatterWriter writer = new FormatterWriter(document, lineDelimiter,
+    // createIndentGenerator());
+    // try {
+    // root.accept(context, writer);
+    // writer.flush(context);
+    // return writer.getOutput();
+    // } catch (Exception e) {
+    // e.printStackTrace();
+    // return null;
+    // }
+  }
+
+  /**
+   * Factory method for FormatterDocuments that represent the content with formatting options.<br>
+   * No formatting operations done in this method and no formatting done with the content of the
+   * formatterDocument in general.
+   * 
+   * @param input
+   * @return
+   */
+  private FormatterDocument createDocument(String input) {
+    FormatterDocument document = new FormatterDocument(input);
+    for (int i = 0; i < INDENTING.length; ++i) {
+      document.setBoolean(INDENTING[i], getBoolean(INDENTING[i]));
+    }
+    document.setInt(RutaFormatterConstants.FORMATTER_TAB_SIZE,
+            getInt(RutaFormatterConstants.FORMATTER_TAB_SIZE));
+    return document;
+  }
+
+  private boolean equalsIgnoreBlanks(Reader inputReader, Reader outputReader) {
+    LineNumberReader input = new LineNumberReader(inputReader);
+    LineNumberReader output = new LineNumberReader(outputReader);
+    for (;;) {
+      final String inputLine = readLine(input);
+      final String outputLine = readLine(output);
+      if (inputLine == null) {
+        if (outputLine == null) {
+          return true;
+        } else {
+          return false;
+        }
+      } else if (outputLine == null) {
+        return false;
+      } else if (!inputLine.equals(outputLine)) {
+        return false;
+      }
+    }
+  }
+
+  private String readLine(LineNumberReader reader) {
+    String line;
+    do {
+      try {
+        line = reader.readLine();
+      } catch (IOException e) {
+        return null; // just doing sth.
+      }
+      if (line == null) {
+        return line;
+      }
+      line = line.trim();
+    } while (line.length() == 0);
+    return line;
+  }
+
+  @Override
+  public int getInt(String key) {
+    return super.getInt(key);
+  }
+
+  @Override
+  protected boolean getBoolean(String key) {
+    return super.getBoolean(key);
+  }
+
+  @Override
+  protected String getString(String key) {
+    return super.getString(key);
+  }
+
+}

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatterConstants.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatterConstants.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatterConstants.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatterConstants.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.ruta.ide.formatter;
+
+import org.eclipse.dltk.ui.CodeFormatterConstants;
+
+public class RutaFormatterConstants {
+
+  public static final String FORMATTER_TAB_CHAR = CodeFormatterConstants.FORMATTER_TAB_CHAR;
+
+  public static final String FORMATTER_TAB_SIZE = CodeFormatterConstants.FORMATTER_TAB_SIZE;
+
+  public static final String FORMATTER_INDENTATION_SIZE = CodeFormatterConstants.FORMATTER_INDENTATION_SIZE;
+
+  public static final String FORMATTER_PROFILES = "formatter.profiles"; //$NON-NLS-1$
+
+  public static final String FORMATTER_ACTIVE_PROFILE = "formatter.profiles.active"; //$NON-NLS-1$
+
+  public static final String INDENT_BLOCK = "indent.block";
+
+  public static final String INDENT_STRUCTURE = "indent.structure";
+
+  // TODO implement smarter format options, first just indentation...
+  public static final String LINES_BEFORE_LONG_DECLARATIONS = "lines.before.long.declarations";
+
+  public static final String MAX_LINE_LENGTH = "wrapping.max.line.length";
+
+  // public static final String LINES_FILE_AFTER_GLOBAL =
+  // "line.file.global.after";
+  // public static final String LINES_FILE_BEFORE_FIRST_ =
+  // "line.file.block.between";
+  // public static final String LINES_FILE_BETWEEN_BLOCK =
+  // "line.file.block.between";
+  // public static final String LINES_FILE_BETWEEN_BLOCK =
+  // "line.file.block.between";
+  // public static final String LINES_FILE_BETWEEN_BLOCK =
+  // "line.file.block.between";
+  // public static final String LINES_FILE_BETWEEN_BLOCK =
+  // "line.file.block.between";
+  // public static final String LINES_FILE_BETWEEN_BLOCK =
+  // "line.file.block.between";
+
+  public static final String LINES_PRESERVE = "lines.preserve";
+}

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatterFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatterFactory.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatterFactory.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatterFactory.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.formatter;
+
+import java.net.URL;
+import java.util.Map;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.apache.uima.ruta.ide.formatter.preferences.RutaFormatterModifyDialog;
+import org.eclipse.dltk.formatter.AbstractScriptFormatterFactory;
+import org.eclipse.dltk.ui.formatter.IFormatterModifyDialog;
+import org.eclipse.dltk.ui.formatter.IFormatterModifyDialogOwner;
+import org.eclipse.dltk.ui.formatter.IScriptFormatter;
+import org.eclipse.dltk.ui.preferences.PreferenceKey;
+
+public class RutaFormatterFactory extends AbstractScriptFormatterFactory {
+
+  private static final String[] KEYS = {
+      // RutaUI.PLUGIN_ID :
+      RutaFormatterConstants.FORMATTER_TAB_CHAR,
+      RutaFormatterConstants.FORMATTER_INDENTATION_SIZE,
+      RutaFormatterConstants.FORMATTER_TAB_SIZE,
+      // RutaFormatterPlugin.PLUGIN_ID :
+      RutaFormatterConstants.INDENT_BLOCK, RutaFormatterConstants.INDENT_STRUCTURE,
+      RutaFormatterConstants.LINES_BEFORE_LONG_DECLARATIONS,
+      RutaFormatterConstants.MAX_LINE_LENGTH };
+
+  public PreferenceKey[] getPreferenceKeys() {
+    final PreferenceKey[] result = new PreferenceKey[KEYS.length];
+    for (int i = 0; i < KEYS.length; ++i) {
+      final String key = KEYS[i];
+      final String qualifier;
+      if (RutaFormatterConstants.FORMATTER_TAB_CHAR.equals(key)
+              || RutaFormatterConstants.FORMATTER_INDENTATION_SIZE.equals(key)
+              || RutaFormatterConstants.FORMATTER_TAB_SIZE.equals(key)) {
+        qualifier = RutaIdePlugin.PLUGIN_ID;
+      } else {
+        qualifier = RutaIdePlugin.PLUGIN_ID;
+      }
+      result[i] = new PreferenceKey(qualifier, key);
+    }
+    return result;
+  }
+
+  @Override
+  public PreferenceKey getProfilesKey() {
+    return new PreferenceKey(RutaIdePlugin.PLUGIN_ID,
+            RutaFormatterConstants.FORMATTER_PROFILES);
+  }
+
+  public PreferenceKey getActiveProfileKey() {
+    return new PreferenceKey(RutaIdePlugin.PLUGIN_ID,
+            RutaFormatterConstants.FORMATTER_ACTIVE_PROFILE);
+  }
+
+  public IScriptFormatter createFormatter(String lineDelimiter, Map preferences) {
+    return new RutaFormatter(lineDelimiter, preferences);
+  }
+
+  @Override
+  public URL getPreviewContent() {
+    return getClass().getResource("formatPreviewScript.tm"); //$NON-NLS-1$
+  }
+
+  public IFormatterModifyDialog createDialog(IFormatterModifyDialogOwner dialogOwner) {
+    return new RutaFormatterModifyDialog(dialogOwner, this);
+  }
+
+}

Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatterPreferenceInitializer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatterPreferenceInitializer.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatterPreferenceInitializer.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/formatter/RutaFormatterPreferenceInitializer.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta.ide.formatter;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+public class RutaFormatterPreferenceInitializer extends AbstractPreferenceInitializer {
+
+  public void initializeDefaultPreferences() {
+    RutaIdePlugin plugin = RutaIdePlugin.getDefault();
+    IPreferenceStore store = plugin.getPreferenceStore();
+
+    store.setDefault(RutaFormatterConstants.INDENT_BLOCK, true);
+    store.setDefault(RutaFormatterConstants.INDENT_STRUCTURE, true);
+
+    store.setDefault(RutaFormatterConstants.LINES_BEFORE_LONG_DECLARATIONS, 1);
+
+    store.setDefault(RutaFormatterConstants.LINES_PRESERVE, 1);
+
+    store.setDefault(RutaFormatterConstants.MAX_LINE_LENGTH, 100);
+  }
+}