|
From: <caw...@us...> - 2006-12-18 13:30:38
|
Revision: 1716
http://svn.sourceforge.net/rubyeclipse/?rev=1716&view=rev
Author: cawilliams
Date: 2006-12-18 05:30:32 -0800 (Mon, 18 Dec 2006)
Log Message:
-----------
apply Kyle's patch for "Textmate like template expansion"
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubySourceViewer.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCompletionProcessor.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ILinkedModeEditStrategy.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAutoEditStrategy.java
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ILinkedModeEditStrategy.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ILinkedModeEditStrategy.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ILinkedModeEditStrategy.java 2006-12-18 13:30:32 UTC (rev 1716)
@@ -0,0 +1,19 @@
+package org.rubypeople.rdt.internal.ui.rubyeditor;
+
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.link.LinkedPosition;
+
+/**
+ * Interface for linked mode edit strategies.
+ */
+public interface ILinkedModeEditStrategy extends IAutoEditStrategy {
+
+ /**
+ * Returns the linked positions to use for the most recently processed
+ * document command.
+ *
+ * @return An array of linked positions to use in linked mode, or
+ * <code>null</code> if no linked mode should be set up
+ */
+ public LinkedPosition[] getLinkedPositions();
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAutoEditStrategy.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAutoEditStrategy.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAutoEditStrategy.java 2006-12-18 13:30:32 UTC (rev 1716)
@@ -0,0 +1,176 @@
+package org.rubypeople.rdt.internal.ui.rubyeditor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.link.LinkedPosition;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.templates.DocumentTemplateContext;
+import org.eclipse.jface.text.templates.Template;
+import org.eclipse.jface.text.templates.TemplateBuffer;
+import org.eclipse.jface.text.templates.TemplateContext;
+import org.eclipse.jface.text.templates.TemplateContextType;
+import org.eclipse.jface.text.templates.TemplateException;
+import org.eclipse.jface.text.templates.TemplateVariable;
+import org.rubypeople.rdt.internal.ui.text.ruby.RubyCompletionProcessor;
+
+public class RubyAutoEditStrategy implements ILinkedModeEditStrategy {
+
+ private RubyCompletionProcessor fRubyCp;
+
+ private ISourceViewer fViewer;
+
+ /** The linked position list */
+ protected final List fPositionList = new ArrayList();
+
+ public RubyAutoEditStrategy(String partition, ISourceViewer viewer,
+ RubyCompletionProcessor rhtmlCp) {
+ fViewer = viewer;
+ fRubyCp = rhtmlCp;
+ }
+
+ public void customizeDocumentCommand(IDocument document,
+ DocumentCommand command) {
+ fPositionList.clear();
+ if (command.text.length() == 1) {
+ if (command.text.charAt(0) == '\t') {
+ try {
+ int length = 0;
+ while ((command.offset - length > 0)
+ && Pattern.matches("\\w", document.get(
+ command.offset - length - 1, 1))) {
+ length++;
+ }
+ String prefix = document.get(command.offset - length,
+ length);
+ Region region = new Region(
+ command.offset - prefix.length(), prefix.length());
+ if (prefix.length() > 0) {
+ Template[] templates = fRubyCp
+ .getTemplates("ruby");
+ for (int i = 0; i < templates.length; i++) {
+ Template template = templates[i];
+ if (template.getName().equals(prefix)) {
+ final int offset = command.offset
+ - prefix.length();
+ TemplateContextType contextType = fRubyCp
+ .getContextType(fViewer, region);
+ TemplateContext context = new DocumentTemplateContext(
+ contextType, document, region
+ .getOffset(), region
+ .getLength());
+
+ context.setReadOnly(false);
+ TemplateBuffer templateBuffer;
+ try {
+ templateBuffer = context.evaluate(template);
+ } catch (TemplateException e1) {
+ return;
+ }
+
+ int start = getReplaceOffset(context, region);
+ int end = Math.max(getReplaceEndOffset(context,
+ region), offset);
+
+ // insert template string
+ String templateString = templateBuffer
+ .getString();
+
+ command.text = templateString;
+ command.offset = start;
+ command.length = end - start;
+
+ fPositionList.add(new LinkedPosition(document,
+ offset + templateString.length(), 0));
+
+ // translate positions
+ TemplateVariable[] variables = templateBuffer
+ .getVariables();
+ for (int z = 0; z != variables.length; z++) {
+ TemplateVariable variable = variables[z];
+
+ if (variable.isUnambiguous())
+ continue;
+
+ int[] offsets = variable.getOffsets();
+ int variablelength = variable.getLength();
+
+ for (int j = 0; j != offsets.length; j++)
+ fPositionList.add(new LinkedPosition(
+ document, offsets[j] + start,
+ variablelength));
+ }
+
+ break;
+ }
+
+ }
+ }
+ } catch (BadLocationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public LinkedPosition[] getLinkedPositions() {
+ final int size = fPositionList.size();
+ if (size > 0) {
+
+ final LinkedPosition[] positions = new LinkedPosition[size];
+ fPositionList.toArray(positions);
+
+ return positions;
+ }
+ return null;
+ }
+
+ /**
+ * Returns the offset of the range in the document that will be replaced by
+ * applying this template.
+ *
+ * @return the offset of the range in the document that will be replaced by
+ * applying this template
+ * @since 3.1
+ */
+ protected final int getReplaceOffset(TemplateContext context, Region region) {
+ int start;
+ if (context instanceof DocumentTemplateContext) {
+ DocumentTemplateContext docContext = (DocumentTemplateContext) context;
+ start = docContext.getStart();
+ } else {
+ start = region.getOffset();
+ }
+ return start;
+ }
+
+ /**
+ * Returns the end offset of the range in the document that will be replaced
+ * by applying this template.
+ *
+ * @return the end offset of the range in the document that will be replaced
+ * by applying this template
+ * @since 3.1
+ */
+ protected final int getReplaceEndOffset(TemplateContext context,
+ Region region) {
+ int end;
+ if (context instanceof DocumentTemplateContext) {
+ DocumentTemplateContext docContext = (DocumentTemplateContext) context;
+ end = docContext.getEnd();
+ } else {
+ end = region.getOffset() + region.getLength();
+ }
+ return end;
+ }
+
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubySourceViewer.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubySourceViewer.java 2006-12-15 22:02:36 UTC (rev 1715)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubySourceViewer.java 2006-12-18 13:30:32 UTC (rev 1716)
@@ -6,14 +6,35 @@
*/
package org.rubypeople.rdt.internal.ui.rubyeditor;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IPositionUpdater;
+import org.eclipse.jface.text.link.ILinkedModeListener;
+import org.eclipse.jface.text.link.InclusivePositionUpdater;
+import org.eclipse.jface.text.link.LinkedModeModel;
+import org.eclipse.jface.text.link.LinkedModeUI;
+import org.eclipse.jface.text.link.LinkedPosition;
+import org.eclipse.jface.text.link.LinkedPositionGroup;
import org.eclipse.jface.text.source.IOverviewRuler;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
@@ -26,6 +47,9 @@
private boolean fIgnoreTextConverters = false;
+ /** The linked position list for code auto edit */
+ protected final LinkedList fPositionList = new LinkedList();
+
/**
* This viewer's foreground color.
* @since 0.8.0
@@ -60,11 +84,19 @@
* @since 0.8.0
*/
private boolean fIsConfigured;
+
+ /** The auto edit category */
+ protected static final String CATEGORY_AUTO_EDIT = "org.rubypeople.rdt.ui.RubyEditor"
+ + ".auto.edit." + System.currentTimeMillis(); //$NON-NLS-1$
+ /** The position updater for auto edit */
+ protected final IPositionUpdater fAutoEditUpdater;
+
public RubySourceViewer(Composite composite, IVerticalRuler verticalRuler,
IOverviewRuler overviewRuler, boolean overviewRulerVisible, int styles, IPreferenceStore store) {
super(composite, verticalRuler, overviewRuler, overviewRulerVisible, styles);
setPreferenceStore(store);
+ fAutoEditUpdater = new InclusivePositionUpdater(CATEGORY_AUTO_EDIT);
}
/**
@@ -239,4 +271,155 @@
if (getTextWidget() == null || !redraws()) { return; }
super.doOperation(operation);
}
+
+ /*
+ * @see org.eclipse.jface.text.TextViewer#handleVisibleDocumentChanged(org.eclipse.jface.text.DocumentEvent)
+ */
+ protected final void handleVisibleDocumentChanged(final DocumentEvent event) {
+ super.handleVisibleDocumentChanged(event);
+
+ if (!fPositionList.isEmpty()) {
+
+ try {
+
+ final IDocument document = event.getDocument();
+ final LinkedModeModel model = new LinkedModeModel();
+
+ final String category = CATEGORY_AUTO_EDIT;
+ if (!document.containsPositionCategory(category)) {
+
+ document.addPositionCategory(category);
+ document.addPositionUpdater(fAutoEditUpdater);
+
+ model.addLinkingListener(new ILinkedModeListener() {
+
+ public final void left(final LinkedModeModel dummy,
+ final int flags) {
+
+ if (document.containsPositionCategory(category)) {
+
+ try {
+ document.removePositionCategory(category);
+ } catch (BadPositionCategoryException exception) {
+ // Do nothing
+ }
+ document
+ .removePositionUpdater(fAutoEditUpdater);
+ }
+ }
+
+ public final void resume(final LinkedModeModel dummy,
+ final int flags) {
+ }
+
+ public final void suspend(final LinkedModeModel dummy) {
+ }
+ });
+ }
+
+ LinkedPosition position = null;
+ LinkedPositionGroup group = null;
+
+ for (final Iterator iterator = fPositionList.iterator(); iterator
+ .hasNext();) {
+
+ position = (LinkedPosition) iterator.next();
+
+ group = new LinkedPositionGroup();
+ group.addPosition(position);
+
+ model.addGroup(group);
+ }
+ model.forceInstall();
+
+ final LinkedModeUI handler = new LinkedModeUI(model, this);
+
+ final LinkedPosition exit = (LinkedPosition) fPositionList
+ .getFirst();
+ final LinkedPosition entry = (LinkedPosition) fPositionList
+ .getLast();
+
+ addSelectionChangedListener(new ISelectionChangedListener() {
+
+ private boolean fHandled = false;
+
+ public final void selectionChanged(
+ final SelectionChangedEvent dummy) {
+
+ if (!fHandled) {
+
+ fHandled = true;
+
+ removeSelectionChangedListener(this);
+ }
+ }
+ });
+
+ addPostSelectionChangedListener(new ISelectionChangedListener() {
+
+ private boolean fHandled = false;
+
+ public final void selectionChanged(
+ final SelectionChangedEvent dummy) {
+
+ if (!fHandled) {
+ setSelectedRange(entry.offset, entry.length);
+
+ invalidateTextPresentation(entry.offset, 0);
+
+ fHandled = true;
+
+ removePostSelectionChangedListener(this);
+ }
+ }
+ });
+
+ handler
+ .setExitPosition(this, exit.offset, 0,
+ LinkedPositionGroup.NO_STOP);
+
+ handler.enter();
+
+ } catch (BadLocationException exception) {
+ // Do nothing
+ } finally {
+ fPositionList.clear();
+ }
+ }
+ }
+
+ protected void customizeDocumentCommand(DocumentCommand command) {
+ if (isIgnoringAutoEditStrategies())
+ return;
+
+ List strategies = (List) selectContentTypePlugin(command.offset,
+ fAutoIndentStrategies);
+ if (strategies == null)
+ return;
+
+ IDocument document = getDocument();
+ if (!strategies.isEmpty()) {
+
+ fPositionList.clear();
+ String originalCommandText = command.text;
+
+ LinkedPosition[] result = null;
+ IAutoEditStrategy strategy = null;
+
+ for (final Iterator iterator = new ArrayList(strategies).iterator(); iterator
+ .hasNext();) {
+
+ strategy = (IAutoEditStrategy) iterator.next();
+ strategy.customizeDocumentCommand(document, command);
+
+ if ((strategy instanceof ILinkedModeEditStrategy) && originalCommandText.equals("\t")) {
+ result = ((ILinkedModeEditStrategy) strategy)
+ .getLinkedPositions();
+ if (result != null && result.length > 0)
+ fPositionList.addAll(Arrays.asList(result));
+ }
+ }
+ }
+ }
+
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCompletionProcessor.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCompletionProcessor.java 2006-12-15 22:02:36 UTC (rev 1715)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCompletionProcessor.java 2006-12-18 13:30:32 UTC (rev 1716)
@@ -168,7 +168,7 @@
* @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getContextType(org.eclipse.jface.text.ITextViewer,
* org.eclipse.jface.text.IRegion)
*/
- protected TemplateContextType getContextType(ITextViewer textViewer,
+ public TemplateContextType getContextType(ITextViewer textViewer,
IRegion region) {
return RubyTemplateAccess.getDefault().getContextTypeRegistry()
.getContextType(RubyContextType.NAME);
@@ -356,7 +356,7 @@
*
* @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getTemplates(java.lang.String)
*/
- protected Template[] getTemplates(String contextTypeId) {
+ public Template[] getTemplates(String contextTypeId) {
return RubyTemplateAccess.getDefault().getTemplateStore()
.getTemplates();
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2006-12-15 22:02:36 UTC (rev 1715)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2006-12-18 13:30:32 UTC (rev 1716)
@@ -42,6 +42,7 @@
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.rubyeditor.IRubyScriptDocumentProvider;
import org.rubypeople.rdt.internal.ui.rubyeditor.RubyAbstractEditor;
+import org.rubypeople.rdt.internal.ui.rubyeditor.RubyAutoEditStrategy;
import org.rubypeople.rdt.internal.ui.text.ContentAssistPreference;
import org.rubypeople.rdt.internal.ui.text.HTMLTextPresenter;
import org.rubypeople.rdt.internal.ui.text.IRubyColorConstants;
@@ -63,341 +64,384 @@
import org.rubypeople.rdt.internal.ui.text.ruby.hover.RubyCodeTextHover;
import org.rubypeople.rdt.ui.text.hyperlinks.RubyHyperLinkDetector;
-public class RubySourceViewerConfiguration extends TextSourceViewerConfiguration {
+public class RubySourceViewerConfiguration extends
+ TextSourceViewerConfiguration {
- protected RubyTextTools textTools;
- protected ITextEditor fTextEditor;
- private RubyCodeTextHover fRubyTextHover;
+ protected RubyTextTools textTools;
+ protected ITextEditor fTextEditor;
+ private RubyCodeTextHover fRubyTextHover;
- /**
- * The document partitioning.
- *
- * @since 0.8.0
- */
- private String fDocumentPartitioning;
+ /**
+ * The document partitioning.
+ *
+ * @since 0.8.0
+ */
+ private String fDocumentPartitioning;
- /**
- * The color manager.
- *
- * @since 0.8.0
- */
- private IColorManager fColorManager;
+ /**
+ * The color manager.
+ *
+ * @since 0.8.0
+ */
+ private IColorManager fColorManager;
- protected AbstractRubyScanner fCodeScanner;
- protected AbstractRubyScanner fMultilineCommentScanner, fSinglelineCommentScanner,
- fStringScanner;
- private SingleTokenRubyCodeScanner fRegexpScanner;
- private SingleTokenRubyCodeScanner fCommandScanner;
- private RubyDoubleClickSelector fRubyDoubleClickSelector;
+ protected AbstractRubyScanner fCodeScanner;
- /**
- * Creates a new Ruby source viewer configuration for viewers in the given
- * editor using the given preference store, the color manager and the
- * specified document partitioning.
- * <p>
- * Creates a Ruby source viewer configuration in the new setup without text
- * tools. Clients are allowed to call
- * {@link RubySourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}
- * and disallowed to call
- * {@link RubySourceViewerConfiguration#getPreferenceStore()} on the
- * resulting Ruby source viewer configuration.
- * </p>
- *
- * @param colorManager
- * the color manager
- * @param preferenceStore
- * the preference store, can be read-only
- * @param editor
- * the editor in which the configured viewer(s) will reside, or
- * <code>null</code> if none
- * @param partitioning
- * the document partitioning for this configuration, or
- * <code>null</code> for the default partitioning
- * @since 3.0
- */
- public RubySourceViewerConfiguration(IColorManager colorManager,
- IPreferenceStore preferenceStore, ITextEditor editor, String partitioning) {
- super(preferenceStore);
- fColorManager = colorManager;
- fTextEditor = editor;
- fDocumentPartitioning = partitioning;
- initializeScanners();
- }
-
- /*
- * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
- */
- public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
- final MultiPassContentFormatter formatter= new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IDocument.DEFAULT_CONTENT_TYPE);
+ protected AbstractRubyScanner fMultilineCommentScanner, fSinglelineCommentScanner, fStringScanner;
+ private SingleTokenRubyCodeScanner fRegexpScanner;
+ private SingleTokenRubyCodeScanner fCommandScanner;
+ private RubyDoubleClickSelector fRubyDoubleClickSelector;
+ private RubyCompletionProcessor fRubyCp;
+
+ /**
+ * Creates a new Ruby source viewer configuration for viewers in the given
+ * editor using the given preference store, the color manager and the
+ * specified document partitioning.
+ * <p>
+ * Creates a Ruby source viewer configuration in the new setup without text
+ * tools. Clients are allowed to call
+ * {@link RubySourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}
+ * and disallowed to call
+ * {@link RubySourceViewerConfiguration#getPreferenceStore()} on the
+ * resulting Ruby source viewer configuration.
+ * </p>
+ *
+ * @param colorManager
+ * the color manager
+ * @param preferenceStore
+ * the preference store, can be read-only
+ * @param editor
+ * the editor in which the configured viewer(s) will reside, or
+ * <code>null</code> if none
+ * @param partitioning
+ * the document partitioning for this configuration, or
+ * <code>null</code> for the default partitioning
+ * @since 3.0
+ */
+ public RubySourceViewerConfiguration(IColorManager colorManager,
+ IPreferenceStore preferenceStore, ITextEditor editor,
+ String partitioning) {
+ super(preferenceStore);
+ fColorManager = colorManager;
+ fTextEditor = editor;
+ fDocumentPartitioning = partitioning;
+ initializeScanners();
+ }
- formatter.setMasterStrategy(new RubyFormattingStrategy());
- formatter.setSlaveStrategy(new CommentFormattingStrategy(), IRubyPartitions.RUBY_DOC);
- formatter.setSlaveStrategy(new CommentFormattingStrategy(), IRubyPartitions.RUBY_SINGLE_LINE_COMMENT);
- formatter.setSlaveStrategy(new CommentFormattingStrategy(), IRubyPartitions.RUBY_MULTI_LINE_COMMENT);
+ /*
+ * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
+ */
+ public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
+ final MultiPassContentFormatter formatter = new MultiPassContentFormatter(
+ getConfiguredDocumentPartitioning(sourceViewer),
+ IDocument.DEFAULT_CONTENT_TYPE);
- return formatter;
- }
-
- @Override
- public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
- if (!fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
+ formatter.setMasterStrategy(new RubyFormattingStrategy());
+ formatter.setSlaveStrategy(new CommentFormattingStrategy(),
+ IRubyPartitions.RUBY_DOC);
+ formatter.setSlaveStrategy(new CommentFormattingStrategy(),
+ IRubyPartitions.RUBY_SINGLE_LINE_COMMENT);
+ formatter.setSlaveStrategy(new CommentFormattingStrategy(),
+ IRubyPartitions.RUBY_MULTI_LINE_COMMENT);
+
+ return formatter;
+ }
+
+ @Override
+ public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
+ if (!fPreferenceStore
+ .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
return null;
- IHyperlinkDetector[] inheritedDetectors= super.getHyperlinkDetectors(sourceViewer);
+ IHyperlinkDetector[] inheritedDetectors = super
+ .getHyperlinkDetectors(sourceViewer);
if (fTextEditor == null)
return inheritedDetectors;
- int inheritedDetectorsLength= inheritedDetectors != null ? inheritedDetectors.length : 0;
- IHyperlinkDetector[] detectors= new IHyperlinkDetector[inheritedDetectorsLength + 1];
- detectors[0]= new RubyHyperLinkDetector(fTextEditor.getEditorInput());
- for (int i= 0; i < inheritedDetectorsLength; i++)
- detectors[i+1]= inheritedDetectors[i];
+ int inheritedDetectorsLength = inheritedDetectors != null ? inheritedDetectors.length
+ : 0;
+ IHyperlinkDetector[] detectors = new IHyperlinkDetector[inheritedDetectorsLength + 1];
+ detectors[0] = new RubyHyperLinkDetector(fTextEditor.getEditorInput());
+ for (int i = 0; i < inheritedDetectorsLength; i++)
+ detectors[i + 1] = inheritedDetectors[i];
return detectors;
- }
+ }
- /**
- * Determines whether the preference change encoded by the given event
- * changes the behavior of one of its contained components.
- *
- * @param event
- * the event to be investigated
- * @return <code>true</code> if event causes a behavioral change
- * @since 0.8.0
- */
- public boolean affectsTextPresentation(PropertyChangeEvent event) {
- return fCodeScanner.affectsBehavior(event)
- || fMultilineCommentScanner.affectsBehavior(event)
- || fSinglelineCommentScanner.affectsBehavior(event)
- || fStringScanner.affectsBehavior(event) || fRegexpScanner.affectsBehavior(event)
- || fCommandScanner.affectsBehavior(event);
- }
-
- /**
- * Adapts the behavior of the contained components to the change
- * encoded in the given event.
- * <p>
- * Clients are not allowed to call this method if the old setup with
- * text tools is in use.
- * </p>
- *
- * @param event the event to which to adapt
- * @see RubySourceViewerConfiguration#RubySourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)
- * @since 0.8.0
- */
- public void handlePropertyChangeEvent(PropertyChangeEvent event) {
- Assert.isTrue(isNewSetup());
- if (fCodeScanner.affectsBehavior(event))
- fCodeScanner.adaptToPreferenceChange(event);
- if (fMultilineCommentScanner.affectsBehavior(event))
- fMultilineCommentScanner.adaptToPreferenceChange(event);
- if (fSinglelineCommentScanner.affectsBehavior(event))
- fSinglelineCommentScanner.adaptToPreferenceChange(event);
- if (fStringScanner.affectsBehavior(event))
- fStringScanner.adaptToPreferenceChange(event);
- if (fRegexpScanner.affectsBehavior(event))
- fRegexpScanner.adaptToPreferenceChange(event);
- if (fCommandScanner.affectsBehavior(event))
- fCommandScanner.adaptToPreferenceChange(event);
- }
+ /**
+ * Determines whether the preference change encoded by the given event
+ * changes the behavior of one of its contained components.
+ *
+ * @param event
+ * the event to be investigated
+ * @return <code>true</code> if event causes a behavioral change
+ * @since 0.8.0
+ */
+ public boolean affectsTextPresentation(PropertyChangeEvent event) {
+ return fCodeScanner.affectsBehavior(event)
+ || fMultilineCommentScanner.affectsBehavior(event)
+ || fSinglelineCommentScanner.affectsBehavior(event)
+ || fStringScanner.affectsBehavior(event)
+ || fRegexpScanner.affectsBehavior(event)
+ || fCommandScanner.affectsBehavior(event);
+ }
+ /**
+ * Adapts the behavior of the contained components to the change encoded in
+ * the given event.
+ * <p>
+ * Clients are not allowed to call this method if the old setup with text
+ * tools is in use.
+ * </p>
+ *
+ * @param event
+ * the event to which to adapt
+ * @see RubySourceViewerConfiguration#RubySourceViewerConfiguration(IColorManager,
+ * IPreferenceStore, ITextEditor, String)
+ * @since 0.8.0
+ */
+ public void handlePropertyChangeEvent(PropertyChangeEvent event) {
+ Assert.isTrue(isNewSetup());
+ if (fCodeScanner.affectsBehavior(event))
+ fCodeScanner.adaptToPreferenceChange(event);
+ if (fMultilineCommentScanner.affectsBehavior(event))
+ fMultilineCommentScanner.adaptToPreferenceChange(event);
+ if (fSinglelineCommentScanner.affectsBehavior(event))
+ fSinglelineCommentScanner.adaptToPreferenceChange(event);
+ if (fStringScanner.affectsBehavior(event))
+ fStringScanner.adaptToPreferenceChange(event);
+ if (fRegexpScanner.affectsBehavior(event))
+ fRegexpScanner.adaptToPreferenceChange(event);
+ if (fCommandScanner.affectsBehavior(event))
+ fCommandScanner.adaptToPreferenceChange(event);
+ }
- /**
- * Creates and returns a preference store which combines the preference
- * stores from the text tools and which is read-only.
- *
- * @param rubyTextTools
- * the Ruby text tools
- * @return the combined read-only preference store
- * @since 0.8.0
- */
- private static final IPreferenceStore createPreferenceStore(RubyTextTools rubyTextTools) {
- Assert.isNotNull(rubyTextTools);
- IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
- if (rubyTextTools.getCorePreferenceStore() == null)
- return new ChainedPreferenceStore(new IPreferenceStore[] {
- rubyTextTools.getPreferenceStore(), generalTextStore});
+ /**
+ * Creates and returns a preference store which combines the preference
+ * stores from the text tools and which is read-only.
+ *
+ * @param rubyTextTools
+ * the Ruby text tools
+ * @return the combined read-only preference store
+ * @since 0.8.0
+ */
+ private static final IPreferenceStore createPreferenceStore(
+ RubyTextTools rubyTextTools) {
+ Assert.isNotNull(rubyTextTools);
+ IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
+ if (rubyTextTools.getCorePreferenceStore() == null)
+ return new ChainedPreferenceStore(new IPreferenceStore[] {
+ rubyTextTools.getPreferenceStore(), generalTextStore });
- return new ChainedPreferenceStore(new IPreferenceStore[] {
- rubyTextTools.getPreferenceStore(),
- new PreferencesAdapter(rubyTextTools.getCorePreferenceStore()), generalTextStore});
- }
+ return new ChainedPreferenceStore(new IPreferenceStore[] {
+ rubyTextTools.getPreferenceStore(),
+ new PreferencesAdapter(rubyTextTools.getCorePreferenceStore()),
+ generalTextStore });
+ }
- /**
- * Initializes the scanners.
- *
- * @since 3.0
- */
- private void initializeScanners() {
- Assert.isTrue(isNewSetup());
- fCodeScanner = new RubyCodeScanner(getColorManager(), fPreferenceStore);
- fMultilineCommentScanner = new RubyCommentScanner(getColorManager(), fPreferenceStore,
- IRubyColorConstants.RUBY_MULTI_LINE_COMMENT);
- fSinglelineCommentScanner = new RubyCommentScanner(getColorManager(), fPreferenceStore,
- IRubyColorConstants.RUBY_SINGLE_LINE_COMMENT);
- fStringScanner = new SingleTokenRubyCodeScanner(getColorManager(), fPreferenceStore,
- IRubyColorConstants.RUBY_STRING);
- fRegexpScanner = new SingleTokenRubyCodeScanner(getColorManager(), fPreferenceStore,
- IRubyColorConstants.RUBY_REGEXP);
- fCommandScanner = new SingleTokenRubyCodeScanner(getColorManager(), fPreferenceStore,
- IRubyColorConstants.RUBY_COMMAND);
- }
+ /**
+ * Initializes the scanners.
+ *
+ * @since 3.0
+ */
+ private void initializeScanners() {
+ Assert.isTrue(isNewSetup());
+ fCodeScanner = new RubyCodeScanner(getColorManager(), fPreferenceStore);
+ fMultilineCommentScanner = new RubyCommentScanner(getColorManager(),
+ fPreferenceStore, IRubyColorConstants.RUBY_MULTI_LINE_COMMENT);
+ fSinglelineCommentScanner = new RubyCommentScanner(getColorManager(),
+ fPreferenceStore, IRubyColorConstants.RUBY_SINGLE_LINE_COMMENT);
+ fStringScanner = new SingleTokenRubyCodeScanner(getColorManager(),
+ fPreferenceStore, IRubyColorConstants.RUBY_STRING);
+ fRegexpScanner = new SingleTokenRubyCodeScanner(getColorManager(),
+ fPreferenceStore, IRubyColorConstants.RUBY_REGEXP);
+ fCommandScanner = new SingleTokenRubyCodeScanner(getColorManager(),
+ fPreferenceStore, IRubyColorConstants.RUBY_COMMAND);
+ }
- /**
- * @return <code>true</code> iff the new setup without text tools is in
- * use.
- *
- * @since 3.0
- */
- private boolean isNewSetup() {
- return textTools == null;
- }
+ /**
+ * @return <code>true</code> iff the new setup without text tools is in
+ * use.
+ *
+ * @since 3.0
+ */
+ private boolean isNewSetup() {
+ return textTools == null;
+ }
- /**
- * Returns the color manager for this configuration.
- *
- * @return the color manager
- */
- protected IColorManager getColorManager() {
- return fColorManager;
- }
+ /**
+ * Returns the color manager for this configuration.
+ *
+ * @return the color manager
+ */
+ protected IColorManager getColorManager() {
+ return fColorManager;
+ }
- public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
- PresentationReconciler reconciler = new PresentationReconciler();
- reconciler.setDocumentPartitioning(IRubyPartitions.RUBY_PARTITIONING);
+ public IPresentationReconciler getPresentationReconciler(
+ ISourceViewer sourceViewer) {
+ PresentationReconciler reconciler = new PresentationReconciler();
+ reconciler.setDocumentPartitioning(IRubyPartitions.RUBY_PARTITIONING);
- DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getCodeScanner());
- reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
- reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getCodeScanner());
+ reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
- dr = new DefaultDamagerRepairer(getSinglelineCommentScanner());
- reconciler.setDamager(dr, RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT);
- reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT);
+ dr = new DefaultDamagerRepairer(getSinglelineCommentScanner());
+ reconciler
+ .setDamager(dr, RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT);
+ reconciler.setRepairer(dr,
+ RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT);
- dr = new DefaultDamagerRepairer(getMultilineCommentScanner());
- reconciler.setDamager(dr, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT);
- reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT);
+ dr = new DefaultDamagerRepairer(getMultilineCommentScanner());
+ reconciler.setDamager(dr, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT);
+ reconciler
+ .setRepairer(dr, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT);
- dr = new DefaultDamagerRepairer(getStringScanner());
- reconciler.setDamager(dr, RubyPartitionScanner.RUBY_STRING);
- reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_STRING);
+ dr = new DefaultDamagerRepairer(getStringScanner());
+ reconciler.setDamager(dr, RubyPartitionScanner.RUBY_STRING);
+ reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_STRING);
- dr = new DefaultDamagerRepairer(getRegexpScanner());
- reconciler.setDamager(dr, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION);
- reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION);
+ dr = new DefaultDamagerRepairer(getRegexpScanner());
+ reconciler.setDamager(dr, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION);
+ reconciler
+ .setRepairer(dr, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION);
- dr = new DefaultDamagerRepairer(getCommandScanner());
- reconciler.setDamager(dr, RubyPartitionScanner.RUBY_COMMAND);
- reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_COMMAND);
+ dr = new DefaultDamagerRepairer(getCommandScanner());
+ reconciler.setDamager(dr, RubyPartitionScanner.RUBY_COMMAND);
+ reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_COMMAND);
- return reconciler;
- }
+ return reconciler;
+ }
- private ITokenScanner getCommandScanner() {
- return fCommandScanner;
- }
+ private ITokenScanner getCommandScanner() {
+ return fCommandScanner;
+ }
- protected ITokenScanner getCodeScanner() {
- return fCodeScanner;
- }
+ protected ITokenScanner getCodeScanner() {
+ return fCodeScanner;
+ }
- protected ITokenScanner getMultilineCommentScanner() {
- return fMultilineCommentScanner;
- }
+ protected ITokenScanner getMultilineCommentScanner() {
+ return fMultilineCommentScanner;
+ }
- protected ITokenScanner getSinglelineCommentScanner() {
- return fSinglelineCommentScanner;
- }
+ protected ITokenScanner getSinglelineCommentScanner() {
+ return fSinglelineCommentScanner;
+ }
- protected ITokenScanner getStringScanner() {
- return fStringScanner;
- }
+ protected ITokenScanner getStringScanner() {
+ return fStringScanner;
+ }
- protected ITokenScanner getRegexpScanner() {
- return fRegexpScanner;
- }
+ protected ITokenScanner getRegexpScanner() {
+ return fRegexpScanner;
+ }
- public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
- return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
- RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT, RubyPartitionScanner.RUBY_STRING,
- RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT};
- }
-
- /*
- * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
- * @since 0.8.0
- */
- public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
- if (fDocumentPartitioning != null)
- return fDocumentPartitioning;
- return super.getConfiguredDocumentPartitioning(sourceViewer);
- }
+ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
+ return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
+ RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT,
+ RubyPartitionScanner.RUBY_STRING,
+ RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT };
+ }
- public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
- ContentAssistant contentAssistant = new ContentAssistant();
- contentAssistant.setContentAssistProcessor(new RubyCompletionProcessor(getEditor()),
- IDocument.DEFAULT_CONTENT_TYPE);
+ /*
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
+ * @since 0.8.0
+ */
+ public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
+ if (fDocumentPartitioning != null)
+ return fDocumentPartitioning;
+ return super.getConfiguredDocumentPartitioning(sourceViewer);
+ }
- contentAssistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
- contentAssistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
+ public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
+ fRubyCp = new RubyCompletionProcessor(getEditor());
- ContentAssistPreference.configure(contentAssistant, getPreferenceStore());
- return contentAssistant;
- }
+ ContentAssistant contentAssistant = new ContentAssistant();
+ contentAssistant.setContentAssistProcessor(fRubyCp,
+ IDocument.DEFAULT_CONTENT_TYPE);
- /*
- * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
- */
- public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
- return new RubyAnnotationHover(RubyAnnotationHover.VERTICAL_RULER_HOVER);
- }
-
- public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
- String partitioning= getConfiguredDocumentPartitioning(sourceViewer);
- if (IRubyPartitions.RUBY_SINGLE_LINE_COMMENT.equals(contentType))
- return new IAutoEditStrategy[] { new RubyCommentAutoIndentStrategy(partitioning) };
- else
+ contentAssistant
+ .setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
+ contentAssistant
+ .setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
+
+ ContentAssistPreference.configure(contentAssistant,
+ getPreferenceStore());
+ return contentAssistant;
+ }
+
+ /*
+ * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
+ */
+ public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
+ return new RubyAnnotationHover(RubyAnnotationHover.VERTICAL_RULER_HOVER);
+ }
+
+ public IAutoEditStrategy[] getAutoEditStrategies(
+ ISourceViewer sourceViewer, String contentType) {
+ String partitioning = getConfiguredDocumentPartitioning(sourceViewer);
+ if (IRubyPartitions.RUBY_SINGLE_LINE_COMMENT.equals(contentType)) {
+ return new IAutoEditStrategy[] { new RubyCommentAutoIndentStrategy(
+ partitioning) };
+ } else if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) {
+ IAutoEditStrategy[] strategies = super.getAutoEditStrategies(
+ sourceViewer, contentType);
+ IAutoEditStrategy[] newStrategies = new IAutoEditStrategy[strategies.length + 1];
+ System
+ .arraycopy(strategies, 0, newStrategies, 0,
+ strategies.length);
+ newStrategies[newStrategies.length - 1] = new RubyAutoEditStrategy(
+ partitioning, sourceViewer, fRubyCp);
+ strategies = newStrategies;
+ return strategies;
+ } else {
return super.getAutoEditStrategies(sourceViewer, contentType);
- }
+ }
+ }
- /*
- * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
- * @since 2.0
- */
- public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
- return new IInformationControlCreator() {
+ /*
+ * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
+ * @since 2.0
+ */
+ public IInformationControlCreator getInformationControlCreator(
+ ISourceViewer sourceViewer) {
+ return new IInformationControlCreator() {
- public IInformationControl createInformationControl(Shell parent) {
- return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true));
- }
- };
- }
+ public IInformationControl createInformationControl(Shell parent) {
+ return new DefaultInformationControl(parent, SWT.NONE,
+ new HTMLTextPresenter(true));
+ }
+ };
+ }
- /**
- * Returns the editor in which the configured viewer(s) will reside.
- *
- * @return the enclosing editor
- */
- protected ITextEditor getEditor() {
- return fTextEditor;
- }
+ /**
+ * Returns the editor in which the configured viewer(s) will reside.
+ *
+ * @return the enclosing editor
+ */
+ protected ITextEditor getEditor() {
+ return fTextEditor;
+ }
- protected IPreferenceStore getPreferenceStore() {
- return RubyPlugin.getDefault().getPreferenceStore();
- }
+ protected IPreferenceStore getPreferenceStore() {
+ return RubyPlugin.getDefault().getPreferenceStore();
+ }
- public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) {
- return new String[] { "#", ""};
- }
+ public String[] getDefaultPrefixes(ISourceViewer sourceViewer,
+ String contentType) {
+ return new String[] { "#", "" };
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer)
- */
- public IReconciler getReconciler(ISourceViewer sourceViewer) {
- final ITextEditor editor = getEditor();
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer)
+ */
+ public IReconciler getReconciler(ISourceViewer sourceViewer) {
+ final ITextEditor editor = getEditor();
if (editor != null && editor.isEditable()) {
RubyReconciler reconciler = new RubyReconciler(fTextEditor,
new RubyReconcilingStrategy(
@@ -409,19 +453,19 @@
return reconciler;
}
return null;
- }
-
- private IRubyProject getProject() {
- ITextEditor editor= getEditor();
+ }
+
+ private IRubyProject getProject() {
+ ITextEditor editor = getEditor();
if (editor == null)
return null;
- IRubyElement element= null;
- IEditorInput input= editor.getEditorInput();
- IDocumentProvider provider= editor.getDocumentProvider();
+ IRubyElement element = null;
+ IEditorInput input = editor.getEditorInput();
+ IDocumentProvider provider = editor.getDocumentProvider();
if (provider instanceof IRubyScriptDocumentProvider) {
- IRubyScriptDocumentProvider cudp= (IRubyScriptDocumentProvider) provider;
- element= cudp.getWorkingCopy(input);
+ IRubyScriptDocumentProvider cudp = (IRubyScriptDocumentProvider) provider;
+ element = cudp.getWorkingCopy(input);
}
if (element == null)
@@ -430,37 +474,43 @@
return element.getRubyProject();
}
- public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
+ public String[] getIndentPrefixes(ISourceViewer sourceViewer,
+ String contentType) {
- Vector vector= new Vector();
+ Vector vector = new Vector();
// prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
- IRubyProject project= getProject();
- final int tabWidth= CodeFormatterUtil.getTabWidth(project);
- final int indentWidth= CodeFormatterUtil.getIndentWidth(project);
- int spaceEquivalents= Math.min(tabWidth, indentWidth);
+ IRubyProject project = getProject();
+ final int tabWidth = CodeFormatterUtil.getTabWidth(project);
+ final int indentWidth = CodeFormatterUtil.getIndentWidth(project);
+ int spaceEquivalents = Math.min(tabWidth, indentWidth);
boolean useSpaces;
if (project == null)
- useSpaces= RubyCore.SPACE.equals(RubyCore.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR)) || tabWidth > indentWidth;
+ useSpaces = RubyCore.SPACE
+ .equals(RubyCore
+ .getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR))
+ || tabWidth > indentWidth;
else
- useSpaces= RubyCore.SPACE.equals(project.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, true)) || tabWidth > indentWidth;
+ useSpaces = RubyCore.SPACE.equals(project.getOption(
+ DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, true))
+ || tabWidth > indentWidth;
- for (int i= 0; i <= spaceEquivalents; i++) {
- StringBuffer prefix= new StringBuffer();
+ for (int i = 0; i <= spaceEquivalents; i++) {
+ StringBuffer prefix = new StringBuffer();
if (useSpaces) {
- for (int j= 0; j + i < spaceEquivalents; j++)
- prefix.append(' ');
+ for (int j = 0; j + i < spaceEquivalents; j++)
+ prefix.append(' ');
if (i != 0)
- prefix.append('\t');
+ prefix.append('\t');
} else {
- for (int j= 0; j < i; j++)
- prefix.append(' ');
+ for (int j = 0; j < i; j++)
+ prefix.append(' ');
if (i != spaceEquivalents)
- prefix.append('\t');
+ prefix.append('\t');
}
vector.add(prefix.toString());
@@ -469,16 +519,16 @@
vector.add(""); //$NON-NLS-1$
return (String[]) vector.toArray(new String[vector.size()]);
- }
+ }
- public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer,
- String contentType) {
- if (fRubyDoubleClickSelector == null) {
- fRubyDoubleClickSelector= new RubyDoubleClickSelector();
- }
- return fRubyDoubleClickSelector;
- }
-
+ public ITextDoubleClickStrategy getDoubleClickStrategy(
+ ISourceViewer sourceViewer, String contentType) {
+ if (fRubyDoubleClickSelector == null) {
+ fRubyDoubleClickSelector = new RubyDoubleClickSelector();
+ }
+ return fRubyDoubleClickSelector;
+ }
+
/*
* @see SourceViewerConfiguration#getTabWidth(ISourceViewer)
*/
@@ -486,11 +536,12 @@
return CodeFormatterUtil.getTabWidth(getProject());
}
- public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
- if (fRubyTextHover == null) {
- fRubyTextHover = new RubyCodeTextHover();
- }
- return fRubyTextHover;
- }
+ public ITextHover getTextHover(ISourceViewer sourceViewer,
+ String contentType) {
+ if (fRubyTextHover == null) {
+ fRubyTextHover = new RubyCodeTextHover();
+ }
+ return fRubyTextHover;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|