You can subscribe to this list here.
| 2005 |
Jan
|
Feb
|
Mar
(41) |
Apr
(9) |
May
|
Jun
|
Jul
(39) |
Aug
(38) |
Sep
(135) |
Oct
(220) |
Nov
(75) |
Dec
(74) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2006 |
Jan
(44) |
Feb
(160) |
Mar
(49) |
Apr
(69) |
May
(40) |
Jun
(52) |
Jul
(47) |
Aug
(51) |
Sep
(19) |
Oct
(22) |
Nov
(36) |
Dec
(76) |
| 2007 |
Jan
(154) |
Feb
(165) |
Mar
(186) |
Apr
(143) |
May
(175) |
Jun
(133) |
Jul
(203) |
Aug
(177) |
Sep
(136) |
Oct
|
Nov
|
Dec
|
|
From: <caw...@us...> - 2007-05-29 13:22:47
|
Revision: 2547
http://svn.sourceforge.net/rubyeclipse/?rev=2547&view=rev
Author: cawilliams
Date: 2007-05-29 06:22:45 -0700 (Tue, 29 May 2007)
Log Message:
-----------
include CommentHoverProvider, and also allow F2 to change focus to RDoc when it is shown. (so you can read the whole thing)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/plugin.properties
trunk/org.rubypeople.rdt.ui/plugin.xml
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorActionContributor.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.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/text/ruby/hover/RubyInformationProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyTypeHover.java
Modified: trunk/org.rubypeople.rdt.ui/plugin.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.properties 2007-05-29 13:21:21 UTC (rev 2546)
+++ trunk/org.rubypeople.rdt.ui/plugin.properties 2007-05-29 13:22:45 UTC (rev 2547)
@@ -57,6 +57,8 @@
buildPathPageName=Ruby Load Path
+commentHover=Ruby RDoc comment hover
+
PerspectiveRuby.name=Ruby
ViewRubyResources.name=Ruby Resources
Modified: trunk/org.rubypeople.rdt.ui/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.xml 2007-05-29 13:21:21 UTC (rev 2546)
+++ trunk/org.rubypeople.rdt.ui/plugin.xml 2007-05-29 13:22:45 UTC (rev 2547)
@@ -442,6 +442,11 @@
contextId="org.rubypeople.rdt.ui.rubyEditorScope "
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
</key>
+ <key
+ sequence="F2"
+ contextId="org.rubypeople.rdt.ui.rubyEditorScope"
+ commandId="org.rubypeople.rdt.ui.edit.text.ruby.show.rdoc"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
<!-- alternative for some gtk input modes -->
<key
platform="gtk"
@@ -490,6 +495,12 @@
id="org.rubypeople.rdt.ui.category.project ">
</category>
<command
+ name="%ActionDefinition.showRdoc.name"
+ description="%ActionDefinition.showRdoc.description"
+ categoryId="org.eclipse.ui.category.edit"
+ id="org.rubypeople.rdt.ui.edit.text.ruby.show.rdoc">
+ </command>
+ <command
categoryId="org.rubypeople.rdt.ui.category.source"
description="%ActionDefinition.format.description"
id="org.rubypeople.rdt.ui.edit.text.ruby.format"
@@ -923,6 +934,10 @@
id="org.rubypeople.rdt.ui.ProblemHover">
</hover>
<hover
+ id="com.aptana.rdt.ui.RubyCommentHover"
+ class="org.rubypeople.rdt.internal.ui.text.ruby.hover.CommentHoverProvider"
+ label="%commentHover"/>
+ <hover
id="org.rubypeople.rdt.ui.RiDocHover"
class="org.rubypeople.rdt.internal.ui.text.ruby.hover.RiDocHoverProvider"
label="%rdocHover"/>
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java 2007-05-29 13:21:21 UTC (rev 2546)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java 2007-05-29 13:22:45 UTC (rev 2547)
@@ -3,6 +3,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Iterator;
+import java.util.ResourceBundle;
import java.util.Stack;
import org.eclipse.core.resources.IMarker;
@@ -20,24 +21,36 @@
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.AbstractInformationControlManager;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DefaultInformationControl;
import org.eclipse.jface.text.DocumentCommand;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension;
import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.ILineTracker;
import org.eclipse.jface.text.IPositionUpdater;
import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITextViewerExtension;
+import org.eclipse.jface.text.ITextViewerExtension2;
+import org.eclipse.jface.text.ITextViewerExtension4;
import org.eclipse.jface.text.ITextViewerExtension5;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextUtilities;
+import org.eclipse.jface.text.information.IInformationProvider;
+import org.eclipse.jface.text.information.IInformationProviderExtension;
+import org.eclipse.jface.text.information.IInformationProviderExtension2;
+import org.eclipse.jface.text.information.InformationPresenter;
import org.eclipse.jface.text.link.ILinkedModeListener;
import org.eclipse.jface.text.link.LinkedModeModel;
import org.eclipse.jface.text.link.LinkedModeUI;
@@ -46,11 +59,16 @@
import org.eclipse.jface.text.link.LinkedModeUI.ExitFlags;
import org.eclipse.jface.text.link.LinkedModeUI.IExitPolicy;
import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationHover;
+import org.eclipse.jface.text.source.IAnnotationHoverExtension;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.ICharacterPairMatcher;
+import org.eclipse.jface.text.source.ILineRange;
import org.eclipse.jface.text.source.IOverviewRuler;
import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.ISourceViewerExtension3;
import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.jface.text.source.IVerticalRulerInfo;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.text.source.projection.ProjectionSupport;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
@@ -60,11 +78,13 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.search.ui.IContextMenuConstants;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.custom.VerifyKeyListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPartListener2;
@@ -83,6 +103,8 @@
import org.eclipse.ui.texteditor.IEditorStatusLine;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
import org.eclipse.ui.texteditor.MarkerAnnotation;
+import org.eclipse.ui.texteditor.ResourceAction;
+import org.eclipse.ui.texteditor.TextEditorAction;
import org.eclipse.ui.texteditor.TextOperationAction;
import org.eclipse.ui.texteditor.link.EditorLinkedModeUI;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
@@ -96,12 +118,13 @@
import org.rubypeople.rdt.internal.corext.util.RubyModelUtil;
import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
-import org.rubypeople.rdt.internal.ui.RubyUIMessages;
import org.rubypeople.rdt.internal.ui.actions.CompositeActionGroup;
import org.rubypeople.rdt.internal.ui.actions.FoldingActionGroup;
+import org.rubypeople.rdt.internal.ui.text.HTMLTextPresenter;
import org.rubypeople.rdt.internal.ui.text.IRubyPartitions;
import org.rubypeople.rdt.internal.ui.text.RubyHeuristicScanner;
import org.rubypeople.rdt.internal.ui.text.Symbols;
+import org.rubypeople.rdt.internal.ui.text.ruby.hover.SourceViewerInformationControl;
import org.rubypeople.rdt.ui.IWorkingCopyManager;
import org.rubypeople.rdt.ui.PreferenceConstants;
import org.rubypeople.rdt.ui.actions.FormatAction;
@@ -177,6 +200,8 @@
private CompositeActionGroup fActionGroups;
private CompositeActionGroup fContextMenuGroup;
+ private InformationPresenter fInformationPresenter;
+
public RubyEditor() {
super();
@@ -242,6 +267,12 @@
ISelectionProvider provider= getSite().getSelectionProvider();
ISelection selection= provider.getSelection();
+ ResourceAction resAction= new TextOperationAction(RubyEditorMessages.getBundleForConstructedKeys(), "ShowRDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$
+ resAction= new InformationDispatchAction(RubyEditorMessages.getBundleForConstructedKeys(), "ShowRDoc.", (TextOperationAction) resAction); //$NON-NLS-1$
+ resAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SHOW_RDOC);
+ setAction("ShowRDoc", resAction); //$NON-NLS-1$
+// PlatformUI.getWorkbench().getHelpSystem().setHelp(resAction, IRubyHelpContextIds.SHOW_JAVADOC_ACTION);
+
SurroundWithBeginRescueAction beginRescueAction = new SurroundWithBeginRescueAction(this);
beginRescueAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SURROUND_WITH_BEGIN_RESCUE);
beginRescueAction.update(selection);
@@ -273,6 +304,19 @@
public void createPartControl(Composite parent) {
super.createPartControl(parent);
+ IInformationControlCreator informationControlCreator= new IInformationControlCreator() {
+ public IInformationControl createInformationControl(Shell shell) {
+ boolean cutDown= false;
+ int style= cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL);
+ return new DefaultInformationControl(shell, SWT.RESIZE | SWT.TOOL, style, new HTMLTextPresenter(cutDown));
+ }
+ };
+
+ fInformationPresenter= new InformationPresenter(informationControlCreator);
+ fInformationPresenter.setSizeConstraints(60, 10, true, true);
+ fInformationPresenter.install(getSourceViewer());
+ fInformationPresenter.setDocumentPartitioning(IRubyPartitions.RUBY_PARTITIONING);
+
ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(),
@@ -1674,4 +1718,248 @@
option= project.getOption(SPACES_FOR_TABS, true);
return RubyCore.SPACE.equals(option);
}
+
+ /**
+ * This action behaves in two different ways: If there is no current text
+ * hover, the javadoc is displayed using information presenter. If there is
+ * a current text hover, it is converted into a information presenter in
+ * order to make it sticky.
+ */
+ class InformationDispatchAction extends TextEditorAction {
+
+ /** The wrapped text operation action. */
+ private final TextOperationAction fTextOperationAction;
+
+ /**
+ * Creates a dispatch action.
+ *
+ * @param resourceBundle the resource bundle
+ * @param prefix the prefix
+ * @param textOperationAction the text operation action
+ */
+ public InformationDispatchAction(ResourceBundle resourceBundle, String prefix, final TextOperationAction textOperationAction) {
+ super(resourceBundle, prefix, RubyEditor.this);
+ if (textOperationAction == null)
+ throw new IllegalArgumentException();
+ fTextOperationAction= textOperationAction;
+ }
+
+ /*
+ * @see org.eclipse.jface.action.IAction#run()
+ */
+ public void run() {
+
+ ISourceViewer sourceViewer= getSourceViewer();
+ if (sourceViewer == null) {
+ fTextOperationAction.run();
+ return;
+ }
+
+ if (sourceViewer instanceof ITextViewerExtension4) {
+ ITextViewerExtension4 extension4= (ITextViewerExtension4) sourceViewer;
+ if (extension4.moveFocusToWidgetToken())
+ return;
+ }
+
+ if (sourceViewer instanceof ITextViewerExtension2) {
+ // does a text hover exist?
+ ITextHover textHover= ((ITextViewerExtension2) sourceViewer).getCurrentTextHover();
+ if (textHover != null && makeTextHoverFocusable(sourceViewer, textHover))
+ return;
+ }
+
+ if (sourceViewer instanceof ISourceViewerExtension3) {
+ // does an annotation hover exist?
+ IAnnotationHover annotationHover= ((ISourceViewerExtension3) sourceViewer).getCurrentAnnotationHover();
+ if (annotationHover != null && makeAnnotationHoverFocusable(sourceViewer, annotationHover))
+ return;
+ }
+
+ // otherwise, just run the action
+ fTextOperationAction.run();
+ }
+
+ /**
+ * Tries to make a text hover focusable (or "sticky").
+ *
+ * @param sourceViewer the source viewer to display the hover over
+ * @param textHover the hover to make focusable
+ * @return <code>true</code> if successful, <code>false</code> otherwise
+ * @since 3.2
+ */
+ private boolean makeTextHoverFocusable(ISourceViewer sourceViewer, ITextHover textHover) {
+ Point hoverEventLocation= ((ITextViewerExtension2) sourceViewer).getHoverEventLocation();
+ int offset= computeOffsetAtLocation(sourceViewer, hoverEventLocation.x, hoverEventLocation.y);
+ if (offset == -1)
+ return false;
+
+ try {
+ IRegion hoverRegion= textHover.getHoverRegion(sourceViewer, offset);
+ if (hoverRegion == null)
+ return false;
+
+ String hoverInfo= textHover.getHoverInfo(sourceViewer, hoverRegion);
+
+ IInformationControlCreator controlCreator= null;
+ if (textHover instanceof IInformationProviderExtension2)
+ controlCreator= ((IInformationProviderExtension2)textHover).getInformationPresenterControlCreator();
+
+ IInformationProvider informationProvider= new InformationProvider(hoverRegion, hoverInfo, controlCreator);
+
+ fInformationPresenter.setOffset(offset);
+ fInformationPresenter.setAnchor(AbstractInformationControlManager.ANCHOR_BOTTOM);
+ fInformationPresenter.setMargins(6, 6); // default values from AbstractInformationControlManager
+ String contentType= TextUtilities.getContentType(sourceViewer.getDocument(), IRubyPartitions.RUBY_PARTITIONING, offset, true);
+ fInformationPresenter.setInformationProvider(informationProvider, contentType);
+ fInformationPresenter.showInformation();
+
+ return true;
+
+ } catch (BadLocationException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Tries to make an annotation hover focusable (or "sticky").
+ *
+ * @param sourceViewer the source viewer to display the hover over
+ * @param annotationHover the hover to make focusable
+ * @return <code>true</code> if successful, <code>false</code> otherwise
+ * @since 3.2
+ */
+ private boolean makeAnnotationHoverFocusable(ISourceViewer sourceViewer, IAnnotationHover annotationHover) {
+ IVerticalRulerInfo info= getVerticalRuler();
+ int line= info.getLineOfLastMouseButtonActivity();
+ if (line == -1)
+ return false;
+
+ try {
+
+ // compute the hover information
+ Object hoverInfo;
+ if (annotationHover instanceof IAnnotationHoverExtension) {
+ IAnnotationHoverExtension extension= (IAnnotationHoverExtension) annotationHover;
+ ILineRange hoverLineRange= extension.getHoverLineRange(sourceViewer, line);
+ if (hoverLineRange == null)
+ return false;
+ final int maxVisibleLines= Integer.MAX_VALUE; // allow any number of lines being displayed, as we support scrolling
+ hoverInfo= extension.getHoverInfo(sourceViewer, hoverLineRange, maxVisibleLines);
+ } else {
+ hoverInfo= annotationHover.getHoverInfo(sourceViewer, line);
+ }
+
+ // hover region: the beginning of the concerned line to place the control right over the line
+ IDocument document= sourceViewer.getDocument();
+ int offset= document.getLineOffset(line);
+ String contentType= TextUtilities.getContentType(document, IRubyPartitions.RUBY_PARTITIONING, offset, true);
+
+ IInformationControlCreator controlCreator= null;
+
+ /*
+ * XXX: This is a hack to avoid API changes at the end of 3.2,
+ * and should be fixed for 3.3, see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=137967
+ */
+ if ("org.eclipse.jface.text.source.projection.ProjectionAnnotationHover".equals(annotationHover.getClass().getName())) { //$NON-NLS-1$
+ controlCreator= new IInformationControlCreator() {
+ public IInformationControl createInformationControl(Shell shell) {
+ int shellStyle= SWT.RESIZE | SWT.TOOL | getOrientation();
+ int style= SWT.V_SCROLL | SWT.H_SCROLL;
+ return new SourceViewerInformationControl(shell, shellStyle, style);
+ }
+ };
+
+ } else {
+ if (annotationHover instanceof IInformationProviderExtension2)
+ controlCreator= ((IInformationProviderExtension2) annotationHover).getInformationPresenterControlCreator();
+ else if (annotationHover instanceof IAnnotationHoverExtension)
+ controlCreator= ((IAnnotationHoverExtension) annotationHover).getHoverControlCreator();
+ }
+
+ IInformationProvider informationProvider= new InformationProvider(new Region(offset, 0), hoverInfo, controlCreator);
+
+ fInformationPresenter.setOffset(offset);
+ fInformationPresenter.setAnchor(AbstractInformationControlManager.ANCHOR_RIGHT);
+ fInformationPresenter.setMargins(4, 0); // AnnotationBarHoverManager sets (5,0), minus SourceViewer.GAP_SIZE_1
+ fInformationPresenter.setInformationProvider(informationProvider, contentType);
+ fInformationPresenter.showInformation();
+
+ return true;
+
+ } catch (BadLocationException e) {
+ return false;
+ }
+ }
+
+ // modified version from TextViewer
+ private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) {
+
+ StyledText styledText= textViewer.getTextWidget();
+ IDocument document= textViewer.getDocument();
+
+ if (document == null)
+ return -1;
+
+ try {
+ int widgetOffset= styledText.getOffsetAtLocation(new Point(x, y));
+ Point p= styledText.getLocationAtOffset(widgetOffset);
+ if (p.x > x)
+ widgetOffset--;
+
+ if (textViewer instanceof ITextViewerExtension5) {
+ ITextViewerExtension5 extension= (ITextViewerExtension5) textViewer;
+ return extension.widgetOffset2ModelOffset(widgetOffset);
+ } else {
+ IRegion visibleRegion= textViewer.getVisibleRegion();
+ return widgetOffset + visibleRegion.getOffset();
+ }
+ } catch (IllegalArgumentException e) {
+ return -1;
+ }
+
+ }
+ }
+
+ /**
+ * Information provider used to present focusable information shells.
+ *
+ * @since 3.2
+ */
+ private static final class InformationProvider implements IInformationProvider, IInformationProviderExtension, IInformationProviderExtension2 {
+
+ private IRegion fHoverRegion;
+ private Object fHoverInfo;
+ private IInformationControlCreator fControlCreator;
+
+ InformationProvider(IRegion hoverRegion, Object hoverInfo, IInformationControlCreator controlCreator) {
+ fHoverRegion= hoverRegion;
+ fHoverInfo= hoverInfo;
+ fControlCreator= controlCreator;
+ }
+ /*
+ * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, int)
+ */
+ public IRegion getSubject(ITextViewer textViewer, int invocationOffset) {
+ return fHoverRegion;
+ }
+ /*
+ * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
+ */
+ public String getInformation(ITextViewer textViewer, IRegion subject) {
+ return fHoverInfo.toString();
+ }
+ /*
+ * @see org.eclipse.jface.text.information.IInformationProviderExtension#getInformation2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
+ * @since 3.2
+ */
+ public Object getInformation2(ITextViewer textViewer, IRegion subject) {
+ return fHoverInfo;
+ }
+ /*
+ * @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator()
+ */
+ public IInformationControlCreator getInformationPresenterControlCreator() {
+ return fControlCreator;
+ }
+ }
}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorActionContributor.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorActionContributor.java 2007-05-29 13:21:21 UTC (rev 2546)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorActionContributor.java 2007-05-29 13:22:45 UTC (rev 2547)
@@ -1,5 +1,8 @@
package org.rubypeople.rdt.internal.ui.rubyeditor;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import java.util.ResourceBundle;
import org.eclipse.jface.action.IAction;
@@ -8,6 +11,8 @@
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.actions.RetargetAction;
import org.eclipse.ui.ide.IDEActionFactory;
import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
import org.eclipse.ui.texteditor.ITextEditor;
@@ -17,17 +22,27 @@
import org.rubypeople.rdt.internal.ui.RubyUIMessages;
import org.rubypeople.rdt.internal.ui.actions.FoldingActionGroup;
import org.rubypeople.rdt.ui.actions.IRubyEditorActionDefinitionIds;
+import org.rubypeople.rdt.ui.actions.RdtActionConstants;
import org.rubypeople.rdt.ui.actions.RubyActionIds;
public class RubyEditorActionContributor extends BasicTextEditorActionContributor {
+ private List fPartListeners= new ArrayList();
+
protected RetargetTextEditorAction contentAssistProposal;
private RetargetTextEditorAction fGotoMatchingBracket;
private RetargetTextEditorAction fQuickAssistAction;
+
+ private RetargetAction fRetargetShowRubyDoc;
+ private RetargetTextEditorAction fShowRubyDoc;
public RubyEditorActionContributor() {
super();
ResourceBundle b = RubyEditorMessages.getBundleForConstructedKeys();
+
+ fRetargetShowRubyDoc= new RetargetAction(RdtActionConstants.SHOW_RUBY_DOC, RubyEditorMessages.ShowRDoc_label);
+ fRetargetShowRubyDoc.setActionDefinitionId(IRubyEditorActionDefinitionIds.SHOW_RDOC);
+ markAsPartListener(fRetargetShowRubyDoc);
contentAssistProposal = new RetargetTextEditorAction(RubyUIMessages.getResourceBundle(),
"ContentAssistProposal.");
@@ -38,7 +53,13 @@
fQuickAssistAction= new RetargetTextEditorAction(RubyEditorMessages.getBundleForConstructedKeys(), "CorrectionAssistProposal."); //$NON-NLS-1$
fQuickAssistAction.setActionDefinitionId(ITextEditorActionDefinitionIds.QUICK_ASSIST);
+ fShowRubyDoc= new RetargetTextEditorAction(b, "ShowRDoc."); //$NON-NLS-1$
+ fShowRubyDoc.setActionDefinitionId(IRubyEditorActionDefinitionIds.SHOW_RDOC);
}
+
+ protected final void markAsPartListener(RetargetAction action) {
+ fPartListeners.add(action);
+ }
public void contributeToMenu(IMenuManager menuManager) {
IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
@@ -98,4 +119,37 @@
actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId()));
actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId()));
}
+
+ @Override
+ public void init(IActionBars bars, IWorkbenchPage page) {
+ Iterator e= fPartListeners.iterator();
+ while (e.hasNext())
+ page.addPartListener((RetargetAction) e.next());
+
+ super.init(bars, page);
+//
+// bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
+// bars.setGlobalActionHandler(IRubyEditorActionDefinitionIds.TOGGLE_MARK_OCCURRENCES, fToggleMarkOccurrencesAction);
+
+ bars.setGlobalActionHandler(RdtActionConstants.SHOW_RUBY_DOC, fShowRubyDoc);
+ }
+
+ /*
+ * @see IEditorActionBarContributor#dispose()
+ */
+ public void dispose() {
+
+ Iterator e= fPartListeners.iterator();
+ while (e.hasNext())
+ getPage().removePartListener((RetargetAction) e.next());
+ fPartListeners.clear();
+
+ if (fRetargetShowRubyDoc != null) {
+ fRetargetShowRubyDoc.dispose();
+ fRetargetShowRubyDoc= null;
+ }
+
+ setActiveEditor(null);
+ super.dispose();
+ }
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorMessages.java 2007-05-29 13:21:21 UTC (rev 2546)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorMessages.java 2007-05-29 13:22:45 UTC (rev 2547)
@@ -42,6 +42,8 @@
private static final String BUNDLE_FOR_CONSTRUCTED_KEYS= "org.rubypeople.rdt.internal.ui.rubyeditor.ConstructedRubyEditorMessages";//$NON-NLS-1$
private static ResourceBundle fgBundleForConstructedKeys= ResourceBundle.getBundle(BUNDLE_FOR_CONSTRUCTED_KEYS);
+ public static String ShowRDoc_label;
+
/**
* Returns the message bundle which contains constructed keys.
*
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyInformationProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyInformationProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyInformationProvider.java 2007-05-29 13:22:45 UTC (rev 2547)
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.text.ruby.hover;
+
+
+import org.eclipse.jface.text.DefaultInformationControl;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.information.IInformationProvider;
+import org.eclipse.jface.text.information.IInformationProviderExtension2;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IPerspectiveDescriptor;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.rubypeople.rdt.internal.ui.text.HTMLTextPresenter;
+import org.rubypeople.rdt.internal.ui.text.RubyWordFinder;
+import org.rubypeople.rdt.ui.text.ruby.hover.IRubyEditorTextHover;
+
+
+public class RubyInformationProvider implements IInformationProvider, IInformationProviderExtension2 {
+
+ class EditorWatcher implements IPartListener {
+
+ /**
+ * @see IPartListener#partOpened(IWorkbenchPart)
+ */
+ public void partOpened(IWorkbenchPart part) {
+ }
+
+ /**
+ * @see IPartListener#partDeactivated(IWorkbenchPart)
+ */
+ public void partDeactivated(IWorkbenchPart part) {
+ }
+
+ /**
+ * @see IPartListener#partClosed(IWorkbenchPart)
+ */
+ public void partClosed(IWorkbenchPart part) {
+ if (part == fEditor) {
+ fEditor.getSite().getWorkbenchWindow().getPartService().removePartListener(fPartListener);
+ fPartListener= null;
+ }
+ }
+
+ /**
+ * @see IPartListener#partActivated(IWorkbenchPart)
+ */
+ public void partActivated(IWorkbenchPart part) {
+ update();
+ }
+
+ public void partBroughtToTop(IWorkbenchPart part) {
+ update();
+ }
+ }
+
+ protected IEditorPart fEditor;
+ protected IPartListener fPartListener;
+
+ protected String fCurrentPerspective;
+ protected IRubyEditorTextHover fImplementation;
+
+ /**
+ * The presentation control creator.
+ *
+ * @since 3.2
+ */
+ private IInformationControlCreator fPresenterControlCreator;
+
+
+
+ public RubyInformationProvider(IEditorPart editor) {
+
+ fEditor= editor;
+
+ if (fEditor != null) {
+
+ fPartListener= new EditorWatcher();
+ IWorkbenchWindow window= fEditor.getSite().getWorkbenchWindow();
+ window.getPartService().addPartListener(fPartListener);
+
+ update();
+ }
+ }
+
+ protected void update() {
+
+ IWorkbenchWindow window= fEditor.getSite().getWorkbenchWindow();
+ IWorkbenchPage page= window.getActivePage();
+ if (page != null) {
+
+ IPerspectiveDescriptor perspective= page.getPerspective();
+ if (perspective != null) {
+ String perspectiveId= perspective.getId();
+
+ if (fCurrentPerspective == null || fCurrentPerspective != perspectiveId) {
+ fCurrentPerspective= perspectiveId;
+
+ fImplementation= new RubyTypeHover();
+ fImplementation.setEditor(fEditor);
+ }
+ }
+ }
+ }
+
+ /*
+ * @see IInformationProvider#getSubject(ITextViewer, int)
+ */
+ public IRegion getSubject(ITextViewer textViewer, int offset) {
+
+ if (textViewer != null)
+ return RubyWordFinder.findWord(textViewer.getDocument(), offset);
+
+ return null;
+ }
+
+ /*
+ * @see IInformationProvider#getInformation(ITextViewer, IRegion)
+ */
+ public String getInformation(ITextViewer textViewer, IRegion subject) {
+ if (fImplementation != null) {
+ String s= fImplementation.getHoverInfo(textViewer, subject);
+ if (s != null && s.trim().length() > 0) {
+ return s;
+ }
+ }
+
+ return null;
+ }
+
+ /*
+ * @see IInformationProviderExtension2#getInformationPresenterControlCreator()
+ * @since 3.1
+ */
+ public IInformationControlCreator getInformationPresenterControlCreator() {
+ if (fPresenterControlCreator == null) {
+ fPresenterControlCreator= new AbstractReusableInformationControlCreator() {
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractReusableInformationControlCreator#doCreateInformationControl(org.eclipse.swt.widgets.Shell)
+ */
+ public IInformationControl doCreateInformationControl(Shell parent) {
+ int shellStyle= SWT.RESIZE | SWT.TOOL;
+ int style= SWT.V_SCROLL | SWT.H_SCROLL;
+ if (BrowserInformationControl.isAvailable(parent))
+ return new BrowserInformationControl(parent, shellStyle, style);
+ else
+ return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false));
+ }
+ };
+ }
+ return fPresenterControlCreator;
+ }
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyTypeHover.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyTypeHover.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyTypeHover.java 2007-05-29 13:22:45 UTC (rev 2547)
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.text.ruby.hover;
+
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.ui.IEditorPart;
+import org.rubypeople.rdt.ui.text.ruby.hover.IRubyEditorTextHover;
+
+
+public class RubyTypeHover implements IRubyEditorTextHover {
+
+ private IRubyEditorTextHover fProblemHover;
+ private IRubyEditorTextHover fRubydocHover;
+
+ public RubyTypeHover() {
+ fProblemHover= new ProblemHover();
+ fRubydocHover= new CommentHoverProvider();
+ }
+
+ /*
+ * @see IRubyEditorTextHover#setEditor(IEditorPart)
+ */
+ public void setEditor(IEditorPart editor) {
+ fProblemHover.setEditor(editor);
+ fRubydocHover.setEditor(editor);
+ }
+
+ /*
+ * @see ITextHover#getHoverRegion(ITextViewer, int)
+ */
+ public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
+ return fRubydocHover.getHoverRegion(textViewer, offset);
+ }
+
+ /*
+ * @see ITextHover#getHoverInfo(ITextViewer, IRegion)
+ */
+ public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
+ String hoverInfo= fProblemHover.getHoverInfo(textViewer, hoverRegion);
+ if (hoverInfo != null)
+ return hoverInfo;
+
+ return fRubydocHover.getHoverInfo(textViewer, hoverRegion);
+ }
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java 2007-05-29 13:21:21 UTC (rev 2546)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java 2007-05-29 13:22:45 UTC (rev 2547)
@@ -7,5 +7,11 @@
* (value <code>"org.rubypeople.rdt.ui.actions.Open"</code>).
*/
public static final String OPEN= "org.rubypeople.rdt.ui.actions.Open"; //$NON-NLS-1$
+
+ /**
+ * Edit menu: name of standard Show Rubydoc global action
+ * (value <code>"org.rubypeople.rdt.ui.actions.ShowRubyDoc"</code>).
+ */
+ public static final String SHOW_RUBY_DOC= "org.rubypeople.rdt.ui.actions.ShowRubyDoc"; //$NON-NLS-1$
}
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 2007-05-29 13:21:21 UTC (rev 2546)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2007-05-29 13:22:45 UTC (rev 2547)
@@ -16,6 +16,9 @@
import org.eclipse.jface.text.formatter.IContentFormatter;
import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
+import org.eclipse.jface.text.information.IInformationPresenter;
+import org.eclipse.jface.text.information.IInformationProvider;
+import org.eclipse.jface.text.information.InformationPresenter;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.quickassist.IQuickAssistAssistant;
@@ -63,6 +66,7 @@
import org.rubypeople.rdt.internal.ui.text.ruby.RubyTokenScanner;
import org.rubypeople.rdt.internal.ui.text.ruby.hover.RubyEditorTextHoverDescriptor;
import org.rubypeople.rdt.internal.ui.text.ruby.hover.RubyEditorTextHoverProxy;
+import org.rubypeople.rdt.internal.ui.text.ruby.hover.RubyInformationProvider;
public class RubySourceViewerConfiguration extends TextSourceViewerConfiguration {
@@ -302,12 +306,48 @@
*/
public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
return new IInformationControlCreator() {
-
public IInformationControl createInformationControl(Shell parent) {
return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true));
}
};
}
+
+ /*
+ * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
+ * @since 2.0
+ */
+ public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
+ InformationPresenter presenter= new InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
+ presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
+
+ // Register information provider
+ IInformationProvider provider= new RubyInformationProvider(getEditor());
+ String[] contentTypes= getConfiguredContentTypes(sourceViewer);
+ for (int i= 0; i < contentTypes.length; i++)
+ presenter.setInformationProvider(provider, contentTypes[i]);
+
+ presenter.setSizeConstraints(60, 10, true, true);
+ return presenter;
+ }
+
+ /**
+ * Returns the information presenter control creator. The creator is a factory creating the
+ * presenter controls for the given source viewer. This implementation always returns a creator
+ * for <code>DefaultInformationControl</code> instances.
+ *
+ * @param sourceViewer the source viewer to be configured by this configuration
+ * @return an information control creator
+ * @since 2.1
+ */
+ private IInformationControlCreator getInformationPresenterControlCreator(ISourceViewer sourceViewer) {
+ return new IInformationControlCreator() {
+ public IInformationControl createInformationControl(Shell parent) {
+ int shellStyle= SWT.RESIZE | SWT.TOOL;
+ int style= SWT.V_SCROLL | SWT.H_SCROLL;
+ return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false));
+ }
+ };
+ }
/**
* Returns the editor in which the configured viewer(s) will reside.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-29 13:21:23
|
Revision: 2546
http://svn.sourceforge.net/rubyeclipse/?rev=2546&view=rev
Author: cawilliams
Date: 2007-05-29 06:21:21 -0700 (Tue, 29 May 2007)
Log Message:
-----------
move CommentHoverProvider over to rdt.ui
Modified Paths:
--------------
trunk/com.aptana.rdt/META-INF/MANIFEST.MF
trunk/com.aptana.rdt/plugin.xml
Removed Paths:
-------------
trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java
Modified: trunk/com.aptana.rdt/META-INF/MANIFEST.MF
===================================================================
--- trunk/com.aptana.rdt/META-INF/MANIFEST.MF 2007-05-29 13:20:43 UTC (rev 2545)
+++ trunk/com.aptana.rdt/META-INF/MANIFEST.MF 2007-05-29 13:21:21 UTC (rev 2546)
@@ -10,7 +10,6 @@
Export-Package: com.aptana.rdt,
com.aptana.rdt.internal.parser.warnings,
com.aptana.rdt.internal.ui.preferences,
- com.aptana.rdt.internal.ui.text.ruby.hover,
com.aptana.rdt.core.gems
Require-Bundle: org.eclipse.core.resources,
org.eclipse.core.runtime,
Modified: trunk/com.aptana.rdt/plugin.xml
===================================================================
--- trunk/com.aptana.rdt/plugin.xml 2007-05-29 13:20:43 UTC (rev 2545)
+++ trunk/com.aptana.rdt/plugin.xml 2007-05-29 13:21:21 UTC (rev 2546)
@@ -33,13 +33,6 @@
</description>
</cheatsheet>
</extension>
-
- <extension point="org.rubypeople.rdt.ui.rubyEditorTextHovers">
- <hover
- id="com.aptana.rdt.ui.RubyCommentHover"
- class="com.aptana.rdt.internal.ui.text.ruby.hover.CommentHoverProvider"
- label="%commentHover"/>
- </extension>
<extension
point="org.eclipse.ui.views">
Deleted: trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java 2007-05-29 13:20:43 UTC (rev 2545)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java 2007-05-29 13:21:21 UTC (rev 2546)
@@ -1,162 +0,0 @@
-package com.aptana.rdt.internal.ui.text.ruby.hover;
-
-import org.eclipse.jface.text.DefaultInformationControl;
-import org.eclipse.jface.text.IInformationControl;
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Shell;
-import org.rubypeople.rdt.core.IMember;
-import org.rubypeople.rdt.core.IRubyElement;
-import org.rubypeople.rdt.core.util.RDocUtil;
-import org.rubypeople.rdt.internal.ui.text.HTMLPrinter;
-import org.rubypeople.rdt.internal.ui.text.HTMLTextPresenter;
-import org.rubypeople.rdt.internal.ui.text.ruby.IInformationControlExtension4;
-import org.rubypeople.rdt.internal.ui.text.ruby.hover.AbstractReusableInformationControlCreator;
-import org.rubypeople.rdt.internal.ui.text.ruby.hover.AbstractRubyEditorTextHover;
-import org.rubypeople.rdt.internal.ui.text.ruby.hover.BrowserInformationControl;
-import org.rubypeople.rdt.ui.RubyElementLabels;
-
-public class CommentHoverProvider extends AbstractRubyEditorTextHover {
-
- private final long LABEL_FLAGS= RubyElementLabels.ALL_FULLY_QUALIFIED | RubyElementLabels.M_PARAMETER_NAMES | RubyElementLabels.USE_RESOLVED;
- private final long LOCAL_VARIABLE_FLAGS= LABEL_FLAGS & ~RubyElementLabels.F_FULLY_QUALIFIED | RubyElementLabels.F_POST_QUALIFIED;
-
- /**
- * The hover control creator.
- *
- * @since 1.0
- */
- private IInformationControlCreator fHoverControlCreator;
- /**
- * The presentation control creator.
- *
- * @since 1.0
- */
- private IInformationControlCreator fPresenterControlCreator;
-
- /*
- * @see RubyElementHover
- */
- protected String getHoverInfo(IRubyElement[] result) {
-
- StringBuffer buffer= new StringBuffer();
- int nResults= result.length;
- if (nResults == 0)
- return null;
-
- boolean hasContents= false;
- if (nResults > 1) {
-
- for (int i= 0; i < result.length; i++) {
- HTMLPrinter.startBulletList(buffer);
- IRubyElement curr= result[i];
- if (curr instanceof IMember || curr.getElementType() == IRubyElement.LOCAL_VARIABLE) {
- HTMLPrinter.addBullet(buffer, getInfoText(curr));
- hasContents= true;
- }
- HTMLPrinter.endBulletList(buffer);
- }
-
- } else {
-
- IRubyElement curr= result[0];
- if (curr instanceof IMember) {
- IMember member= (IMember) curr;
- HTMLPrinter.addSmallHeader(buffer, getInfoText(member));
- String contents = RDocUtil.getDocumentation(member);
- if (contents != null) {
- HTMLPrinter.addParagraph(buffer, contents);
- }
- hasContents= true;
- } else if (curr.getElementType() == IRubyElement.LOCAL_VARIABLE) {
- HTMLPrinter.addSmallHeader(buffer, getInfoText(curr));
- hasContents= true;
- }
- }
-
- if (!hasContents)
- return null;
-
- if (buffer.length() > 0) {
- HTMLPrinter.insertPageProlog(buffer, 0, getStyleSheet());
- HTMLPrinter.addPageEpilog(buffer);
- return buffer.toString();
- }
-
- return null;
- }
-
- /*
- * @see IInformationProviderExtension2#getInformationPresenterControlCreator()
- * @since 1.0
- */
- public IInformationControlCreator getInformationPresenterControlCreator() {
- if (fPresenterControlCreator == null) {
- fPresenterControlCreator= new AbstractReusableInformationControlCreator() {
-
- /*
- * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractReusableInformationControlCreator#doCreateInformationControl(org.eclipse.swt.widgets.Shell)
- */
- public IInformationControl doCreateInformationControl(Shell parent) {
- int shellStyle= SWT.RESIZE | SWT.TOOL;
- int style= SWT.V_SCROLL | SWT.H_SCROLL;
- if (BrowserInformationControl.isAvailable(parent))
- return new BrowserInformationControl(parent, shellStyle, style);
- else
- return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false));
- }
- };
- }
- return fPresenterControlCreator;
- }
-
- /*
- * @see ITextHoverExtension#getHoverControlCreator()
- * @since 1.0
- */
- public IInformationControlCreator getHoverControlCreator() {
- if (fHoverControlCreator == null) {
- fHoverControlCreator= new AbstractReusableInformationControlCreator() {
-
- /*
- * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractReusableInformationControlCreator#doCreateInformationControl(org.eclipse.swt.widgets.Shell)
- */
- public IInformationControl doCreateInformationControl(Shell parent) {
- if (BrowserInformationControl.isAvailable(parent))
- return new BrowserInformationControl(parent, SWT.TOOL | SWT.NO_TRIM, SWT.NONE, getTooltipAffordanceString());
- else
- return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true), getTooltipAffordanceString());
- }
-
- /*
- * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractReusableInformationControlCreator#canReuse(org.eclipse.jface.text.IInformationControl)
- */
- public boolean canReuse(IInformationControl control) {
- boolean canReuse= super.canReuse(control);
- if (canReuse && control instanceof IInformationControlExtension4)
- ((IInformationControlExtension4)control).setStatusText(getTooltipAffordanceString());
- return canReuse;
-
- }
- };
- }
- return fHoverControlCreator;
- }
-
- private String getInfoText(IRubyElement member) {
- long flags= member.getElementType() == IRubyElement.LOCAL_VARIABLE ? LOCAL_VARIABLE_FLAGS : LABEL_FLAGS;
- String label= RubyElementLabels.getElementLabel(member, flags);
- StringBuffer buf= new StringBuffer();
- for (int i= 0; i < label.length(); i++) {
- char ch= label.charAt(i);
- if (ch == '<') {
- buf.append("<"); //$NON-NLS-1$
- } else if (ch == '>') {
- buf.append(">"); //$NON-NLS-1$
- } else {
- buf.append(ch);
- }
- }
- return buf.toString();
- }
-}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-29 13:20:45
|
Revision: 2545
http://svn.sourceforge.net/rubyeclipse/?rev=2545&view=rev
Author: cawilliams
Date: 2007-05-29 06:20:43 -0700 (Tue, 29 May 2007)
Log Message:
-----------
move comment hover provider over from com.aptana.rdt - so we can place it before the RiDocProvider (so we try to get it's results before invoking ri)
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java 2007-05-29 13:20:43 UTC (rev 2545)
@@ -0,0 +1,162 @@
+package org.rubypeople.rdt.internal.ui.text.ruby.hover;
+
+import org.eclipse.jface.text.DefaultInformationControl;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Shell;
+import org.rubypeople.rdt.core.IMember;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.util.RDocUtil;
+import org.rubypeople.rdt.internal.ui.text.HTMLPrinter;
+import org.rubypeople.rdt.internal.ui.text.HTMLTextPresenter;
+import org.rubypeople.rdt.internal.ui.text.ruby.IInformationControlExtension4;
+import org.rubypeople.rdt.internal.ui.text.ruby.hover.AbstractReusableInformationControlCreator;
+import org.rubypeople.rdt.internal.ui.text.ruby.hover.AbstractRubyEditorTextHover;
+import org.rubypeople.rdt.internal.ui.text.ruby.hover.BrowserInformationControl;
+import org.rubypeople.rdt.ui.RubyElementLabels;
+
+public class CommentHoverProvider extends AbstractRubyEditorTextHover {
+
+ private final long LABEL_FLAGS= RubyElementLabels.ALL_FULLY_QUALIFIED | RubyElementLabels.M_PARAMETER_NAMES | RubyElementLabels.USE_RESOLVED;
+ private final long LOCAL_VARIABLE_FLAGS= LABEL_FLAGS & ~RubyElementLabels.F_FULLY_QUALIFIED | RubyElementLabels.F_POST_QUALIFIED;
+
+ /**
+ * The hover control creator.
+ *
+ * @since 1.0
+ */
+ private IInformationControlCreator fHoverControlCreator;
+ /**
+ * The presentation control creator.
+ *
+ * @since 1.0
+ */
+ private IInformationControlCreator fPresenterControlCreator;
+
+ /*
+ * @see RubyElementHover
+ */
+ protected String getHoverInfo(IRubyElement[] result) {
+
+ StringBuffer buffer= new StringBuffer();
+ int nResults= result.length;
+ if (nResults == 0)
+ return null;
+
+ boolean hasContents= false;
+ if (nResults > 1) {
+
+ for (int i= 0; i < result.length; i++) {
+ HTMLPrinter.startBulletList(buffer);
+ IRubyElement curr= result[i];
+ if (curr instanceof IMember || curr.getElementType() == IRubyElement.LOCAL_VARIABLE) {
+ HTMLPrinter.addBullet(buffer, getInfoText(curr));
+ hasContents= true;
+ }
+ HTMLPrinter.endBulletList(buffer);
+ }
+
+ } else {
+
+ IRubyElement curr= result[0];
+ if (curr instanceof IMember) {
+ IMember member= (IMember) curr;
+ HTMLPrinter.addSmallHeader(buffer, getInfoText(member));
+ String contents = RDocUtil.getHTMLDocumentation(member);
+ if (contents != null) {
+ HTMLPrinter.addParagraph(buffer, contents);
+ }
+ hasContents= true;
+ } else if (curr.getElementType() == IRubyElement.LOCAL_VARIABLE) {
+ HTMLPrinter.addSmallHeader(buffer, getInfoText(curr));
+ hasContents= true;
+ }
+ }
+
+ if (!hasContents)
+ return null;
+
+ if (buffer.length() > 0) {
+ HTMLPrinter.insertPageProlog(buffer, 0, getStyleSheet());
+ HTMLPrinter.addPageEpilog(buffer);
+ return buffer.toString();
+ }
+
+ return null;
+ }
+
+ /*
+ * @see IInformationProviderExtension2#getInformationPresenterControlCreator()
+ * @since 1.0
+ */
+ public IInformationControlCreator getInformationPresenterControlCreator() {
+ if (fPresenterControlCreator == null) {
+ fPresenterControlCreator= new AbstractReusableInformationControlCreator() {
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractReusableInformationControlCreator#doCreateInformationControl(org.eclipse.swt.widgets.Shell)
+ */
+ public IInformationControl doCreateInformationControl(Shell parent) {
+ int shellStyle= SWT.RESIZE | SWT.TOOL;
+ int style= SWT.V_SCROLL | SWT.H_SCROLL;
+ if (BrowserInformationControl.isAvailable(parent))
+ return new BrowserInformationControl(parent, shellStyle, style);
+ else
+ return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false));
+ }
+ };
+ }
+ return fPresenterControlCreator;
+ }
+
+ /*
+ * @see ITextHoverExtension#getHoverControlCreator()
+ * @since 1.0
+ */
+ public IInformationControlCreator getHoverControlCreator() {
+ if (fHoverControlCreator == null) {
+ fHoverControlCreator= new AbstractReusableInformationControlCreator() {
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractReusableInformationControlCreator#doCreateInformationControl(org.eclipse.swt.widgets.Shell)
+ */
+ public IInformationControl doCreateInformationControl(Shell parent) {
+ if (BrowserInformationControl.isAvailable(parent))
+ return new BrowserInformationControl(parent, SWT.TOOL | SWT.NO_TRIM, SWT.NONE, getTooltipAffordanceString());
+ else
+ return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true), getTooltipAffordanceString());
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractReusableInformationControlCreator#canReuse(org.eclipse.jface.text.IInformationControl)
+ */
+ public boolean canReuse(IInformationControl control) {
+ boolean canReuse= super.canReuse(control);
+ if (canReuse && control instanceof IInformationControlExtension4)
+ ((IInformationControlExtension4)control).setStatusText(getTooltipAffordanceString());
+ return canReuse;
+
+ }
+ };
+ }
+ return fHoverControlCreator;
+ }
+
+ private String getInfoText(IRubyElement member) {
+ long flags= member.getElementType() == IRubyElement.LOCAL_VARIABLE ? LOCAL_VARIABLE_FLAGS : LABEL_FLAGS;
+ String label= RubyElementLabels.getElementLabel(member, flags);
+ StringBuffer buf= new StringBuffer();
+ for (int i= 0; i < label.length(); i++) {
+ char ch= label.charAt(i);
+ if (ch == '<') {
+ buf.append("<"); //$NON-NLS-1$
+ } else if (ch == '>') {
+ buf.append(">"); //$NON-NLS-1$
+ } else {
+ buf.append(ch);
+ }
+ }
+ return buf.toString();
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-29 13:14:40
|
Revision: 2544
http://svn.sourceforge.net/rubyeclipse/?rev=2544&view=rev
Author: cawilliams
Date: 2007-05-29 06:14:39 -0700 (Tue, 29 May 2007)
Log Message:
-----------
call out to JRuby to format the comments into RDoc HTML using the actual RDoc library. Now we can provide accurate HTML versions of comments/docs inside the editor hovers and proposals
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/util/RDocUtil.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/util/RDocUtiltest.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/util/RDocUtil.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/util/RDocUtil.java 2007-05-29 13:13:35 UTC (rev 2543)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/util/RDocUtil.java 2007-05-29 13:14:39 UTC (rev 2544)
@@ -1,15 +1,27 @@
package org.rubypeople.rdt.core.util;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
import java.util.Collection;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.jruby.Ruby;
import org.jruby.ast.CommentNode;
+import org.jruby.exceptions.RaiseException;
import org.jruby.lexer.yacc.ISourcePosition;
+import org.jruby.runtime.builtin.IRubyObject;
import org.rubypeople.rdt.core.IMember;
import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.core.parser.RubyParser;
public class RDocUtil {
+ private static Ruby fgRuby;
+ private static String fgRdocScriptPath;
+
private RDocUtil() {}
public static String getDocumentation(IRubyElement element) {
@@ -19,6 +31,10 @@
return "";
}
+ public static String getHTMLDocumentation(IRubyElement element) {
+ return getHTMLDocumentation(getDocumentation(element));
+ }
+
private static String getContents(IMember member) {
String src = "";
int elementOffset = -1;
@@ -90,4 +106,41 @@
private static String removePrecedingHashes(String comment) {
return comment.trim().substring(1);
}
+
+ public static String getHTMLDocumentation(String docs) {
+ if (docs == null) return null;
+ String script = "require 'rdoc/markup/simple_markup'\n" +
+ "require 'rdoc/markup/simple_markup/to_html'\n" +
+ "p = SM::SimpleMarkup.new\n" +
+ "h = SM::ToHtml.new\n" +
+ "input_string =<<EOF\n" + docs + "\nEOF\n" +
+ "p.convert(input_string, h)\n";
+ Ruby ruby = getJRubyInstance();
+ try {
+ ruby.setCurrentDirectory(getRDocScriptPath());
+ IRubyObject object = ruby.evalScript(script);
+ docs = object.toString();
+ } catch (IOException e) {
+ // ignore
+ } catch (RaiseException e) {
+ e.printStackTrace();
+ }
+ return docs;
+ }
+
+ private static Ruby getJRubyInstance() {
+ if (fgRuby == null)
+ fgRuby = Ruby.getDefaultInstance();
+ return fgRuby;
+ }
+
+ private static String getRDocScriptPath() throws IOException {
+ if (fgRdocScriptPath == null) {
+ URL installURL = new URL(RubyCore.getPlugin().getBundle().getEntry("/"),new Path("ruby").toString()); //$NON-NLS-1$
+ URL localURL = FileLocator.toFileURL(installURL);
+ File file = new File(localURL.getFile());
+ fgRdocScriptPath = file.getAbsolutePath();
+ }
+ return fgRdocScriptPath;
+ }
}
Added: trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/util/RDocUtiltest.java
===================================================================
--- trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/util/RDocUtiltest.java (rev 0)
+++ trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/util/RDocUtiltest.java 2007-05-29 13:14:39 UTC (rev 2544)
@@ -0,0 +1,33 @@
+package org.rubypeople.rdt.core.tests.util;
+
+import org.rubypeople.rdt.core.util.RDocUtil;
+
+import junit.framework.TestCase;
+
+public class RDocUtiltest extends TestCase {
+
+ public void testHTML() throws Exception {
+ String input = " List entries look like:\n" +
+ " * text\n" +
+ " 1. text\n" +
+ " [label] text\n" +
+ " label:: text\n" +
+ "\n" +
+ " Flag it as a list entry, and\n" +
+ " work out the indent for subsequent lines";
+ String html = RDocUtil.getHTMLDocumentation(input);
+ String expected = "<p>\n" +
+ "List entries look like:\n" +
+ "</p>\n" +
+ "<pre>\n" +
+ " * text\n" +
+ " 1. text\n" +
+ " [label] text\n" +
+ " label:: text\n" +
+ "</pre>\n" +
+ "<p>\n" +
+ "Flag it as a list entry, and work out the indent for subsequent lines\n" +
+ "</p>\n";
+ assertEquals(expected, html);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-29 13:13:36
|
Revision: 2543
http://svn.sourceforge.net/rubyeclipse/?rev=2543&view=rev
Author: cawilliams
Date: 2007-05-29 06:13:35 -0700 (Tue, 29 May 2007)
Log Message:
-----------
add necessary ruuby libraries to be able to invoke RDoc HTML formatter
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/.project
Added Paths:
-----------
trunk/org.rubypeople.rdt.core/.loadpath
trunk/org.rubypeople.rdt.core/ruby/English.rb
trunk/org.rubypeople.rdt.core/ruby/cgi.rb
trunk/org.rubypeople.rdt.core/ruby/delegate.rb
trunk/org.rubypeople.rdt.core/ruby/rdoc/
trunk/org.rubypeople.rdt.core/ruby/rdoc/markup/
trunk/org.rubypeople.rdt.core/ruby/rdoc/markup/simple_markup/
trunk/org.rubypeople.rdt.core/ruby/rdoc/markup/simple_markup/fragments.rb
trunk/org.rubypeople.rdt.core/ruby/rdoc/markup/simple_markup/inline.rb
trunk/org.rubypeople.rdt.core/ruby/rdoc/markup/simple_markup/lines.rb
trunk/org.rubypeople.rdt.core/ruby/rdoc/markup/simple_markup/to_html.rb
trunk/org.rubypeople.rdt.core/ruby/rdoc/markup/simple_markup.rb
trunk/org.rubypeople.rdt.core/ruby/rdoc.rb
Added: trunk/org.rubypeople.rdt.core/.loadpath
===================================================================
--- trunk/org.rubypeople.rdt.core/.loadpath (rev 0)
+++ trunk/org.rubypeople.rdt.core/.loadpath 2007-05-29 13:13:35 UTC (rev 2543)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<loadpath>
+ <pathentry path="" type="src"/>
+ <pathentry path="org.rubypeople.rdt.launching.RUBY_CONTAINER" type="con"/>
+</loadpath>
Modified: trunk/org.rubypeople.rdt.core/.project
===================================================================
(Binary files differ)
Added: trunk/org.rubypeople.rdt.core/ruby/English.rb
===================================================================
--- trunk/org.rubypeople.rdt.core/ruby/English.rb (rev 0)
+++ trunk/org.rubypeople.rdt.core/ruby/English.rb 2007-05-29 13:13:35 UTC (rev 2543)
@@ -0,0 +1,155 @@
+# Include the English library file in a Ruby script, and you can
+# reference the global variables such as \VAR{\$\_} using less
+# cryptic names, listed in the following table.% \vref{tab:english}.
+#
+# Without 'English':
+#
+# $\ = ' -- '
+# "waterbuffalo" =~ /buff/
+# print $", $', $$, "\n"
+#
+# With English:
+#
+# require "English"
+#
+# $OUTPUT_FIELD_SEPARATOR = ' -- '
+# "waterbuffalo" =~ /buff/
+# print $LOADED_FEATURES, $POSTMATCH, $PID, "\n"
+
+
+# The exception object passed to +raise+.
+alias $ERROR_INFO $!
+
+# The stack backtrace generated by the last
+# exception. <tt>See Kernel.caller</tt> for details. Thread local.
+alias $ERROR_POSITION $@
+
+# The default separator pattern used by <tt>String.split</tt>. May be
+# set from the command line using the <tt>-F</tt> flag.
+alias $FS $;
+
+# The default separator pattern used by <tt>String.split</tt>. May be
+# set from the command line using the <tt>-F</tt> flag.
+alias $FIELD_SEPARATOR $;
+
+# The separator string output between the parameters to methods such
+# as <tt>Kernel.print</tt> and <tt>Array.join</tt>. Defaults to +nil+,
+# which adds no text.
+alias $OFS $,
+
+# The separator string output between the parameters to methods such
+# as <tt>Kernel.print</tt> and <tt>Array.join</tt>. Defaults to +nil+,
+# which adds no text.
+alias $OUTPUT_FIELD_SEPARATOR $,
+
+# The input record separator (newline by default). This is the value
+# that routines such as <tt>Kernel.gets</tt> use to determine record
+# boundaries. If set to +nil+, +gets+ will read the entire file.
+alias $RS $/
+
+# The input record separator (newline by default). This is the value
+# that routines such as <tt>Kernel.gets</tt> use to determine record
+# boundaries. If set to +nil+, +gets+ will read the entire file.
+alias $INPUT_RECORD_SEPARATOR $/
+
+# The string appended to the output of every call to methods such as
+# <tt>Kernel.print</tt> and <tt>IO.write</tt>. The default value is
+# +nil+.
+alias $ORS $\
+
+# The string appended to the output of every call to methods such as
+# <tt>Kernel.print</tt> and <tt>IO.write</tt>. The default value is
+# +nil+.
+alias $OUTPUT_RECORD_SEPARATOR $\
+
+# The number of the last line read from the current input file.
+alias $INPUT_LINE_NUMBER $.
+
+# The number of the last line read from the current input file.
+alias $NR $.
+
+# The last line read by <tt>Kernel.gets</tt> or
+# <tt>Kernel.readline</tt>. Many string-related functions in the
+# +Kernel+ module operate on <tt>$_</tt> by default. The variable is
+# local to the current scope. Thread local.
+alias $LAST_READ_LINE $_
+
+# The destination of output for <tt>Kernel.print</tt>
+# and <tt>Kernel.printf</tt>. The default value is
+# <tt>$stdout</tt>.
+alias $DEFAULT_OUTPUT $>
+
+# An object that provides access to the concatenation
+# of the contents of all the files
+# given as command-line arguments, or <tt>$stdin</tt>
+# (in the case where there are no
+# arguments). <tt>$<</tt> supports methods similar to a
+# +File+ object:
+# +inmode+, +close+,
+# <tt>closed?</tt>, +each+,
+# <tt>each_byte</tt>, <tt>each_line</tt>,
+# +eof+, <tt>eof?</tt>, +file+,
+# +filename+, +fileno+,
+# +getc+, +gets+, +lineno+,
+# <tt>lineno=</tt>, +path+,
+# +pos+, <tt>pos=</tt>,
+# +read+, +readchar+,
+# +readline+, +readlines+,
+# +rewind+, +seek+, +skip+,
+# +tell+, <tt>to_a</tt>, <tt>to_i</tt>,
+# <tt>to_io</tt>, <tt>to_s</tt>, along with the
+# methods in +Enumerable+. The method +file+
+# returns a +File+ object for the file currently
+# being read. This may change as <tt>$<</tt> reads
+# through the files on the command line. Read only.
+alias $DEFAULT_INPUT $<
+
+# The process number of the program being executed. Read only.
+alias $PID $$
+
+# The process number of the program being executed. Read only.
+alias $PROCESS_ID $$
+
+# The exit status of the last child process to terminate. Read
+# only. Thread local.
+alias $CHILD_STATUS $?
+
+# A +MatchData+ object that encapsulates the results of a successful
+# pattern match. The variables <tt>$&</tt>, <tt>$`</tt>, <tt>$'</tt>,
+# and <tt>$1</tt> to <tt>$9</tt> are all derived from
+# <tt>$~</tt>. Assigning to <tt>$~</tt> changes the values of these
+# derived variables. This variable is local to the current
+# scope. Thread local.
+alias $LAST_MATCH_INFO $~
+
+# If set to any value apart from +nil+ or +false+, all pattern matches
+# will be case insensitive, string comparisons will ignore case, and
+# string hash values will be case insensitive. Deprecated
+alias $IGNORECASE $=
+
+# An array of strings containing the command-line
+# options from the invocation of the program. Options
+# used by the Ruby interpreter will have been
+# removed. Read only. Also known simply as +ARGV+.
+alias $ARGV $*
+
+# The string matched by the last successful pattern
+# match. This variable is local to the current
+# scope. Read only. Thread local.
+alias $MATCH $&
+
+# The string preceding the match in the last
+# successful pattern match. This variable is local to
+# the current scope. Read only. Thread local.
+alias $PREMATCH $`
+
+# The string following the match in the last
+# successful pattern match. This variable is local to
+# the current scope. Read only. Thread local.
+alias $POSTMATCH $'
+
+# The contents of the highest-numbered group matched in the last
+# successful pattern match. Thus, in <tt>"cat" =~ /(c|a)(t|z)/</tt>,
+# <tt>$+</tt> will be set to "t". This variable is local to the
+# current scope. Read only. Thread local.
+alias $LAST_PAREN_MATCH $+
Added: trunk/org.rubypeople.rdt.core/ruby/cgi.rb
===================================================================
--- trunk/org.rubypeople.rdt.core/ruby/cgi.rb (rev 0)
+++ trunk/org.rubypeople.rdt.core/ruby/cgi.rb 2007-05-29 13:13:35 UTC (rev 2543)
@@ -0,0 +1,2302 @@
+#
+# cgi.rb - cgi support library
+#
+# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
+#
+# Copyright (C) 2000 Information-technology Promotion Agency, Japan
+#
+# Author: Wakou Aoyama <wa...@ru...>
+#
+# Documentation: Wakou Aoyama (RDoc'd and embellished by William Webber)
+#
+# == Overview
+#
+# The Common Gateway Interface (CGI) is a simple protocol
+# for passing an HTTP request from a web server to a
+# standalone program, and returning the output to the web
+# browser. Basically, a CGI program is called with the
+# parameters of the request passed in either in the
+# environment (GET) or via $stdin (POST), and everything
+# it prints to $stdout is returned to the client.
+#
+# This file holds the +CGI+ class. This class provides
+# functionality for retrieving HTTP request parameters,
+# managing cookies, and generating HTML output. See the
+# class documentation for more details and examples of use.
+#
+# The file cgi/session.rb provides session management
+# functionality; see that file for more details.
+#
+# See http://www.w3.org/CGI/ for more information on the CGI
+# protocol.
+
+raise "Please, use ruby 1.5.4 or later." if RUBY_VERSION < "1.5.4"
+
+require 'English'
+
+# CGI class. See documentation for the file cgi.rb for an overview
+# of the CGI protocol.
+#
+# == Introduction
+#
+# CGI is a large class, providing several categories of methods, many of which
+# are mixed in from other modules. Some of the documentation is in this class,
+# some in the modules CGI::QueryExtension and CGI::HtmlExtension. See
+# CGI::Cookie for specific information on handling cookies, and cgi/session.rb
+# (CGI::Session) for information on sessions.
+#
+# For queries, CGI provides methods to get at environmental variables,
+# parameters, cookies, and multipart request data. For responses, CGI provides
+# methods for writing output and generating HTML.
+#
+# Read on for more details. Examples are provided at the bottom.
+#
+# == Queries
+#
+# The CGI class dynamically mixes in parameter and cookie-parsing
+# functionality, environmental variable access, and support for
+# parsing multipart requests (including uploaded files) from the
+# CGI::QueryExtension module.
+#
+# === Environmental Variables
+#
+# The standard CGI environmental variables are available as read-only
+# attributes of a CGI object. The following is a list of these variables:
+#
+#
+# AUTH_TYPE HTTP_HOST REMOTE_IDENT
+# CONTENT_LENGTH HTTP_NEGOTIATE REMOTE_USER
+# CONTENT_TYPE HTTP_PRAGMA REQUEST_METHOD
+# GATEWAY_INTERFACE HTTP_REFERER SCRIPT_NAME
+# HTTP_ACCEPT HTTP_USER_AGENT SERVER_NAME
+# HTTP_ACCEPT_CHARSET PATH_INFO SERVER_PORT
+# HTTP_ACCEPT_ENCODING PATH_TRANSLATED SERVER_PROTOCOL
+# HTTP_ACCEPT_LANGUAGE QUERY_STRING SERVER_SOFTWARE
+# HTTP_CACHE_CONTROL REMOTE_ADDR
+# HTTP_FROM REMOTE_HOST
+#
+#
+# For each of these variables, there is a corresponding attribute with the
+# same name, except all lower case and without a preceding HTTP_.
+# +content_length+ and +server_port+ are integers; the rest are strings.
+#
+# === Parameters
+#
+# The method #params() returns a hash of all parameters in the request as
+# name/value-list pairs, where the value-list is an Array of one or more
+# values. The CGI object itself also behaves as a hash of parameter names
+# to values, but only returns a single value (as a String) for each
+# parameter name.
+#
+# For instance, suppose the request contains the parameter
+# "favourite_colours" with the multiple values "blue" and "green". The
+# following behaviour would occur:
+#
+# cgi.params["favourite_colours"] # => ["blue", "green"]
+# cgi["favourite_colours"] # => "blue"
+#
+# If a parameter does not exist, the former method will return an empty
+# array, the latter an empty string. The simplest way to test for existence
+# of a parameter is by the #has_key? method.
+#
+# === Cookies
+#
+# HTTP Cookies are automatically parsed from the request. They are available
+# from the #cookies() accessor, which returns a hash from cookie name to
+# CGI::Cookie object.
+#
+# === Multipart requests
+#
+# If a request's method is POST and its content type is multipart/form-data,
+# then it may contain uploaded files. These are stored by the QueryExtension
+# module in the parameters of the request. The parameter name is the name
+# attribute of the file input field, as usual. However, the value is not
+# a string, but an IO object, either an IOString for small files, or a
+# Tempfile for larger ones. This object also has the additional singleton
+# methods:
+#
+# #local_path():: the path of the uploaded file on the local filesystem
+# #original_filename():: the name of the file on the client computer
+# #content_type():: the content type of the file
+#
+# == Responses
+#
+# The CGI class provides methods for sending header and content output to
+# the HTTP client, and mixes in methods for programmatic HTML generation
+# from CGI::HtmlExtension and CGI::TagMaker modules. The precise version of HTML
+# to use for HTML generation is specified at object creation time.
+#
+# === Writing output
+#
+# The simplest way to send output to the HTTP client is using the #out() method.
+# This takes the HTTP headers as a hash parameter, and the body content
+# via a block. The headers can be generated as a string using the #header()
+# method. The output stream can be written directly to using the #print()
+# method.
+#
+# === Generating HTML
+#
+# Each HTML element has a corresponding method for generating that
+# element as a String. The name of this method is the same as that
+# of the element, all lowercase. The attributes of the element are
+# passed in as a hash, and the body as a no-argument block that evaluates
+# to a String. The HTML generation module knows which elements are
+# always empty, and silently drops any passed-in body. It also knows
+# which elements require matching closing tags and which don't. However,
+# it does not know what attributes are legal for which elements.
+#
+# There are also some additional HTML generation methods mixed in from
+# the CGI::HtmlExtension module. These include individual methods for the
+# different types of form inputs, and methods for elements that commonly
+# take particular attributes where the attributes can be directly specified
+# as arguments, rather than via a hash.
+#
+# == Examples of use
+#
+# === Get form values
+#
+# require "cgi"
+# cgi = CGI.new
+# value = cgi['field_name'] # <== value string for 'field_name'
+# # if not 'field_name' included, then return "".
+# fields = cgi.keys # <== array of field names
+#
+# # returns true if form has 'field_name'
+# cgi.has_key?('field_name')
+# cgi.has_key?('field_name')
+# cgi.include?('field_name')
+#
+# CAUTION! cgi['field_name'] returned an Array with the old
+# cgi.rb(included in ruby 1.6)
+#
+# === Get form values as hash
+#
+# require "cgi"
+# cgi = CGI.new
+# params = cgi.params
+#
+# cgi.params is a hash.
+#
+# cgi.params['new_field_name'] = ["value"] # add new param
+# cgi.params['field_name'] = ["new_value"] # change value
+# cgi.params.delete('field_name') # delete param
+# cgi.params.clear # delete all params
+#
+#
+# === Save form values to file
+#
+# require "pstore"
+# db = PStore.new("query.db")
+# db.transaction do
+# db["params"] = cgi.params
+# end
+#
+#
+# === Restore form values from file
+#
+# require "pstore"
+# db = PStore.new("query.db")
+# db.transaction do
+# cgi.params = db["params"]
+# end
+#
+#
+# === Get multipart form values
+#
+# require "cgi"
+# cgi = CGI.new
+# value = cgi['field_name'] # <== value string for 'field_name'
+# value.read # <== body of value
+# value.local_path # <== path to local file of value
+# value.original_filename # <== original filename of value
+# value.content_type # <== content_type of value
+#
+# and value has StringIO or Tempfile class methods.
+#
+# === Get cookie values
+#
+# require "cgi"
+# cgi = CGI.new
+# values = cgi.cookies['name'] # <== array of 'name'
+# # if not 'name' included, then return [].
+# names = cgi.cookies.keys # <== array of cookie names
+#
+# and cgi.cookies is a hash.
+#
+# === Get cookie objects
+#
+# require "cgi"
+# cgi = CGI.new
+# for name, cookie in cgi.cookies
+# cookie.expires = Time.now + 30
+# end
+# cgi.out("cookie" => cgi.cookies) {"string"}
+#
+# cgi.cookies # { "name1" => cookie1, "name2" => cookie2, ... }
+#
+# require "cgi"
+# cgi = CGI.new
+# cgi.cookies['name'].expires = Time.now + 30
+# cgi.out("cookie" => cgi.cookies['name']) {"string"}
+#
+# === Print http header and html string to $DEFAULT_OUTPUT ($>)
+#
+# require "cgi"
+# cgi = CGI.new("html3") # add HTML generation methods
+# cgi.out() do
+# cgi.html() do
+# cgi.head{ cgi.title{"TITLE"} } +
+# cgi.body() do
+# cgi.form() do
+# cgi.textarea("get_text") +
+# cgi.br +
+# cgi.submit
+# end +
+# cgi.pre() do
+# CGI::escapeHTML(
+# "params: " + cgi.params.inspect + "\n" +
+# "cookies: " + cgi.cookies.inspect + "\n" +
+# ENV.collect() do |key, value|
+# key + " --> " + value + "\n"
+# end.join("")
+# )
+# end
+# end
+# end
+# end
+#
+# # add HTML generation methods
+# CGI.new("html3") # html3.2
+# CGI.new("html4") # html4.01 (Strict)
+# CGI.new("html4Tr") # html4.01 Transitional
+# CGI.new("html4Fr") # html4.01 Frameset
+#
+class CGI
+
+ # :stopdoc:
+
+ # String for carriage return
+ CR = "\015"
+
+ # String for linefeed
+ LF = "\012"
+
+ # Standard internet newline sequence
+ EOL = CR + LF
+
+ REVISION = '$Id: cgi.rb 12050 2007-03-12 17:55:03Z knu $' #:nodoc:
+
+ NEEDS_BINMODE = true if /WIN/ni.match(RUBY_PLATFORM)
+
+ # Path separators in different environments.
+ PATH_SEPARATOR = {'UNIX'=>'/', 'WINDOWS'=>'\\', 'MACINTOSH'=>':'}
+
+ # HTTP status codes.
+ HTTP_STATUS = {
+ "OK" => "200 OK",
+ "PARTIAL_CONTENT" => "206 Partial Content",
+ "MULTIPLE_CHOICES" => "300 Multiple Choices",
+ "MOVED" => "301 Moved Permanently",
+ "REDIRECT" => "302 Found",
+ "NOT_MODIFIED" => "304 Not Modified",
+ "BAD_REQUEST" => "400 Bad Request",
+ "AUTH_REQUIRED" => "401 Authorization Required",
+ "FORBIDDEN" => "403 Forbidden",
+ "NOT_FOUND" => "404 Not Found",
+ "METHOD_NOT_ALLOWED" => "405 Method Not Allowed",
+ "NOT_ACCEPTABLE" => "406 Not Acceptable",
+ "LENGTH_REQUIRED" => "411 Length Required",
+ "PRECONDITION_FAILED" => "412 Rrecondition Failed",
+ "SERVER_ERROR" => "500 Internal Server Error",
+ "NOT_IMPLEMENTED" => "501 Method Not Implemented",
+ "BAD_GATEWAY" => "502 Bad Gateway",
+ "VARIANT_ALSO_VARIES" => "506 Variant Also Negotiates"
+ }
+
+ # Abbreviated day-of-week names specified by RFC 822
+ RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
+
+ # Abbreviated month names specified by RFC 822
+ RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
+
+ # :startdoc:
+
+ def env_table
+ ENV
+ end
+
+ def stdinput
+ $stdin
+ end
+
+ def stdoutput
+ $DEFAULT_OUTPUT
+ end
+
+ private :env_table, :stdinput, :stdoutput
+
+ # URL-encode a string.
+ # url_encoded_string = CGI::escape("'Stop!' said Fred")
+ # # => "%27Stop%21%27+said+Fred"
+ def CGI::escape(string)
+ string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
+ '%' + $1.unpack('H2' * $1.size).join('%').upcase
+ end.tr(' ', '+')
+ end
+
+
+ # URL-decode a string.
+ # string = CGI::unescape("%27Stop%21%27+said+Fred")
+ # # => "'Stop!' said Fred"
+ def CGI::unescape(string)
+ string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n) do
+ [$1.delete('%')].pack('H*')
+ end
+ end
+
+
+ # Escape special characters in HTML, namely &\"<>
+ # CGI::escapeHTML('Usage: foo "bar" <baz>')
+ # # => "Usage: foo "bar" <baz>"
+ def CGI::escapeHTML(string)
+ string.gsub(/&/n, '&').gsub(/\"/n, '"').gsub(/>/n, '>').gsub(/</n, '<')
+ end
+
+
+ # Unescape a string that has been HTML-escaped
+ # CGI::unescapeHTML("Usage: foo "bar" <baz>")
+ # # => "Usage: foo \"bar\" <baz>"
+ def CGI::unescapeHTML(string)
+ string.gsub(/&(amp|quot|gt|lt|\#[0-9]+|\#x[0-9A-Fa-f]+);/n) do
+ match = $1.dup
+ case match
+ when 'amp' then '&'
+ when 'quot' then '"'
+ when 'gt' then '>'
+ when 'lt' then '<'
+ when /\A#0*(\d+)\z/n then
+ if Integer($1) < 256
+ Integer($1).chr
+ else
+ if Integer($1) < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U)
+ [Integer($1)].pack("U")
+ else
+ "&##{$1};"
+ end
+ end
+ when /\A#x([0-9a-f]+)\z/ni then
+ if $1.hex < 256
+ $1.hex.chr
+ else
+ if $1.hex < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U)
+ [$1.hex].pack("U")
+ else
+ "&#x#{$1};"
+ end
+ end
+ else
+ "&#{match};"
+ end
+ end
+ end
+
+
+ # Escape only the tags of certain HTML elements in +string+.
+ #
+ # Takes an element or elements or array of elements. Each element
+ # is specified by the name of the element, without angle brackets.
+ # This matches both the start and the end tag of that element.
+ # The attribute list of the open tag will also be escaped (for
+ # instance, the double-quotes surrounding attribute values).
+ #
+ # print CGI::escapeElement('<BR><A HREF="url"></A>', "A", "IMG")
+ # # "<BR><A HREF="url"></A>"
+ #
+ # print CGI::escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"])
+ # # "<BR><A HREF="url"></A>"
+ def CGI::escapeElement(string, *elements)
+ elements = elements[0] if elements[0].kind_of?(Array)
+ unless elements.empty?
+ string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/ni) do
+ CGI::escapeHTML($&)
+ end
+ else
+ string
+ end
+ end
+
+
+ # Undo escaping such as that done by CGI::escapeElement()
+ #
+ # print CGI::unescapeElement(
+ # CGI::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
+ # # "<BR><A HREF="url"></A>"
+ #
+ # print CGI::unescapeElement(
+ # CGI::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
+ # # "<BR><A HREF="url"></A>"
+ def CGI::unescapeElement(string, *elements)
+ elements = elements[0] if elements[0].kind_of?(Array)
+ unless elements.empty?
+ string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/ni) do
+ CGI::unescapeHTML($&)
+ end
+ else
+ string
+ end
+ end
+
+
+ # Format a +Time+ object as a String using the format specified by RFC 1123.
+ #
+ # CGI::rfc1123_date(Time.now)
+ # # Sat, 01 Jan 2000 00:00:00 GMT
+ def CGI::rfc1123_date(time)
+ t = time.clone.gmtime
+ return format("%s, %.2d %s %.4d %.2d:%.2d:%.2d GMT",
+ RFC822_DAYS[t.wday], t.day, RFC822_MONTHS[t.month-1], t.year,
+ t.hour, t.min, t.sec)
+ end
+
+
+ # Create an HTTP header block as a string.
+ #
+ # Includes the empty line that ends the header block.
+ #
+ # +options+ can be a string specifying the Content-Type (defaults
+ # to text/html), or a hash of header key/value pairs. The following
+ # header keys are recognized:
+ #
+ # type:: the Content-Type header. Defaults to "text/html"
+ # charset:: the charset of the body, appended to the Content-Type header.
+ # nph:: a boolean value. If true, prepend protocol string and status code, and
+ # date; and sets default values for "server" and "connection" if not
+ # explicitly set.
+ # status:: the HTTP status code, returned as the Status header. See the
+ # list of available status codes below.
+ # server:: the server software, returned as the Server header.
+ # connection:: the connection type, returned as the Connection header (for
+ # instance, "close".
+ # length:: the length of the content that will be sent, returned as the
+ # Content-Length header.
+ # language:: the language of the content, returned as the Content-Language
+ # header.
+ # expires:: the time on which the current content expires, as a +Time+
+ # object, returned as the Expires header.
+ # cookie:: a cookie or cookies, returned as one or more Set-Cookie headers.
+ # The value can be the literal string of the cookie; a CGI::Cookie
+ # object; an Array of literal cookie strings or Cookie objects; or a
+ # hash all of whose values are literal cookie strings or Cookie objects.
+ # These cookies are in addition to the cookies held in the
+ # @output_cookies field.
+ #
+ # Other header lines can also be set; they are appended as key: value.
+ #
+ # header
+ # # Content-Type: text/html
+ #
+ # header("text/plain")
+ # # Content-Type: text/plain
+ #
+ # header("nph" => true,
+ # "status" => "OK", # == "200 OK"
+ # # "status" => "200 GOOD",
+ # "server" => ENV['SERVER_SOFTWARE'],
+ # "connection" => "close",
+ # "type" => "text/html",
+ # "charset" => "iso-2022-jp",
+ # # Content-Type: text/html; charset=iso-2022-jp
+ # "length" => 103,
+ # "language" => "ja",
+ # "expires" => Time.now + 30,
+ # "cookie" => [cookie1, cookie2],
+ # "my_header1" => "my_value"
+ # "my_header2" => "my_value")
+ #
+ # The status codes are:
+ #
+ # "OK" --> "200 OK"
+ # "PARTIAL_CONTENT" --> "206 Partial Content"
+ # "MULTIPLE_CHOICES" --> "300 Multiple Choices"
+ # "MOVED" --> "301 Moved Permanently"
+ # "REDIRECT" --> "302 Found"
+ # "NOT_MODIFIED" --> "304 Not Modified"
+ # "BAD_REQUEST" --> "400 Bad Request"
+ # "AUTH_REQUIRED" --> "401 Authorization Required"
+ # "FORBIDDEN" --> "403 Forbidden"
+ # "NOT_FOUND" --> "404 Not Found"
+ # "METHOD_NOT_ALLOWED" --> "405 Method Not Allowed"
+ # "NOT_ACCEPTABLE" --> "406 Not Acceptable"
+ # "LENGTH_REQUIRED" --> "411 Length Required"
+ # "PRECONDITION_FAILED" --> "412 Precondition Failed"
+ # "SERVER_ERROR" --> "500 Internal Server Error"
+ # "NOT_IMPLEMENTED" --> "501 Method Not Implemented"
+ # "BAD_GATEWAY" --> "502 Bad Gateway"
+ # "VARIANT_ALSO_VARIES" --> "506 Variant Also Negotiates"
+ #
+ # This method does not perform charset conversion.
+ #
+ def header(options = "text/html")
+
+ buf = ""
+
+ case options
+ when String
+ options = { "type" => options }
+ when Hash
+ options = options.dup
+ end
+
+ unless options.has_key?("type")
+ options["type"] = "text/html"
+ end
+
+ if options.has_key?("charset")
+ options["type"] += "; charset=" + options.delete("charset")
+ end
+
+ options.delete("nph") if defined?(MOD_RUBY)
+ if options.delete("nph") or
+ (/IIS\/(\d+)/n.match(env_table['SERVER_SOFTWARE']) and $1.to_i < 5)
+ buf += (env_table["SERVER_PROTOCOL"] or "HTTP/1.0") + " " +
+ (HTTP_STATUS[options["status"]] or options["status"] or "200 OK") +
+ EOL +
+ "Date: " + CGI::rfc1123_date(Time.now) + EOL
+
+ unless options.has_key?("server")
+ options["server"] = (env_table['SERVER_SOFTWARE'] or "")
+ end
+
+ unless options.has_key?("connection")
+ options["connection"] = "close"
+ end
+
+ options.delete("status")
+ end
+
+ if options.has_key?("status")
+ buf += "Status: " +
+ (HTTP_STATUS[options["status"]] or options["status"]) + EOL
+ options.delete("status")
+ end
+
+ if options.has_key?("server")
+ buf += "Server: " + options.delete("server") + EOL
+ end
+
+ if options.has_key?("connection")
+ buf += "Connection: " + options.delete("connection") + EOL
+ end
+
+ buf += "Content-Type: " + options.delete("type") + EOL
+
+ if options.has_key?("length")
+ buf += "Content-Length: " + options.delete("length").to_s + EOL
+ end
+
+ if options.has_key?("language")
+ buf += "Content-Language: " + options.delete("language") + EOL
+ end
+
+ if options.has_key?("expires")
+ buf += "Expires: " + CGI::rfc1123_date( options.delete("expires") ) + EOL
+ end
+
+ if options.has_key?("cookie")
+ if options["cookie"].kind_of?(String) or
+ options["cookie"].kind_of?(Cookie)
+ buf += "Set-Cookie: " + options.delete("cookie").to_s + EOL
+ elsif options["cookie"].kind_of?(Array)
+ options.delete("cookie").each{|cookie|
+ buf += "Set-Cookie: " + cookie.to_s + EOL
+ }
+ elsif options["cookie"].kind_of?(Hash)
+ options.delete("cookie").each_value{|cookie|
+ buf += "Set-Cookie: " + cookie.to_s + EOL
+ }
+ end
+ end
+ if @output_cookies
+ for cookie in @output_cookies
+ buf += "Set-Cookie: " + cookie.to_s + EOL
+ end
+ end
+
+ options.each{|key, value|
+ buf += key + ": " + value.to_s + EOL
+ }
+
+ if defined?(MOD_RUBY)
+ table = Apache::request.headers_out
+ buf.scan(/([^:]+): (.+)#{EOL}/n){ |name, value|
+ warn sprintf("name:%s value:%s\n", name, value) if $DEBUG
+ case name
+ when 'Set-Cookie'
+ table.add(name, value)
+ when /^status$/ni
+ Apache::request.status_line = value
+ Apache::request.status = value.to_i
+ when /^content-type$/ni
+ Apache::request.content_type = value
+ when /^content-encoding$/ni
+ Apache::request.content_encoding = value
+ when /^location$/ni
+ if Apache::request.status == 200
+ Apache::request.status = 302
+ end
+ Apache::request.headers_out[name] = value
+ else
+ Apache::request.headers_out[name] = value
+ end
+ }
+ Apache::request.send_http_header
+ ''
+ else
+ buf + EOL
+ end
+
+ end # header()
+
+
+ # Print an HTTP header and body to $DEFAULT_OUTPUT ($>)
+ #
+ # The header is provided by +options+, as for #header().
+ # The body of the document is that returned by the passed-
+ # in block. This block takes no arguments. It is required.
+ #
+ # cgi = CGI.new
+ # cgi.out{ "string" }
+ # # Content-Type: text/html
+ # # Content-Length: 6
+ # #
+ # # string
+ #
+ # cgi.out("text/plain") { "string" }
+ # # Content-Type: text/plain
+ # # Content-Length: 6
+ # #
+ # # string
+ #
+ # cgi.out("nph" => true,
+ # "status" => "OK", # == "200 OK"
+ # "server" => ENV['SERVER_SOFTWARE'],
+ # "connection" => "close",
+ # "type" => "text/html",
+ # "charset" => "iso-2022-jp",
+ # # Content-Type: text/html; charset=iso-2022-jp
+ # "language" => "ja",
+ # "expires" => Time.now + (3600 * 24 * 30),
+ # "cookie" => [cookie1, cookie2],
+ # "my_header1" => "my_value",
+ # "my_header2" => "my_value") { "string" }
+ #
+ # Content-Length is automatically calculated from the size of
+ # the String returned by the content block.
+ #
+ # If ENV['REQUEST_METHOD'] == "HEAD", then only the header
+ # is outputted (the content block is still required, but it
+ # is ignored).
+ #
+ # If the charset is "iso-2022-jp" or "euc-jp" or "shift_jis" then
+ # the content is converted to this charset, and the language is set
+ # to "ja".
+ def out(options = "text/html") # :yield:
+
+ options = { "type" => options } if options.kind_of?(String)
+ content = yield
+
+ if options.has_key?("charset")
+ require "nkf"
+ case options["charset"]
+ when /iso-2022-jp/ni
+ content = NKF::nkf('-m0 -x -j', content)
+ options["language"] = "ja" unless options.has_key?("language")
+ when /euc-jp/ni
+ content = NKF::nkf('-m0 -x -e', content)
+ options["language"] = "ja" unless options.has_key?("language")
+ when /shift_jis/ni
+ content = NKF::nkf('-m0 -x -s', content)
+ options["language"] = "ja" unless options.has_key?("language")
+ end
+ end
+
+ options["length"] = content.length.to_s
+ output = stdoutput
+ output.binmode if defined? output.binmode
+ output.print header(options)
+ output.print content unless "HEAD" == env_table['REQUEST_METHOD']
+ end
+
+
+ # Print an argument or list of arguments to the default output stream
+ #
+ # cgi = CGI.new
+ # cgi.print # default: cgi.print == $DEFAULT_OUTPUT.print
+ def print(*options)
+ stdoutput.print(*options)
+ end
+
+ require "delegate"
+
+ # Class representing an HTTP cookie.
+ #
+ # In addition to its specific fields and methods, a Cookie instance
+ # is a delegator to the array of its values.
+ #
+ # See RFC 2965.
+ #
+ # == Examples of use
+ # cookie1 = CGI::Cookie::new("name", "value1", "value2", ...)
+ # cookie1 = CGI::Cookie::new("name" => "name", "value" => "value")
+ # cookie1 = CGI::Cookie::new('name' => 'name',
+ # 'value' => ['value1', 'value2', ...],
+ # 'path' => 'path', # optional
+ # 'domain' => 'domain', # optional
+ # 'expires' => Time.now, # optional
+ # 'secure' => true # optional
+ # )
+ #
+ # cgi.out("cookie" => [cookie1, cookie2]) { "string" }
+ #
+ # name = cookie1.name
+ # values = cookie1.value
+ # path = cookie1.path
+ # domain = cookie1.domain
+ # expires = cookie1.expires
+ # secure = cookie1.secure
+ #
+ # cookie1.name = 'name'
+ # cookie1.value = ['value1', 'value2', ...]
+ # cookie1.path = 'path'
+ # cookie1.domain = 'domain'
+ # cookie1.expires = Time.now + 30
+ # cookie1.secure = true
+ class Cookie < DelegateClass(Array)
+
+ # Create a new CGI::Cookie object.
+ #
+ # The contents of the cookie can be specified as a +name+ and one
+ # or more +value+ arguments. Alternatively, the contents can
+ # be specified as a single hash argument. The possible keywords of
+ # this hash are as follows:
+ #
+ # name:: the name of the cookie. Required.
+ # value:: the cookie's value or list of values.
+ # path:: the path for which this cookie applies. Defaults to the
+ # base directory of the CGI script.
+ # domain:: the domain for which this cookie applies.
+ # expires:: the time at which this cookie expires, as a +Time+ object.
+ # secure:: whether this cookie is a secure cookie or not (default to
+ # false). Secure cookies are only transmitted to HTTPS
+ # servers.
+ #
+ # These keywords correspond to attributes of the cookie object.
+ def initialize(name = "", *value)
+ options = if name.kind_of?(String)
+ { "name" => name, "value" => value }
+ else
+ name
+ end
+ unless options.has_key?("name")
+ raise ArgumentError, "`name' required"
+ end
+
+ @name = options["name"]
+ @value = Array(options["value"])
+ # simple support for IE
+ if options["path"]
+ @path = options["path"]
+ else
+ %r|^(.*/)|.match(ENV["SCRIPT_NAME"])
+ @path = ($1 or "")
+ end
+ @domain = options["domain"]
+ @expires = options["expires"]
+ @secure = options["secure"] == true ? true : false
+
+ super(@value)
+ end
+
+ attr_accessor("name", "value", "path", "domain", "expires")
+ attr_reader("secure")
+
+ # Set whether the Cookie is a secure cookie or not.
+ #
+ # +val+ must be a boolean.
+ def secure=(val)
+ @secure = val if val == true or val == false
+ @secure
+ end
+
+ # Convert the Cookie to its string representation.
+ def to_s
+ buf = ""
+ buf += @name + '='
+
+ if @value.kind_of?(String)
+ buf += CGI::escape(@value)
+ else
+ buf += @value.collect{|v| CGI::escape(v) }.join("&")
+ end
+
+ if @domain
+ buf += '; domain=' + @domain
+ end
+
+ if @path
+ buf += '; path=' + @path
+ end
+
+ if @expires
+ buf += '; expires=' + CGI::rfc1123_date(@expires)
+ end
+
+ if @secure == true
+ buf += '; secure'
+ end
+
+ buf
+ end
+
+ end # class Cookie
+
+
+ # Parse a raw cookie string into a hash of cookie-name=>Cookie
+ # pairs.
+ #
+ # cookies = CGI::Cookie::parse("raw_cookie_string")
+ # # { "name1" => cookie1, "name2" => cookie2, ... }
+ #
+ def Cookie::parse(raw_cookie)
+ cookies = Hash.new([])
+ return cookies unless raw_cookie
+
+ raw_cookie.split(/[;,]\s?/).each do |pairs|
+ name, values = pairs.split('=',2)
+ next unless name and values
+ name = CGI::unescape(name)
+ values ||= ""
+ values = values.split('&').collect{|v| CGI::unescape(v) }
+ if cookies.has_key?(name)
+ values = cookies[name].value + values
+ end
+ cookies[name] = Cookie::new({ "name" => name, "value" => values })
+ end
+
+ cookies
+ end
+
+ # Parse an HTTP query string into a hash of key=>value pairs.
+ #
+ # params = CGI::parse("query_string")
+ # # {"name1" => ["value1", "value2", ...],
+ # # "name2" => ["value1", "value2", ...], ... }
+ #
+ def CGI::parse(query)
+ params = Hash.new([].freeze)
+
+ query.split(/[&;]/n).each do |pairs|
+ key, value = pairs.split('=',2).collect{|v| CGI::unescape(v) }
+ if params.has_key?(key)
+ params[key].push(value)
+ else
+ params[key] = [value]
+ end
+ end
+
+ params
+ end
+
+ # Mixin module. It provides the follow functionality groups:
+ #
+ # 1. Access to CGI environment variables as methods. See
+ # documentation to the CGI class for a list of these variables.
+ #
+ # 2. Access to cookies, including the cookies attribute.
+ #
+ # 3. Access to parameters, including the params attribute, and overloading
+ # [] to perform parameter value lookup by key.
+ #
+ # 4. The initialize_query method, for initialising the above
+ # mechanisms, handling multipart forms, and allowing the
+ # class to be used in "offline" mode.
+ #
+ module QueryExtension
+
+ %w[ CONTENT_LENGTH SERVER_PORT ].each do |env|
+ define_method(env.sub(/^HTTP_/n, '').downcase) do
+ (val = env_table[env]) && Integer(val)
+ end
+ end
+
+ %w[ AUTH_TYPE CONTENT_TYPE GATEWAY_INTERFACE PATH_INFO
+ PATH_TRANSLATED QUERY_STRING REMOTE_ADDR REMOTE_HOST
+ REMOTE_IDENT REMOTE_USER REQUEST_METHOD SCRIPT_NAME
+ SERVER_NAME SERVER_PROTOCOL SERVER_SOFTWARE
+
+ HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING
+ HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM HTTP_HOST
+ HTTP_NEGOTIATE HTTP_PRAGMA HTTP_REFERER HTTP_USER_AGENT ].each do |env|
+ define_method(env.sub(/^HTTP_/n, '').downcase) do
+ env_table[env]
+ end
+ end
+
+ # Get the raw cookies as a string.
+ def raw_cookie
+ env_table["HTTP_COOKIE"]
+ end
+
+ # Get the raw RFC2965 cookies as a string.
+ def raw_cookie2
+ env_table["HTTP_COOKIE2"]
+ end
+
+ # Get the cookies as a hash of cookie-name=>Cookie pairs.
+ attr_accessor("cookies")
+
+ # Get the parameters as a hash of name=>values pairs, where
+ # values is an Array.
+ attr("params")
+
+ # Set all the parameters.
+ def params=(hash)
+ @params.clear
+ @params.update(hash)
+ end
+
+ def read_multipart(boundary, content_length)
+ params = Hash.new([])
+ boundary = "--" + boundary
+ quoted_boundary = Regexp.quote(boundary, "n")
+ buf = ""
+ bufsize = 10 * 1024
+ boundary_end=""
+
+ # start multipart/form-data
+ stdinput.binmode if defined? stdinput.binmode
+ boundary_size = boundary.size + EOL.size
+ content_length -= boundary_size
+ status = stdinput.read(boundary_size)
+ if nil == status
+ raise EOFError, "no content body"
+ elsif boundary + EOL != status
+ raise EOFError, "bad content body"
+ end
+
+ loop do
+ head = nil
+ if 10240 < content_length
+ require "tempfile"
+ body = Tempfile.new("CGI")
+ else
+ begin
+ require "stringio"
+ body = StringIO.new
+ rescue LoadError
+ require "tempfile"
+ body = Tempfile.new("CGI")
+ end
+ end
+ body.binmode if defined? body.binmode
+
+ until head and /#{quoted_boundary}(?:#{EOL}|--)/n.match(buf)
+
+ if (not head) and /#{EOL}#{EOL}/n.match(buf)
+ buf = buf.sub(/\A((?:.|\n)*?#{EOL})#{EOL}/n) do
+ head = $1.dup
+ ""
+ end
+ next
+ end
+
+ if head and ( (EOL + boundary + EOL).size < buf.size )
+ body.print buf[0 ... (buf.size - (EOL + boundary + EOL).size)]
+ buf[0 ... (buf.size - (EOL + boundary + EOL).size)] = ""
+ end
+
+ c = if bufsize < content_length
+ stdinput.read(bufsize)
+ else
+ stdinput.read(content_length)
+ end
+ if c.nil? || c.empty?
+ raise EOFError, "bad content body"
+ end
+ buf.concat(c)
+ content_length -= c.size
+ end
+
+ buf = buf.sub(/\A((?:.|\n)*?)(?:[\r\n]{1,2})?#{quoted_boundary}([\r\n]{1,2}|--)/n) do
+ body.print $1
+ if "--" == $2
+ content_length = -1
+ end
+ boundary_end = $2.dup
+ ""
+ end
+
+ body.rewind
+
+ /Content-Disposition:.* filename=(?:"((?:\\.|[^\"])*)"|([^;]*))/ni.match(head)
+ filename = ($1 or $2 or "")
+ if /Mac/ni.match(env_table['HTTP_USER_AGENT']) and
+ /Mozilla/ni.match(env_table['HTTP_USER_AGENT']) and
+ (not /MSIE/ni.match(env_table['HTTP_USER_AGENT']))
+ filename = CGI::unescape(filename)
+ end
+
+ /Content-Type: (.*)/ni.match(head)
+ content_type = ($1 or "")
+
+ (class << body; self; end).class_eval do
+ alias local_path path
+ define_method(:original_filename) {filename.dup.taint}
+ define_method(:content_type) {content_type.dup.taint}
+ end
+
+ /Content-Disposition:.* name="?([^\";]*)"?/ni.match(head)
+ name = $1.dup
+
+ if params.has_key?(name)
+ params[name].push(body)
+ else
+ params[name] = [body]
+ end
+ break if buf.size == 0
+ break if content_length == -1
+ end
+ raise EOFError, "bad boundary end of body part" unless boundary_end=~/--/
+
+ params
+ end # read_multipart
+ private :read_multipart
+
+ # offline mode. read name=value pairs on standard input.
+ def read_from_cmdline
+ require "shellwords"
+
+ string = unless ARGV.empty?
+ ARGV.join(' ')
+ else
+ if STDIN.tty?
+ STDERR.print(
+ %|(offline mode: enter name=value pairs on standard input)\n|
+ )
+ end
+ readlines.join(' ').gsub(/\n/n, '')
+ end.gsub(/\\=/n, '%3D').gsub(/\\&/n, '%26')
+
+ words = Shellwords.shellwords(string)
+
+ if words.find{|x| /=/n.match(x) }
+ words.join('&')
+ else
+ words.join('+')
+ end
+ end
+ private :read_from_cmdline
+
+ # Initialize the data from the query.
+ #
+ # Handles multipart forms (in particular, forms that involve file uploads).
+ # Reads query parameters in the @params field, and cookies into @cookies.
+ def initialize_query()
+ if ("POST" == env_table['REQUEST_METHOD']) and
+ %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n.match(env_table['CONTENT_TYPE'])
+ boundary = $1.dup
+ @multipart = true
+ @params = read_multipart(boundary, Integer(env_table['CONTENT_LENGTH']))
+ else
+ @multipart = false
+ @params = CGI::parse(
+ case env_table['REQUEST_METHOD']
+ when "GET", "HEAD"
+ if defined?(MOD_RUBY)
+ Apache::request.args or ""
+ else
+ env_table['QUERY_STRING'] or ""
+ end
+ when "POST"
+ stdinput.binmode if defined? stdinput.binmode
+ stdinput.read(Integer(env_table['CONTENT_LENGTH'])) or ''
+ else
+ read_from_cmdline
+ end
+ )
+ end
+
+ @cookies = CGI::Cookie::parse((env_table['HTTP_COOKIE'] or env_table['COOKIE']))
+ end
+ private :initialize_query
+
+ def multipart?
+ @multipart
+ end
+
+ module Value # :nodoc:
+ def set_params(params)
+ @params = params
+ end
+ def [](idx, *args)
+ if args.size == 0
+ warn "#{caller(1)[0]}:CAUTION! cgi['key'] == cgi.params['key'][0]; if want Array, use cgi.params['key']"
+ @params[idx]
+ else
+ super[idx,*args]
+ end
+ end
+ def first
+ warn "#{caller(1)[0]}:CAUTION! cgi['key'] == cgi.params['key'][0]; if want Array, use cgi.params['key']"
+ self
+ end
+ alias last first
+ def to_a
+ @params || [self]
+ end
+ alias to_ary to_a # to be rhs of multiple assignment
+ end
+
+ # Get the value for the parameter with a given key.
+ #
+ # If the parameter has multiple values, only the first will be
+ # retrieved; use #params() to get the array of values.
+ def [](key)
+ params = @params[key]
+ value = params[0]
+ if @multipart
+ if value
+ return value
+ elsif defined? StringIO
+ StringIO.new("")
+ else
+ Tempfile.new("CGI")
+ end
+ else
+ str = if value then value.dup else "" end
+ str.extend(Value)
+ str.set_params(params)
+ str
+ end
+ end
+
+ # Return all parameter keys as an array.
+ def keys(*args)
+ @params.keys(*args)
+ end
+
+ # Returns true if a given parameter key exists in the query.
+ def has_key?(*args)
+ @params.has_key?(*args)
+ end
+ alias key? has_key?
+ alias include? has_key?
+
+ end # QueryExtension
+
+
+ # Prettify (indent) an HTML string.
+ #
+ # +string+ is the HTML string to indent. +shift+ is the indentation
+ # unit to use; it defaults to two spaces.
+ #
+ # print CGI::pretty("<HTML><BODY></BODY></HTML>")
+ # # <HTML>
+ # # <BODY>
+ # # </BODY>
+ # # </HTML>
+ #
+ # print CGI::pretty("<HTML><BODY></BODY></HTML>", "\t")
+ # # <HTML>
+ # # <BODY>
+ # # </BODY>
+ # # </HTML>
+ #
+ def CGI::pretty(string, shift = " ")
+ lines = string.gsub(/(?!\A)<(?:.|\n)*?>/n, "\n\\0").gsub(/<(?:.|\n)*?>(?!\n)/n, "\\0\n")
+ end_pos = 0
+ while end_pos = lines.index(/^<\/(\w+)/n, end_pos)
+ element = $1.dup
+ start_pos = lines.rindex(/^\s*<#{element}/ni, end_pos)
+ lines[start_pos ... end_pos] = "__" + lines[start_pos ... end_pos].gsub(/\n(?!\z)/n, "\n" + shift) + "__"
+ end
+ lines.gsub(/^((?:#{Regexp::quote(shift)})*)__(?=<\/?\w)/n, '\1')
+ end
+
+
+ # Base module for HTML-generation mixins.
+ #
+ # Provides methods for code generation for tags following
+ # the various DTD element types.
+ module TagMaker # :nodoc:
+
+ # Generate code for an element with required start and end tags.
+ #
+ # - -
+ def nn_element_def(element)
+ nOE_element_def(element, <<-END)
+ if block_given?
+ yield.to_s
+ else
+ ""
+ end +
+ "</#{element.upcase}>"
+ END
+ end
+
+ # Generate code for an empty element.
+ #
+ # - O EMPTY
+ def nOE_element_def(element, append = nil)
+ s = <<-END
+ "<#{element.upcase}" + attributes.collect{|name, value|
+ next unless value
+ " " + CGI::escapeHTML(name) +
+ if true == value
+ ""
+ else
+ '="' + CGI::escapeHTML(value) + '"'
+ end
+ }.to_s + ">"
+ END
+ s.sub!(/\Z/, " +") << append if append
+ s
+ end
+
+ # Generate code for an element for which the end (and possibly the
+ # start) tag is optional.
+ #
+ # O O or - O
+ def nO_element_def(element)
+ nOE_element_def(element, <<-END)
+ if block_given?
+ yield.to_s + "</#{element.upcase}>"
+ else
+ ""
+ end
+ END
+ end
+
+ end # TagMaker
+
+
+ #
+ # Mixin module providing HTML generation methods.
+ #
+ # For example,
+ # cgi.a("http://www.example.com") { "Example" }
+ # # => "<A HREF=\"http://www.example.com\">Example</A>"
+ #
+ # Modules Http3, Http4, etc., contain more basic HTML-generation methods
+ # (:title, :center, etc.).
+ #
+ # See class CGI for a detailed example.
+ #
+ module HtmlExtension
+
+
+ # Generate an Anchor element as a string.
+ #
+ # +href+ can either be a string, giving the URL
+ # for the HREF attribute, or it can be a hash of
+ # the element's attributes.
+ #
+ # The body of the element is the string returned by the no-argument
+ # block passed in.
+ #
+ # a("http://www.example.com") { "Example" }
+ # # => "<A HREF=\"http://www.example.com\">Example</A>"
+ #
+ # a("HREF" => "http://www.example.com", "TARGET" => "_top") { "Example" }
+ # # => "<A HREF=\"http://www.example.com\" TARGET=\"_top\">Example</A>"
+ #
+ def a(href = "") # :yield:
+ attributes = if href.kind_of?(String)
+ { "HREF" => href }
+ else
+ href
+ end
+ if block_given?
+ super(attributes){ yield }
+ else
+ super(attributes)
+ end
+ end
+
+ # Generate a Document Base URI element as a String.
+ #
+ # +href+ can either by a string, giving the base URL for the HREF
+ # attribute, or it can be a has of the element's attributes.
+ #
+ # The passed-in no-argument block is ignored.
+ #
+ # base("http://www.example.com/cgi")
+ # # => "<BASE HREF=\"http://www.example.com/cgi\">"
+ def base(href = "") # :yield:
+ attributes = if href.kind_of?(String)
+ { "HREF" => href }
+ else
+ href
+ end
+ if block_given?
+ super(attributes){ yield }
+ else
+ super(attributes)
+ end
+ end
+
+ # Generate a BlockQuote element as a string.
+ #
+ # +cite+ can either be a string, give the URI for the source of
+ # the quoted text, or a hash, giving all attributes of the element,
+ # or it can be omitted, in which case the element has no attributes.
+ #
+ # The body is provided by the passed-in no-argument block
+ #
+ # blockquote("http://www.example.com/quotes/foo.html") { "Foo!" }
+ # #=> "<BLOCKQUOTE CITE=\"http://www.example.com/quotes/foo.html\">Foo!</BLOCKQUOTE>
+ def blockquote(cite = nil) # :yield:
+ attributes = if cite.kind_of?(String)
+ { "CITE" => cite }
+ else
+ cite or ""
+ end
+ if block_given?
+ super(attributes){ yield }
+ else
+ super(attributes)
+ end
+ end
+
+
+ # Generate a Table Caption element as a string.
+ #
+ # +align+ can be a string, giving the alignment of the caption
+ # (one of top, bottom, left, or right). It can be a hash of
+ # all the attributes of the element. Or it can be omitted.
+ #
+ # The body of the element is provided by the passed-in no-argument block.
+ #
+ # caption("left") { "Capital Cities" }
+ # # => <CAPTION ALIGN=\"left\">Capital Cities</CAPTION>
+ def caption(align = nil) # :yield:
+ attributes = if align.kind_of?(String)
+ { "ALIGN" => align }
+ else
+ align or ""
+ end
+ if block_given?
+ super(attributes){ yield }
+ else
+ super(attributes)
+ end
+ end
+
+
+ # Generate a Checkbox Input element as a string.
+ #
+ # The attributes of the element can be specified as three arguments,
+ # +name+, +value+, and +checked+. +checked+ is a boolean value;
+ # if true, the CHECKED attribute will be included in the element.
+ #
+ # Alternatively, the attributes can be specified as a hash.
+ #
+ # checkbox("name")
+ # # = checkbox("NAME" => "name")
+ #
+ # checkbox("name", "value")
+ # # = checkbox("NAME" => "name", "VALUE" => "value")
+ #
+ # checkbox("name", "value", true)
+ # # = checkbox("NAME" => "name", "VALUE" => "value", "CHECKED" => true)
+ def checkbox(name = "", value = nil, checked = nil)
+ attributes = if name.kind_of?(String)
+ { "TYPE" => "checkbox", "NAME" => name,
+ "VALUE" => value, "CHECKED" => checked }
+ else
+ name["TYPE"] = "checkbox"
+ name
+ end
+ input(attributes)
+ end
+
+ # Generate a sequence of checkbox elements, as a String.
+ #
+ # The checkboxes will all have the same +name+ attribute.
+ # Each checkbox is followed by a label.
+ # There will be one checkbox for each value. Each value
+ # can be specified as a String, which will be used both
+ # as the value of the VALUE attribute and as the label
+ # for that checkbox. A single-element array has the
+ # same effect.
+ #
+ # Each value can also be specified as a three-element array.
+ # The first element is the VALUE attribute; the second is the
+ # label; and the third is a boolean specifying whether this
+ # checkbox is CHECKED.
+ #
+ # Each value can also be specified as a two-element
+ # array, by omitting either the value element (defaults
+ # to the same as the label), or the boolean checked element
+ # (defaults to false).
+ #
+ # checkbox_group("name", "foo", "bar", "baz")
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="bar">bar
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
+ #
+ # checkbox_group("name", ["foo"], ["bar", true], "baz")
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
+ # # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="bar">bar
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
+ #
+ # checkbox_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="1">Foo
+ # # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="2">Bar
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="Baz">Baz
+ #
+ # checkbox_group("NAME" => "name",
+ # "VALUES" => ["foo", "bar", "baz"])
+ #
+ # checkbox_group("NAME" => "name",
+ # "VALUES" => [["foo"], ["bar", true], "baz"])
+ #
+ # checkbox_group("NAME" => "name",
+ # "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
+ def checkbox_group(name = "", *values)
+ if name.kind_of?(Hash)
+ values = name["VALUES"]
+ name = name["NAME"]
+ end
+ values.collect{|value|
+ if value.kind_of?(String)
+ checkbox(name, value) + value
+ else
+ if value[value.size - 1] == true
+ checkbox(name, value[0], true) +
+ value[value.size - 2]
+ else
+ checkbox(name, value[0]) +
+ value[value.size - 1]
+ end
+ end
+ }.to_s
+ end
+
+
+ # Generate an File Upload Input element as a string.
+ #
+ # The attributes of the element can be specified as three arguments,
+ # +name+, +size+, and +maxlength+. +maxlength+ is the maximum length
+ # of the file's _name_, not of the file's _contents_.
+ #
+ # Alternatively, the attributes can be specified as a hash.
+ #
+ # See #multipart_form() for forms that include file uploads.
+ #
+ # file_field("name")
+ # # <INPUT TYPE="file" NAME="name" SIZE="20">
+ #
+ # file_field("name", 40)
+ # # <INPUT TYPE="file" NAME="name" SIZE="40">
+ #
+ # file_field("name", 40, 100)
+ # # <INPUT TYPE="file" NAME="name" SIZE="40" MAXLENGTH="100">
+ #
+ # file_field("NAME" => "name", "SIZE" => 40)
+ # # <INPUT TYPE="file" NAME="name" SIZE="40">
+ def file_field(name = "", size = 20, maxlength = nil)
+ attributes = if name.kind_of?(String)
+ { "TYPE" => "file", "NAME" => name,
+ "SIZE" => size.to_s }
+ else
+ name["TYPE"] = "file"
+ name
+ end
+ attributes["MAXLENGTH"] = maxlength.to_s if maxlength
+ input(attributes)
+ end
+
+
+ # Generate a Form element as a string.
+ #
+ # +method+ should be either "get" or "post", and defaults to the latter.
+ # +action+ defaults to the current CGI script name. +enctype+
+ # defaults to "application/x-www-form-urlencoded".
+ #
+ # Alternatively, the attributes can be specified as a hash.
+ #
+ # See also #multipart_form() for forms that include file uploads.
+ #
+ # form{ "string" }
+ # # <FORM METHOD="post" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
+ #
+ # form("get") { "string" }
+ # # <FORM METHOD="get" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
+ #
+ # form("get", "url") { "string" }
+ # # <FORM METHOD="get" ACTION="url" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
+ #
+ # form("METHOD" => "post", "ENCTYPE" => "enctype") { "string" }
+ # # <FORM METHOD="post" ENCTYPE="enctype">string</FORM>
+ def form(method = "post", action = script_name, enctype = "application/x-www-form-urlencoded")
+ attributes = if method.kind_of?(String)
+ { "METHOD" => method, "ACTION" => action,
+ "ENCTYPE" => enctype }
+ else
+ unless method.has_key?("METHOD")
+ method["METHOD"] = "post"
+ end
+ unless method.has_key?("ENCTYPE")
+ method["ENCTYPE"] = enctype
+ end
+ method
+ end
+ if block_given?
+ body = yield
+ else
+ body = ""
+ end
+ if @output_hidden
+ body += @output_hidden.collect{|k,v|
+ "<INPUT TYPE=\"HIDDEN\" NAME=\"#{k}\" VALUE=\"#{v}\">"
+ }.to_s
+ end
+ super(attributes){body}
+ end
+
+ # Generate a Hidden Input element as a string.
+ #
+ # The attributes of the element can be specified as two arguments,
+ # +name+ and +value+.
+ #
+ # Alternatively, the attributes can be specified as a hash.
+ #
+ # hid...
[truncated message content] |
|
From: <caw...@us...> - 2007-05-29 13:12:53
|
Revision: 2542
http://svn.sourceforge.net/rubyeclipse/?rev=2542&view=rev
Author: cawilliams
Date: 2007-05-29 06:12:52 -0700 (Tue, 29 May 2007)
Log Message:
-----------
include asm jars so we can actually invoke JRuby on some ruby code and get a result in java
Modified Paths:
--------------
trunk/org.jruby/.classpath
trunk/org.jruby/META-INF/MANIFEST.MF
trunk/org.jruby/build.properties
Added Paths:
-----------
trunk/org.jruby/lib/asm-2.2.3.jar
trunk/org.jruby/lib/asm-commons-2.2.3.jar
Modified: trunk/org.jruby/.classpath
===================================================================
--- trunk/org.jruby/.classpath 2007-05-29 13:11:51 UTC (rev 2541)
+++ trunk/org.jruby/.classpath 2007-05-29 13:12:52 UTC (rev 2542)
@@ -1,7 +1,9 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry exported="true" kind="lib" path="lib/jruby.jar" sourcepath="src.zip"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry exported="true" kind="lib" path="lib/asm-2.2.3.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/asm-commons-2.2.3.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/jruby.jar" sourcepath="src.zip"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Modified: trunk/org.jruby/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.jruby/META-INF/MANIFEST.MF 2007-05-29 13:11:51 UTC (rev 2541)
+++ trunk/org.jruby/META-INF/MANIFEST.MF 2007-05-29 13:12:52 UTC (rev 2542)
@@ -6,7 +6,9 @@
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime
Eclipse-LazyStart: false
-Bundle-ClassPath: lib/jruby.jar
+Bundle-ClassPath: lib/asm-commons-2.2.3.jar,
+ lib/asm-2.2.3.jar,
+ lib/jruby.jar
Export-Package: org.ablaf.ast,
org.ablaf.internal.ast,
org.jruby,
Modified: trunk/org.jruby/build.properties
===================================================================
--- trunk/org.jruby/build.properties 2007-05-29 13:11:51 UTC (rev 2541)
+++ trunk/org.jruby/build.properties 2007-05-29 13:12:52 UTC (rev 2542)
@@ -1,3 +1,5 @@
output.. = bin/
bin.includes = META-INF/,\
- lib/jruby.jar
+ lib/jruby.jar,\
+ lib/asm-commons-2.2.3.jar,\
+ lib/asm-2.2.3.jar
Added: trunk/org.jruby/lib/asm-2.2.3.jar
===================================================================
(Binary files differ)
Property changes on: trunk/org.jruby/lib/asm-2.2.3.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/org.jruby/lib/asm-commons-2.2.3.jar
===================================================================
(Binary files differ)
Property changes on: trunk/org.jruby/lib/asm-commons-2.2.3.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-29 13:11:52
|
Revision: 2541
http://svn.sourceforge.net/rubyeclipse/?rev=2541&view=rev
Author: cawilliams
Date: 2007-05-29 06:11:51 -0700 (Tue, 29 May 2007)
Log Message:
-----------
add ability to validate constants
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyConventions.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyConventions.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyConventions.java 2007-05-29 13:11:31 UTC (rev 2540)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyConventions.java 2007-05-29 13:11:51 UTC (rev 2541)
@@ -85,10 +85,24 @@
if (!isConstant(typeName)) {
return new Status(IStatus.ERROR, RubyCore.PLUGIN_ID, -1, "Class name must be a constant. It must begin with a capital letter, and contain only letters, digits, or underscores.", null);
}
- return new Status(IStatus.OK, RubyCore.PLUGIN_ID, -1, null, null);
+ return RubyModelStatus.VERIFIED_OK;
}
+ public static IStatus validateConstant(String constantName) {
+ if (constantName == null) {
+ return new Status(IStatus.ERROR, RubyCore.PLUGIN_ID, -1, Messages.convention_type_nullName, null);
+ }
+ if (constantName.length() == 0) {
+ return new Status(IStatus.ERROR, RubyCore.PLUGIN_ID, -1, Messages.bind(Messages.convention_type_invalidName, constantName), null);
+ }
+ if (!isConstant(constantName)) {
+ return new Status(IStatus.ERROR, RubyCore.PLUGIN_ID, -1, "Name must be a constant. It must begin with a capital letter, and contain only letters, digits, or underscores.", null);
+ }
+ return RubyModelStatus.VERIFIED_OK;
+
+ }
+
private static boolean isConstant(String className) {
if (className == null || className.length() == 0) return false;
if (!Character.isLowerCase(className.charAt(0)) && !Character.isLetter(className.charAt(0)))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-29 13:11:33
|
Revision: 2540
http://svn.sourceforge.net/rubyeclipse/?rev=2540&view=rev
Author: cawilliams
Date: 2007-05-29 06:11:31 -0700 (Tue, 29 May 2007)
Log Message:
-----------
if we're on a class definition just grab that class
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/SelectionEngine.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/SelectionEngine.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/SelectionEngine.java 2007-05-29 13:11:16 UTC (rev 2539)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/SelectionEngine.java 2007-05-29 13:11:31 UTC (rev 2540)
@@ -117,7 +117,7 @@
return possible.toArray(new IRubyElement[possible.size()]);
}
// We're already on the declaration, just return it
- if ((selected instanceof DefnNode) || (selected instanceof ConstDeclNode)) {
+ if ((selected instanceof DefnNode) || (selected instanceof ConstDeclNode) || (selected instanceof ClassNode) || (selected instanceof ModuleNode)) {
IRubyElement element = ((RubyScript)script).getElementAt(start);
return new IRubyElement[] {element};
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-29 13:11:18
|
Revision: 2539
http://svn.sourceforge.net/rubyeclipse/?rev=2539&view=rev
Author: cawilliams
Date: 2007-05-29 06:11:16 -0700 (Tue, 29 May 2007)
Log Message:
-----------
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java 2007-05-29 13:10:23 UTC (rev 2538)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java 2007-05-29 13:11:16 UTC (rev 2539)
@@ -1226,7 +1226,15 @@
} else if (varNode instanceof MultipleAsgnNode) { // multiple variables in block
MultipleAsgnNode multi = (MultipleAsgnNode) varNode;
ListNode list = multi.getHeadNode();
- iter = list.iterator();
+ if (list != null)
+ iter = list.iterator();
+ else {
+ Node multiArgsNode = multi.getArgsNode();
+ if (multiArgsNode instanceof DAsgnNode) { // single variable in block
+ DAsgnNode dassgn = (DAsgnNode) multiArgsNode;
+ arguments.add(dassgn.getName());
+ }
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-29 13:10:24
|
Revision: 2538
http://svn.sourceforge.net/rubyeclipse/?rev=2538&view=rev
Author: cawilliams
Date: 2007-05-29 06:10:23 -0700 (Tue, 29 May 2007)
Log Message:
-----------
grab html formatting
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RiDocHoverProvider.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RiDocHoverProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RiDocHoverProvider.java 2007-05-29 13:07:57 UTC (rev 2537)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RiDocHoverProvider.java 2007-05-29 13:10:23 UTC (rev 2538)
@@ -24,7 +24,7 @@
args.add(0, ri.getAbsolutePath());
// these will get rid of some of the overhead formatting
args.add("-f");
- args.add("simple");
+ args.add("html");
args.add("--no-pager");
BufferedReader br = null;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
Revision: 2537
http://svn.sourceforge.net/rubyeclipse/?rev=2537&view=rev
Author: cawilliams
Date: 2007-05-29 06:07:57 -0700 (Tue, 29 May 2007)
Log Message:
-----------
try to grab a good name for the constant from the value of the selection if possible. If we grab something invalid just fall back to "CONSTANT"
Modified Paths:
--------------
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/extractconstant/ExtractConstantConfig.java
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/extractconstant/ExtractConstantConfig.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/extractconstant/ExtractConstantConfig.java 2007-05-24 08:28:12 UTC (rev 2536)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/extractconstant/ExtractConstantConfig.java 2007-05-29 13:07:57 UTC (rev 2537)
@@ -10,6 +10,8 @@
package org.rubypeople.rdt.refactoring.core.extractconstant;
import org.jruby.ast.Node;
+import org.rubypeople.rdt.core.RubyConventions;
+import org.rubypeople.rdt.internal.core.util.ASTUtil;
import org.rubypeople.rdt.refactoring.core.IRefactoringConfig;
import org.rubypeople.rdt.refactoring.core.NodeFactory;
import org.rubypeople.rdt.refactoring.core.SelectionInformation;
@@ -19,11 +21,12 @@
public class ExtractConstantConfig implements IRefactoringConfig {
+ private static final String DEFAULT_CONSTANT_NAME = "CONSTANT";
private IDocumentProvider docProvider;
private SelectionInformation selectionInfo;
private Node selectedNodes;
private Node rootNode;
- private String constName = "CONSTANT"; // FIXME Try to guess a good name from the other side of assignment?
+ private String constName = DEFAULT_CONSTANT_NAME;
public ExtractConstantConfig(DocumentProvider docProvider, SelectionInformation selectionInfo) {
this.docProvider = docProvider;
@@ -75,8 +78,42 @@
public void init() {
rootNode = getDocumentProvider().getActiveFileRootNode();
selectedNodes = SelectionNodeProvider.getSelectedNodes(rootNode, getSelection());
+ constName = extractConstantName(selectedNodes);
}
+ private String extractConstantName(Node node) {
+ String name = ASTUtil.stringRepresentation(node);
+ name = trim(name);
+ if (RubyConventions.validateConstant(name).isOK())
+ return name;
+ return DEFAULT_CONSTANT_NAME;
+ }
+
+ private String trim(String name) {
+ name = name.trim();
+ name = name.toUpperCase();
+ name = name.replace(' ', '_');
+ while(true) { // trim until first uppercase letter
+ if (name.length() == 0) break;
+ char c = name.charAt(0);
+ if (!(Character.isUpperCase(c) && Character.isLetter(c))) {
+ name = name.substring(1);
+ } else {
+ break;
+ }
+ }
+ while(true) { // trim end until letter or underscore
+ if (name.length() == 0) break;
+ char c = name.charAt(name.length() - 1);
+ if (!Character.isLetter(c) && c != '_') {
+ name = name.substring(0, name.length() - 1);
+ } else {
+ break;
+ }
+ }
+ return name;
+ }
+
public void setDocumentProvider(IDocumentProvider doc) {
this.docProvider = doc;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tc...@us...> - 2007-05-24 08:28:16
|
Revision: 2536
http://svn.sourceforge.net/rubyeclipse/?rev=2536&view=rev
Author: tcorbat
Date: 2007-05-24 01:28:12 -0700 (Thu, 24 May 2007)
Log Message:
-----------
Comment handling tested in refactorings.
Modified Paths:
--------------
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/NodeFactory.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/encapsulatefield/FieldEncapsulator.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlineclass/ConstructorInliner.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlinemethod/ParameterReplacer.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamelocal/SingleLocalVariableEdit.java
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/convertlocaltofield/temp_to_field_test_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/convertlocaltofield/temp_to_field_test_1.test_source
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/RefactoringTestCase.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_1.test_result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_1.test_source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_2.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_2.test_result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_2.test_source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_3.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_3.test_result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_3.test_source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_4.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_4.test_result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_4.test_source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_5.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_5.test_result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_5.test_source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractconstant/extract_constant_test_comment_1.result.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractconstant/extract_constant_test_comment_1.source.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractconstant/extract_constant_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractmethod/extract_method_test_comment_1.result.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractmethod/extract_method_test_comment_1.source.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractmethod/extract_method_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_comment_1.activeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_comment_1.activeFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinelocal/inline_temp_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinelocal/inline_temp_test_comment_1.test_result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinelocal/inline_temp_test_comment_1.test_source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinemethod/inline_method_test_comment_1.result.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinemethod/inline_method_test_comment_1.source.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinemethod/inline_method_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergeclasspartsinfile/merge_class_parts_in_file_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergeclasspartsinfile/merge_class_parts_in_file_test_comment_1.test_result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergeclasspartsinfile/merge_class_parts_in_file_test_comment_1.test_source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.activeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.activeFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.includedFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.includedFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.activeFile.rb.result.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.activeFile.rb.source.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.includedFile.rb.result.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.includedFile.rb.source.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.activeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.activeFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.includedFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.includedFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/pushdown/push_down_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/pushdown/push_down_test_comment_1.test_result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/pushdown/push_down_test_comment_1.test_source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.activeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.activeFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.dependantFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.dependantFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamefield/rename_field_test_comment_1.activeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamefield/rename_field_test_comment_1.activeFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamefield/rename_field_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamelocal/rename_local_test_comment_1.result.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamelocal/rename_local_test_comment_1.source.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamelocal/rename_local_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_comment_1.activeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_comment_1.activeFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_comment_1.includeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_comment_1.includeFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemethod/rename_method_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_comment_1.activeFile.rb.result
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_comment_1.activeFile.rb.source
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renamemodule/rename_module_test_comment_1.test_properties
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/splitlocal/split_temp_test_comment_1.result.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/splitlocal/split_temp_test_comment_1.source.rb
trunk/org.rubypeople.rdt.refactoring.tests/resources/core/splitlocal/split_temp_test_comment_1.test_properties
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/NodeFactory.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/NodeFactory.java 2007-05-23 20:52:16 UTC (rev 2535)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/NodeFactory.java 2007-05-24 08:28:12 UTC (rev 2536)
@@ -66,7 +66,6 @@
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.lexer.yacc.SourcePosition;
import org.jruby.parser.LocalStaticScope;
-import org.jruby.parser.ParserSupport;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Visibility;
import org.rubypeople.rdt.refactoring.nodewrapper.ArgsNodeWrapper;
@@ -76,8 +75,6 @@
public class NodeFactory {
- private static final ParserSupport parserSupport = new ParserSupport();
-
public static final SourcePosition pos = new SourcePosition();
public static final Node NULL_POSITION_NODE = new NewlineNode(pos, null);
@@ -319,10 +316,15 @@
return commentIncludingPos;
}
- public static Node createGetterSetter(String attrName, boolean isWriterMethod, VisibilityNodeWrapper.METHOD_VISIBILITY visibility) {
+ public static BlockNode createGetterSetter(String attrName, boolean isWriterMethod, VisibilityNodeWrapper.METHOD_VISIBILITY visibility){
+ return createGetterSetter(attrName, isWriterMethod, visibility, new ArrayList<CommentNode>());
+ }
+
+ public static BlockNode createGetterSetter(String attrName, boolean isWriterMethod, VisibilityNodeWrapper.METHOD_VISIBILITY visibility, Collection<CommentNode> comments) {
String methodName = attrName + ((isWriterMethod) ? "=" : ""); //$NON-NLS-1$ //$NON-NLS-2$
String[] args = (isWriterMethod) ? new String[] { attrName } : new String[] {};
DefnNode methodNode = createGetterSetterNode(isWriterMethod, methodName, attrName, args);
+ methodNode.addComments(comments);
BlockNode block = createBlockNode();
block.add(createNewLineNode(methodNode));
if (!visibility.equals(VisibilityNodeWrapper.METHOD_VISIBILITY.NONE))
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/encapsulatefield/FieldEncapsulator.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/encapsulatefield/FieldEncapsulator.java 2007-05-23 20:52:16 UTC (rev 2535)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/encapsulatefield/FieldEncapsulator.java 2007-05-24 08:28:12 UTC (rev 2536)
@@ -33,13 +33,17 @@
import java.util.ArrayList;
import java.util.Collection;
+import org.jruby.ast.BlockNode;
+import org.jruby.ast.CommentNode;
import org.jruby.ast.FCallNode;
import org.jruby.ast.Node;
+import org.jruby.lexer.yacc.SourcePosition;
import org.rubypeople.rdt.refactoring.core.NodeFactory;
import org.rubypeople.rdt.refactoring.editprovider.DeleteEditProvider;
import org.rubypeople.rdt.refactoring.editprovider.EditProvider;
import org.rubypeople.rdt.refactoring.editprovider.InsertEditProvider;
import org.rubypeople.rdt.refactoring.editprovider.MultiEditProvider;
+import org.rubypeople.rdt.refactoring.nodewrapper.AttrAccessorNodeWrapper;
import org.rubypeople.rdt.refactoring.nodewrapper.VisibilityNodeWrapper;
import org.rubypeople.rdt.refactoring.offsetprovider.AfterLastMethodInClassOffsetProvider;
import org.rubypeople.rdt.refactoring.offsetprovider.IOffsetProvider;
@@ -150,6 +154,41 @@
}
protected Node createGetterOrSetter(final boolean writer, final VisibilityNodeWrapper.METHOD_VISIBILITY visibility) {
- return NodeFactory.createGetterSetter(config.getFieldName(), writer, visibility);
+
+ Collection<CommentNode> comments = getAccessorComments(writer);
+
+ BlockNode getterAndSetter = NodeFactory.createGetterSetter(config.getFieldName(), writer, visibility, comments);
+
+ return getterAndSetter;
+ }
+
+ private Collection<CommentNode> getAccessorComments(boolean isSetter) {
+
+ ArrayList<CommentNode> matchingComments = new ArrayList<CommentNode>();
+ AttrAccessorNodeWrapper accessor = config.getSelectedAccessor();
+ if(accessor != null){
+ Collection<FCallNode> accessors = accessor.getAccessorNodes();
+
+ for(FCallNode currentAccessor : accessors){
+ if(isSetter && currentAccessor.getName().equals("attr_writer")){
+ matchingComments.addAll(currentAccessor.getComments());
+ }
+ else if(!isSetter && currentAccessor.getName().equals("attr_reader")){
+ matchingComments.addAll(currentAccessor.getComments());
+ }
+ else if(currentAccessor.getName().equals("attr_accessor")){
+ matchingComments.addAll(currentAccessor.getComments()); }
+ }
+
+ }
+ return resetCommentPositions(matchingComments);
+ }
+
+ private Collection<CommentNode> resetCommentPositions(ArrayList<CommentNode> comments) {
+ ArrayList<CommentNode> resettedComments = new ArrayList<CommentNode>();
+ for(CommentNode currentComment : comments){
+ resettedComments.add(new CommentNode(new SourcePosition("",-1,-1,-1,-1), currentComment.getContent()));
+ }
+ return resettedComments;
}
}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlineclass/ConstructorInliner.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlineclass/ConstructorInliner.java 2007-05-23 20:52:16 UTC (rev 2535)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlineclass/ConstructorInliner.java 2007-05-24 08:28:12 UTC (rev 2536)
@@ -32,6 +32,7 @@
import org.jruby.ast.MethodDefNode;
import org.jruby.ast.Node;
+import org.jruby.lexer.yacc.ISourcePosition;
import org.rubypeople.rdt.refactoring.core.NodeFactory;
import org.rubypeople.rdt.refactoring.editprovider.InsertEditProvider;
import org.rubypeople.rdt.refactoring.nodewrapper.MethodNodeWrapper;
@@ -56,9 +57,17 @@
protected Node getInsertNode(int offset, String document) {
MethodDefNode constructor = inlinedConstructor.getWrappedNode();
MethodDefNode inlinedConstructor = NodeFactory.createMethodNode(newName, constructor.getArgsNode(), constructor.getBodyNode());
+
+ ISourcePosition constructorPosition = constructor.getPosition();
+
+ inlinedConstructor.setPosition(constructorPosition);
+
+ inlinedConstructor.addComments(constructor.getComments());
+
return NodeFactory.createBlockNode(false, true, inlinedConstructor);
}
+
@Override
protected int getOffset(String document) {
BeforeFirstMethodInClassOffsetProvider offsetProvider = new BeforeFirstMethodInClassOffsetProvider(targetClass, document);
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlinemethod/ParameterReplacer.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlinemethod/ParameterReplacer.java 2007-05-23 20:52:16 UTC (rev 2535)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/inlinemethod/ParameterReplacer.java 2007-05-24 08:28:12 UTC (rev 2536)
@@ -41,6 +41,7 @@
import org.jruby.ast.Node;
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.rewriter.ReWriteVisitor;
+import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.lexer.yacc.SourcePosition;
import org.rubypeople.rdt.refactoring.core.renamelocal.LocalVariableRenamer;
import org.rubypeople.rdt.refactoring.documentprovider.DocumentProvider;
@@ -48,6 +49,7 @@
import org.rubypeople.rdt.refactoring.documentprovider.StringDocumentProvider;
import org.rubypeople.rdt.refactoring.nodewrapper.MethodCallNodeWrapper;
import org.rubypeople.rdt.refactoring.util.FileHelper;
+import org.rubypeople.rdt.refactoring.util.NodeUtil;
public class ParameterReplacer implements IParameterReplacer {
@@ -84,9 +86,10 @@
}
MethodDefNode newDefinition = (MethodDefNode) ((NewlineNode) strDoc.getActiveFileRootNode().getBodyNode()).getNextNode();
+ ISourcePosition bodyPosition = NodeUtil.subPositionUnion(newDefinition.getBodyNode());
insert.append(strDoc.getActiveFileContent().substring(
- newDefinition.getBodyNode().getPosition().getStartOffset(),
- newDefinition.getBodyNode().getPosition().getEndOffset() + 1).trim());
+ bodyPosition.getStartOffset(),
+ bodyPosition.getEndOffset() + 1).trim());
return new StringDocumentProvider("subpart_of_" + doc.getActiveFileName(), insert.toString()); //$NON-NLS-1$
}
Modified: trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamelocal/SingleLocalVariableEdit.java
===================================================================
--- trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamelocal/SingleLocalVariableEdit.java 2007-05-23 20:52:16 UTC (rev 2535)
+++ trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/renamelocal/SingleLocalVariableEdit.java 2007-05-24 08:28:12 UTC (rev 2536)
@@ -49,7 +49,7 @@
@Override
public int getOffsetLength() {
- return node.getPosition().getEndOffset() - node.getPosition().getStartOffset();
+ return node.getPositionIncludingComments().getEndOffset() - node.getPositionIncludingComments().getStartOffset();
}
@Override
@@ -66,7 +66,7 @@
@Override
public int getOffset(String document) {
- return node.getPosition().getStartOffset();
+ return node.getPositionIncludingComments().getStartOffset();
}
public Node getNode() {
Modified: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/convertlocaltofield/temp_to_field_test_1.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/convertlocaltofield/temp_to_field_test_1.test_properties 2007-05-23 20:52:16 UTC (rev 2535)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/convertlocaltofield/temp_to_field_test_1.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -1,4 +1,4 @@
newName=i
isClassField=false
initPlace=TempToFieldConverter.INIT_IN_METHOD
-cursorPosition=51
\ No newline at end of file
+cursorPosition=43
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/convertlocaltofield/temp_to_field_test_1.test_source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/convertlocaltofield/temp_to_field_test_1.test_source 2007-05-23 20:52:16 UTC (rev 2535)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/convertlocaltofield/temp_to_field_test_1.test_source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -1,6 +1,6 @@
class A
- def m (arg1, arg2)
- i = 5
- i = arg1 + arg2
- end
+ def m (arg1, arg2)
+ i = 5
+ i = arg1 + arg2
+ end
end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_1.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_1.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_1.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1 @@
+cursorPosition=44
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_1.test_result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_1.test_result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_1.test_result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,17 @@
+class X
+
+ #before accessor
+ #after accessor
+ def a
+ @a
+ end
+ public :a
+
+ #before accessor
+ #after accessor
+ def a= a
+ @a = a
+ end
+ public :a=
+
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_1.test_source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_1.test_source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_1.test_source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,4 @@
+class X
+ #before accessor
+ attr_accessor :a #after accessor
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_2.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_2.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_2.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1 @@
+cursorPosition=98
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_2.test_result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_2.test_result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_2.test_result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,21 @@
+class X
+
+ def blub
+ @a
+ end
+
+ #comment before accessor
+ #comment after accessor
+ def a
+ @a
+ end
+ public :a
+
+ #comment before accessor
+ #comment after accessor
+ def a= a
+ @a = a
+ end
+ public :a=
+
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_2.test_source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_2.test_source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_2.test_source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,8 @@
+class X
+ #comment before accessor
+ attr_accessor :a #comment after accessor
+
+ def blub
+ @a
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_3.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_3.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_3.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1 @@
+cursorPosition=42
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_3.test_result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_3.test_result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_3.test_result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,10 @@
+class X
+
+ #before accessor
+ #after accessor
+ def a
+ @a
+ end
+ public :a
+
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_3.test_source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_3.test_source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_3.test_source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,4 @@
+class X
+ #before accessor
+ attr_reader :a #after accessor
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_4.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_4.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_4.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1 @@
+cursorPosition=88
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_4.test_result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_4.test_result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_4.test_result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,17 @@
+class X
+
+ #before reader
+ #after reader
+ def a
+ @a
+ end
+ public :a
+
+ #before writer
+ #after writer
+ def a= a
+ @a = a
+ end
+ public :a=
+
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_4.test_source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_4.test_source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_4.test_source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,6 @@
+class X
+ #before reader
+ attr_reader :a #after reader
+ #before writer
+ attr_writer :a #after writer
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_5.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_5.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_5.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,4 @@
+cursorPosition=40
+readerVisibility=public
+enableReaderGeneration=true
+
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_5.test_result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_5.test_result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_5.test_result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,15 @@
+class X
+
+ def a
+ @a
+ end
+ public :a
+
+ #before writer
+ #after writer
+ def a= a
+ @a = a
+ end
+ public :a=
+
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_5.test_source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_5.test_source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/encapsulatefield/encapsulate_field_test_comment_5.test_source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,4 @@
+class X
+ #before writer
+ attr_writer :a #after writer
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractconstant/extract_constant_test_comment_1.result.rb
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractconstant/extract_constant_test_comment_1.result.rb (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractconstant/extract_constant_test_comment_1.result.rb 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,3 @@
+Name = "Mirko"
+#before statement
+puts "Hello " + Name #behind statement
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractconstant/extract_constant_test_comment_1.source.rb
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractconstant/extract_constant_test_comment_1.source.rb (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractconstant/extract_constant_test_comment_1.source.rb 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,2 @@
+#before statement
+puts "Hello " + "Mirko" #behind statement
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractconstant/extract_constant_test_comment_1.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractconstant/extract_constant_test_comment_1.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractconstant/extract_constant_test_comment_1.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,3 @@
+start=36
+end=38
+name=Name
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractmethod/extract_method_test_comment_1.result.rb
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractmethod/extract_method_test_comment_1.result.rb (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractmethod/extract_method_test_comment_1.result.rb 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,19 @@
+class Test
+ def methode
+ one, two, three, four, five = 1..5
+
+ extr(one, two)
+ puts three
+ puts four
+ puts five
+ end
+
+ def extr one, two
+ #before one
+ puts one #after one
+ #before two
+ puts two #after two
+ end
+ private :extr
+
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractmethod/extract_method_test_comment_1.source.rb
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractmethod/extract_method_test_comment_1.source.rb (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractmethod/extract_method_test_comment_1.source.rb 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,13 @@
+class Test
+ def methode
+ one, two, three, four, five = 1..5
+
+ #before one
+ puts one #after one
+ #before two
+ puts two #after two
+ puts three
+ puts four
+ puts five
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractmethod/extract_method_test_comment_1.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractmethod/extract_method_test_comment_1.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/extractmethod/extract_method_test_comment_1.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,8 @@
+start=89
+end=137
+name=extr
+visibility=private
+# the next two properties are optional
+#order=
+# the names are changed after the items are re-arranged
+names=one, two
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_comment_1.activeFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_comment_1.activeFile.rb.result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_comment_1.activeFile.rb.result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,43 @@
+
+
+class Target
+ #before constructor
+ def source_initialize #after signature
+ @seven = 7
+ #before end
+ end #after end
+
+ def initialize
+ source_initialize
+ @source = self
+ end
+
+ def foo
+ @six = 6
+ p @six
+ end
+
+ def bar
+ @source.foo1
+ end
+ #before bar
+ def bar1 #behind bar name
+ @six1 = @seven
+ p @six1
+ end
+ def foo1
+ @six1 = 6
+ end
+
+end
+
+class InvalidTarget
+
+ def initialize
+ @var = 5
+ end
+
+ def foo
+ p @var
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_comment_1.activeFile.rb.source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_comment_1.activeFile.rb.source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_comment_1.activeFile.rb.source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,47 @@
+#before source
+class Source #behind name
+
+ #before constructor
+ def initialize #after signature
+ @seven = 7
+ #before end
+ end #after end
+
+ #before bar
+ def bar #behind bar name
+ @six = @seven
+ p @six
+ end
+
+ def foo
+ @six = 6
+ end
+ #before end
+end #at end
+
+class Target
+ def initialize
+ @source = Source.new
+ end
+
+ def foo
+ @six = 6
+ p @six
+ end
+
+ def bar
+ @source.foo
+ end
+
+end
+
+class InvalidTarget
+
+ def initialize
+ @var = 5
+ end
+
+ def foo
+ p @var
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_comment_1.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_comment_1.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlineclass/inline_class_test_comment_1.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,5 @@
+activeFile=activeFile.rb
+requiredFiles=
+caretPosition=72
+targetClassFile=activeFile.rb
+targetClassPos=357
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinelocal/inline_temp_test_comment_1.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinelocal/inline_temp_test_comment_1.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinelocal/inline_temp_test_comment_1.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,3 @@
+caretPosition=51
+replaceWithQuery=false
+newMethodName=
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinelocal/inline_temp_test_comment_1.test_result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinelocal/inline_temp_test_comment_1.test_result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinelocal/inline_temp_test_comment_1.test_result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,5 @@
+class Test
+ def foo param
+ p param
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinelocal/inline_temp_test_comment_1.test_source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinelocal/inline_temp_test_comment_1.test_source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinelocal/inline_temp_test_comment_1.test_source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,7 @@
+class Test
+ def foo param
+ #comment before temp
+ temp = param #comment after temp
+ p temp
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinemethod/inline_method_test_comment_1.result.rb
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinemethod/inline_method_test_comment_1.result.rb (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinemethod/inline_method_test_comment_1.result.rb 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,13 @@
+class X
+ def say_hello to
+ #before hello
+ puts "hello #{to}!" #after hello
+ end
+
+ def mirko
+ @x = X.new
+ name = "mirko"
+ #before hello
+ puts "hello #{name}!" #after hello
+ end
+end
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinemethod/inline_method_test_comment_1.source.rb
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinemethod/inline_method_test_comment_1.source.rb (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinemethod/inline_method_test_comment_1.source.rb 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,12 @@
+class X
+ def say_hello to
+ #before hello
+ puts "hello #{to}!" #after hello
+ end
+
+ def mirko
+ @x = X.new
+ name = "mirko"
+ @x.say_hello name
+ end
+end
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinemethod/inline_method_test_comment_1.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinemethod/inline_method_test_comment_1.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/inlinemethod/inline_method_test_comment_1.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1 @@
+pos=147
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergeclasspartsinfile/merge_class_parts_in_file_test_comment_1.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergeclasspartsinfile/merge_class_parts_in_file_test_comment_1.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergeclasspartsinfile/merge_class_parts_in_file_test_comment_1.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,3 @@
+selectedClass=Count
+selectedPart=1
+checkedParts=1,2,3
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergeclasspartsinfile/merge_class_parts_in_file_test_comment_1.test_result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergeclasspartsinfile/merge_class_parts_in_file_test_comment_1.test_result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergeclasspartsinfile/merge_class_parts_in_file_test_comment_1.test_result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,15 @@
+class Count
+ def initialize
+ @i = 0;
+ end
+
+ def increment
+ @i = @i + 1
+ end
+
+ #comment method
+ def decrement
+ @i = @i - 1
+ end
+
+end
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergeclasspartsinfile/merge_class_parts_in_file_test_comment_1.test_source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergeclasspartsinfile/merge_class_parts_in_file_test_comment_1.test_source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergeclasspartsinfile/merge_class_parts_in_file_test_comment_1.test_source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,19 @@
+class Count
+ def initialize
+ @i = 0;
+ end
+end
+
+class Count
+ def increment
+ @i = @i + 1
+ end
+end
+
+#comment class
+class Count
+ #comment method
+ def decrement
+ @i = @i - 1
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.activeFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.activeFile.rb.result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.activeFile.rb.result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,16 @@
+require "includedFile.rb"
+
+
+class Tree
+ def initialize
+ @leafs = 100
+
+ end
+ def fade
+ @leafs = @leafs -1
+ end
+
+ def blossom
+ @leafs = @leafs + 1
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.activeFile.rb.source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.activeFile.rb.source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.activeFile.rb.source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,23 @@
+require "includedFile.rb"
+
+#comment class
+class Foo
+ #comment method
+ def bar z
+ @i = z
+ end
+end
+
+class Tree
+ def initialize
+ @leafs = 100
+
+ end
+ def fade
+ @leafs = @leafs -1
+ end
+
+ def blossom
+ @leafs = @leafs + 1
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.includedFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.includedFile.rb.result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.includedFile.rb.result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,15 @@
+class Foo
+ def initialize
+ @i = 1
+ end
+
+ def i
+ @i
+ end
+
+ #comment method
+ def bar z
+ @i = z
+ end
+
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.includedFile.rb.source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.includedFile.rb.source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.includedFile.rb.source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,9 @@
+class Foo
+ def initialize
+ @i = 1
+ end
+
+ def i
+ @i
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/mergewithexternalclassparts/merge_with_external_class_parts_comment_1.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,5 @@
+activeFile=activeFile.rb
+targetClass=Foo
+sourceClassPartNumber=1
+destinationFiles=includedFile.rb
+destinationPartNumbers=1
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.activeFile.rb.result.rb
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.activeFile.rb.result.rb (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.activeFile.rb.result.rb 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,43 @@
+require 'includedFile'
+
+class TestKlasse
+
+ def initialize
+ @field = ATargetClass.new
+ end
+
+
+ def five_plus arg
+ 5 + arg
+ end
+
+ def calculate
+ #comment before assignment
+ @field.var = five_plus 1 #comment after assignment
+ end
+
+ def use_var
+ #before use var
+ @field.var = @field.var + "." #after use var
+ end
+
+ #comment before reader
+ #comment after reader
+ def var
+ @field.var
+ end
+ public :var
+
+ #comment before writer
+ #comment after writer
+ def var= var
+ @field.var = var
+ end
+ public :var=
+
+end
+
+t = TestKlasse.new
+t.calculate
+#comment before usage
+puts t.var #comment after usage
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.activeFile.rb.source.rb
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.activeFile.rb.source.rb (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.activeFile.rb.source.rb 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,33 @@
+require 'includedFile'
+
+class TestKlasse
+
+ def initialize
+ @field = ATargetClass.new
+ end
+
+ #comment before writer
+ attr_writer :var #comment after writer
+ #comment before reader
+ attr_reader :var #comment after reader
+
+ def five_plus arg
+ 5 + arg
+ end
+
+ def calculate
+ #comment before assignment
+ @var = five_plus 1 #comment after assignment
+ end
+
+ def use_var
+ #before use var
+ @var += "." #after use var
+ end
+
+end
+
+t = TestKlasse.new
+t.calculate
+#comment before usage
+puts t.var #comment after usage
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.includedFile.rb.result.rb
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.includedFile.rb.result.rb (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.includedFile.rb.result.rb 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,8 @@
+class ATargetClass
+
+ attr_accessor :var
+
+ def test
+ "test"
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.includedFile.rb.source.rb
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.includedFile.rb.source.rb (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.includedFile.rb.source.rb 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,5 @@
+class ATargetClass
+ def test
+ "test"
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movefield/move_field_test_comment_1.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,5 @@
+activeFile=activeFile.rb
+destinationFiles=includedFile.rb
+caretPosition=139
+selectedClass=ATargetClass
+selectedReference=@field
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.activeFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.activeFile.rb.result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.activeFile.rb.result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,14 @@
+require 'includedFile.rb'
+
+class A
+ #before method definition
+ def moveMethod a #after signature
+ @x.moveMethod(a, self)
+ #before end of method
+ end #after method definition
+ private :moveMethod
+ def method
+ @x
+ moveMethod a
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.activeFile.rb.source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.activeFile.rb.source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.activeFile.rb.source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,17 @@
+require 'includedFile.rb'
+
+class A
+ #before method definition
+ def moveMethod a #after signature
+ #before call in method
+ method #after call in method
+ #before statement in method
+ puts 5 #after statement in method
+ #before end of method
+ end #after method definition
+ private :moveMethod
+ def method
+ @x
+ moveMethod a
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.includedFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.includedFile.rb.result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.includedFile.rb.result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,13 @@
+class B
+
+ #before method definition
+ def moveMethod a, a1 #after signature
+ #before call in method
+ a1.method #after call in method
+ #before statement in method
+ puts 5 #after statement in method
+ #before end of method
+ end #after method definition
+
+ #before end in target class
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.includedFile.rb.source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.includedFile.rb.source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.includedFile.rb.source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,3 @@
+class B
+#before end in target class
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/movemethod/move_method_test_comment_1.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,9 @@
+activeFile=activeFile.rb
+destinationFiles=includedFile.rb
+caretPosition=62
+selectedClass=B
+# true false value
+leaveDelegateMethod=true
+# Optional value
+selectedField=@x
+
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/pushdown/push_down_test_comment_1.test_properties
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/pushdown/push_down_test_comment_1.test_properties (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/pushdown/push_down_test_comment_1.test_properties 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,3 @@
+#Format: ClassName[, MethodName]
+selection0=X, method
+selection1=Y, method
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/pushdown/push_down_test_comment_1.test_result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/pushdown/push_down_test_comment_1.test_result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/pushdown/push_down_test_comment_1.test_result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,31 @@
+class A < X
+
+ #before method a
+ def method a #after sig a
+ a #after a
+ #before end
+ end #at end
+
+end
+class B < X
+
+ #before method a
+ def method a #after sig a
+ a #after a
+ #before end
+ end #at end
+
+end
+class C < Y
+
+ #before method a,b
+ def method a, b #after sig b
+ a #after a
+ #before end
+ end #at end
+
+end
+class X
+end
+class Y
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/pushdown/push_down_test_comment_1.test_source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/pushdown/push_down_test_comment_1.test_source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/pushdown/push_down_test_comment_1.test_source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,20 @@
+class A < X
+end
+class B < X
+end
+class C < Y
+end
+class X
+ #before method a
+ def method a #after sig a
+ a #after a
+ #before end
+ end #at end
+end
+class Y
+ #before method a,b
+ def method a, b #after sig b
+ a #after a
+ #before end
+ end #at end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.activeFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.activeFile.rb.result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.activeFile.rb.result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,12 @@
+#before class Test
+class NewName #after Test name
+ def methode
+ end
+end
+
+#before subclass
+class Subclass < NewName #after subclassing Test
+end
+
+#before usage
+t = NewName.new #after usage
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.activeFile.rb.source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.activeFile.rb.source (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.activeFile.rb.source 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,12 @@
+#before class Test
+class Test #after Test name
+ def methode
+ end
+end
+
+#before subclass
+class Subclass < Test #after subclassing Test
+end
+
+#before usage
+t = Test.new #after usage
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.dependantFile.rb.result
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.dependantFile.rb.result (rev 0)
+++ trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.dependantFile.rb.result 2007-05-24 08:28:12 UTC (rev 2536)
@@ -0,0 +1,7 @@
+require 'activeFile.rb'
+
+#before Test extension
+class NewName #after Test
+ def methode
+ end
+end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.refactoring.tests/resources/core/renameclass/rename_class_test_comment_1.dependantFile.rb.source
===================================================================
--- trunk/org.rubypeople.rdt.refactoring.t...
[truncated message content] |
|
From: <caw...@us...> - 2007-05-23 20:52:20
|
Revision: 2535
http://svn.sourceforge.net/rubyeclipse/?rev=2535&view=rev
Author: cawilliams
Date: 2007-05-23 13:52:16 -0700 (Wed, 23 May 2007)
Log Message:
-----------
Modified Paths:
--------------
trunk/org.rubypeople.rdt.debug.core/META-INF/MANIFEST.MF
trunk/org.rubypeople.rdt.debug.core/plugin.xml
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyDebuggerProxy.java
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyExceptionBreakpoint.java
trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_DebuggerLaunch.java
trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/DebugModelPresentation.java
trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/actions/ManageBreakpointRulerAction.java
Modified: trunk/org.rubypeople.rdt.debug.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/META-INF/MANIFEST.MF 2007-05-23 20:51:45 UTC (rev 2534)
+++ trunk/org.rubypeople.rdt.debug.core/META-INF/MANIFEST.MF 2007-05-23 20:52:16 UTC (rev 2535)
@@ -7,7 +7,8 @@
Bundle-Activator: org.rubypeople.rdt.internal.debug.core.RdtDebugCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
-Export-Package: org.rubypeople.rdt.internal.debug.core,
+Export-Package: org.rubypeople.rdt.debug.core,
+ org.rubypeople.rdt.internal.debug.core,
org.rubypeople.rdt.internal.debug.core.commands,
org.rubypeople.rdt.internal.debug.core.model,
org.rubypeople.rdt.internal.debug.core.parsing
Modified: trunk/org.rubypeople.rdt.debug.core/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/plugin.xml 2007-05-23 20:51:45 UTC (rev 2534)
+++ trunk/org.rubypeople.rdt.debug.core/plugin.xml 2007-05-23 20:52:16 UTC (rev 2535)
@@ -16,7 +16,7 @@
point="org.eclipse.debug.core.breakpoints">
<breakpoint
markerType="RubyBreakpointMarker"
- class="org.rubypeople.rdt.internal.debug.core.RubyLineBreakpoint"
+ class="org.rubypeople.rdt.debug.core.RubyLineBreakpoint"
id="RubyLineBreakpoint">
</breakpoint>
</extension>
Modified: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyDebuggerProxy.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyDebuggerProxy.java 2007-05-23 20:51:45 UTC (rev 2534)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyDebuggerProxy.java 2007-05-23 20:52:16 UTC (rev 2535)
@@ -7,6 +7,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IBreakpoint;
+import org.rubypeople.rdt.debug.core.RubyLineBreakpoint;
import org.rubypeople.rdt.internal.debug.core.commands.AbstractDebuggerConnection;
import org.rubypeople.rdt.internal.debug.core.commands.BreakpointCommand;
import org.rubypeople.rdt.internal.debug.core.commands.ClassicDebuggerConnection;
Modified: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyExceptionBreakpoint.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyExceptionBreakpoint.java 2007-05-23 20:51:45 UTC (rev 2534)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyExceptionBreakpoint.java 2007-05-23 20:52:16 UTC (rev 2535)
@@ -17,6 +17,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.Breakpoint;
+import org.rubypeople.rdt.debug.core.RubyLineBreakpoint;
public class RubyExceptionBreakpoint extends Breakpoint {
Modified: trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_DebuggerLaunch.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_DebuggerLaunch.java 2007-05-23 20:51:45 UTC (rev 2534)
+++ trunk/org.rubypeople.rdt.debug.core.tests/src/org/rubypeople/rdt/debug/core/tests/FTC_DebuggerLaunch.java 2007-05-23 20:52:16 UTC (rev 2535)
@@ -15,7 +15,7 @@
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.model.IProcess;
import org.rubypeople.eclipse.testutils.ResourceTools;
-import org.rubypeople.rdt.internal.debug.core.RubyLineBreakpoint;
+import org.rubypeople.rdt.debug.core.RubyLineBreakpoint;
import org.rubypeople.rdt.internal.launching.RubyLaunchConfigurationAttribute;
import org.rubypeople.rdt.launching.IRubyLaunchConfigurationConstants;
import org.rubypeople.rdt.launching.IVMInstallType;
Modified: trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/DebugModelPresentation.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/DebugModelPresentation.java 2007-05-23 20:51:45 UTC (rev 2534)
+++ trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/DebugModelPresentation.java 2007-05-23 20:52:16 UTC (rev 2535)
@@ -16,8 +16,8 @@
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IEditorInput;
+import org.rubypeople.rdt.debug.core.RubyLineBreakpoint;
import org.rubypeople.rdt.internal.debug.core.RubyExceptionBreakpoint;
-import org.rubypeople.rdt.internal.debug.core.RubyLineBreakpoint;
import org.rubypeople.rdt.internal.debug.core.model.RubyThread;
import org.rubypeople.rdt.internal.debug.core.model.RubyValue;
import org.rubypeople.rdt.internal.debug.core.model.RubyVariable;
Modified: trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/actions/ManageBreakpointRulerAction.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/actions/ManageBreakpointRulerAction.java 2007-05-23 20:51:45 UTC (rev 2534)
+++ trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/actions/ManageBreakpointRulerAction.java 2007-05-23 20:52:16 UTC (rev 2535)
@@ -28,7 +28,7 @@
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.IUpdate;
-import org.rubypeople.rdt.internal.debug.core.RubyLineBreakpoint;
+import org.rubypeople.rdt.debug.core.RubyLineBreakpoint;
/**
*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-23 20:51:46
|
Revision: 2534
http://svn.sourceforge.net/rubyeclipse/?rev=2534&view=rev
Author: cawilliams
Date: 2007-05-23 13:51:45 -0700 (Wed, 23 May 2007)
Log Message:
-----------
Added Paths:
-----------
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/debug/
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/debug/core/
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/debug/core/RubyLineBreakpoint.java
Removed Paths:
-------------
trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyLineBreakpoint.java
Copied: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/debug/core/RubyLineBreakpoint.java (from rev 2395, trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyLineBreakpoint.java)
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/debug/core/RubyLineBreakpoint.java (rev 0)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/debug/core/RubyLineBreakpoint.java 2007-05-23 20:51:45 UTC (rev 2534)
@@ -0,0 +1,71 @@
+package org.rubypeople.rdt.debug.core;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.LineBreakpoint;
+
+public class RubyLineBreakpoint extends LineBreakpoint {
+ public static final String RUBY_BREAKPOINT_MARKER = "org.rubypeople.rdt.debug.core.RubyBreakpointMarker"; //$NON-NLS-1$
+
+ private int index = -1 ; // index of breakpoint on ruby debugger side
+
+ public RubyLineBreakpoint(final IResource resource, final int lineNumber) throws CoreException {
+ IWorkspaceRunnable wr = new IWorkspaceRunnable() {
+ public void run(IProgressMonitor monitor) throws CoreException {
+ setMarker(resource.createMarker(RUBY_BREAKPOINT_MARKER));
+ getMarker().setAttribute(IMarker.LINE_NUMBER, lineNumber + 1);
+ getMarker().setAttribute(REGISTERED, false);
+ // setEnabled must be set before calling setRegistered
+ setEnabled(true);
+ setRegistered(true);
+ }
+ };
+ try {
+ ResourcesPlugin.getWorkspace().run(wr, null);
+ } catch (CoreException e) {
+ throw new DebugException(e.getStatus());
+ }
+
+ }
+
+ public String getFileName() throws CoreException {
+ return ensureMarker().getResource().getName();
+ }
+
+ public int getLineNumber() throws CoreException {
+ return ensureMarker().getAttribute(IMarker.LINE_NUMBER, -1);
+ }
+
+ public int getCharStart() throws CoreException {
+ return ensureMarker().getAttribute(IMarker.CHAR_START, -1);
+ }
+
+ public int getCharEnd() throws CoreException {
+ return ensureMarker().getAttribute(IMarker.CHAR_END, -1);
+ }
+
+ /**
+ * Returns the type of marker associated with this type of breakpoints
+ */
+ public static String getMarkerType() {
+ return RUBY_BREAKPOINT_MARKER;
+ }
+
+ public String getModelIdentifier() {
+ return "org.rubypeople.rdt.debug";
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public void setIndex(int index) {
+ this.index = index;
+ }
+
+}
Property changes on: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/debug/core/RubyLineBreakpoint.java
___________________________________________________________________
Name: svn:eol-style
+ native
Deleted: trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyLineBreakpoint.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyLineBreakpoint.java 2007-05-23 20:09:32 UTC (rev 2533)
+++ trunk/org.rubypeople.rdt.debug.core/src/org/rubypeople/rdt/internal/debug/core/RubyLineBreakpoint.java 2007-05-23 20:51:45 UTC (rev 2534)
@@ -1,71 +0,0 @@
-package org.rubypeople.rdt.internal.debug.core;
-
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRunnable;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.debug.core.DebugException;
-import org.eclipse.debug.core.model.LineBreakpoint;
-
-public class RubyLineBreakpoint extends LineBreakpoint {
- protected static final String RUBY_BREAKPOINT_MARKER = "org.rubypeople.rdt.debug.core.RubyBreakpointMarker"; //$NON-NLS-1$
-
- private int index = -1 ; // index of breakpoint on ruby debugger side
-
- public RubyLineBreakpoint(final IResource resource, final int lineNumber) throws CoreException {
- IWorkspaceRunnable wr = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- setMarker(resource.createMarker(RUBY_BREAKPOINT_MARKER));
- getMarker().setAttribute(IMarker.LINE_NUMBER, lineNumber + 1);
- getMarker().setAttribute(REGISTERED, false);
- // setEnabled must be set before calling setRegistered
- setEnabled(true);
- setRegistered(true);
- }
- };
- try {
- ResourcesPlugin.getWorkspace().run(wr, null);
- } catch (CoreException e) {
- throw new DebugException(e.getStatus());
- }
-
- }
-
- public String getFileName() throws CoreException {
- return ensureMarker().getResource().getName();
- }
-
- public int getLineNumber() throws CoreException {
- return ensureMarker().getAttribute(IMarker.LINE_NUMBER, -1);
- }
-
- public int getCharStart() throws CoreException {
- return ensureMarker().getAttribute(IMarker.CHAR_START, -1);
- }
-
- public int getCharEnd() throws CoreException {
- return ensureMarker().getAttribute(IMarker.CHAR_END, -1);
- }
-
- /**
- * Returns the type of marker associated with this type of breakpoints
- */
- public static String getMarkerType() {
- return RUBY_BREAKPOINT_MARKER;
- }
-
- public String getModelIdentifier() {
- return "org.rubypeople.rdt.debug";
- }
-
- public int getIndex() {
- return index;
- }
-
- public void setIndex(int index) {
- this.index = index;
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-23 20:09:33
|
Revision: 2533
http://svn.sourceforge.net/rubyeclipse/?rev=2533&view=rev
Author: cawilliams
Date: 2007-05-23 13:09:32 -0700 (Wed, 23 May 2007)
Log Message:
-----------
Removed Paths:
-------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/symbols/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-23 20:07:56
|
Revision: 2532
http://svn.sourceforge.net/rubyeclipse/?rev=2532&view=rev
Author: cawilliams
Date: 2007-05-23 13:07:55 -0700 (Wed, 23 May 2007)
Log Message:
-----------
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MethodLocator.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MethodLocator.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MethodLocator.java 2007-05-23 19:57:18 UTC (rev 2531)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MethodLocator.java 2007-05-23 20:07:55 UTC (rev 2532)
@@ -59,15 +59,13 @@
@Override
public Instruction visitFCallNode(FCallNode iVisited) {
- Node args = iVisited.getArgsNode(); // FIXME Grab the actual argument count
- match(iVisited, 0);
+ match(iVisited, getArgumentsFromFunctionCall(iVisited).size());
return super.visitFCallNode(iVisited);
}
@Override
public Instruction visitCallNode(CallNode iVisited) {
- Node args = iVisited.getArgsNode();
- match(iVisited, 0); // FIXME Grab the actual arg count
+ match(iVisited, getArgumentsFromFunctionCall(iVisited).size());
return super.visitCallNode(iVisited);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-23 19:57:19
|
Revision: 2531
http://svn.sourceforge.net/rubyeclipse/?rev=2531&view=rev
Author: cawilliams
Date: 2007-05-23 12:57:18 -0700 (Wed, 23 May 2007)
Log Message:
-----------
more search cleanup/new functionality added (specifically grabing arguments from block method calls, and indexing/finding method references)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/MethodReferenceMatch.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceElementParser.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/FieldLocator.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MatchLocator.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MethodLocator.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/MethodReferenceMatch.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/MethodReferenceMatch.java 2007-05-23 19:01:17 UTC (rev 2530)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/MethodReferenceMatch.java 2007-05-23 19:57:18 UTC (rev 2531)
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.rubypeople.rdt.core.search;
+import java.util.List;
+
import org.eclipse.core.resources.IResource;
import org.rubypeople.rdt.core.IRubyElement;
@@ -25,6 +27,7 @@
public class MethodReferenceMatch extends SearchMatch {
private boolean constructor;
private IRubyElement binding;
+ private List<String> arguments;
/**
* Creates a new method reference match.
@@ -58,8 +61,9 @@
* @param resource the resource of the element
* @since 1.0
*/
- public MethodReferenceMatch(IRubyElement enclosingElement, IRubyElement binding, int accuracy, int offset, int length, boolean constructor, boolean insideDocComment, SearchParticipant participant, IResource resource) {
+ public MethodReferenceMatch(IRubyElement enclosingElement, IRubyElement binding, List<String> args, int accuracy, int offset, int length, boolean constructor, boolean insideDocComment, SearchParticipant participant, IResource resource) {
this(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource);
+ this.arguments = args;
this.constructor = constructor;
this.binding = binding;
}
@@ -77,5 +81,9 @@
public IRubyElement getBinding() {
return this.binding;
}
+
+ public List<String> getArguments() {
+ return this.arguments;
+ }
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceElementParser.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceElementParser.java 2007-05-23 19:01:17 UTC (rev 2530)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceElementParser.java 2007-05-23 19:57:18 UTC (rev 2531)
@@ -50,8 +50,10 @@
import org.jruby.ast.InstAsgnNode;
import org.jruby.ast.InstVarNode;
import org.jruby.ast.IterNode;
+import org.jruby.ast.ListNode;
import org.jruby.ast.LocalAsgnNode;
import org.jruby.ast.ModuleNode;
+import org.jruby.ast.MultipleAsgnNode;
import org.jruby.ast.Node;
import org.jruby.ast.RootNode;
import org.jruby.ast.SClassNode;
@@ -370,31 +372,29 @@
public Instruction visitFCallNode(FCallNode iVisited) {
String name = iVisited.getName();
+ List<String> arguments = getArgumentsFromFunctionCall(iVisited);
if (name.equals(REQUIRE) || name.equals(LOAD)) {
addImport(iVisited);
} else if (name.equals(INCLUDE)) { // Collect included mixins
includeModule(iVisited);
} if (name.equals(PUBLIC)) {
- List<String> arguments = getArgumentsFromFunctionCall(iVisited);
for (String methodName : arguments) {
requestor.acceptMethodVisibilityChange(methodName, convertVisibility(Visibility.PUBLIC));
}
} else if (name.equals(PRIVATE)) {
- List<String> arguments = getArgumentsFromFunctionCall(iVisited);
for (String methodName : arguments) {
requestor.acceptMethodVisibilityChange(methodName, convertVisibility(Visibility.PRIVATE));
}
} else if (name.equals(PROTECTED)) {
- List<String> arguments = getArgumentsFromFunctionCall(iVisited);
for (String methodName : arguments) {
requestor.acceptMethodVisibilityChange(methodName, convertVisibility(Visibility.PROTECTED));
}
- } else if (name.equals(MODULE_FUNCTION)) {
- List<String> arguments = getArgumentsFromFunctionCall(iVisited);
+ } else if (name.equals(MODULE_FUNCTION)) {
for (String methodName : arguments) {
requestor.acceptModuleFunction(methodName);
}
}
+ requestor.acceptMethodReference(name, arguments.size(), iVisited.getPosition().getStartOffset());
return super.visitFCallNode(iVisited);
}
@@ -455,8 +455,6 @@
}
public Instruction visitVCallNode(VCallNode iVisited) {
- // XXX If the call has arguments, we need to find the method matching the
- // symbols and mark their visibility differently
String functionName = iVisited.getName();
if (functionName.equals(PUBLIC)) {
currentVisibility = Visibility.PUBLIC;
@@ -467,53 +465,34 @@
} else if (functionName.equals(MODULE_FUNCTION)) {
inModuleFunction = true;
}
+ requestor.acceptMethodReference(functionName, 0, iVisited.getPosition().getStartOffset());
return super.visitVCallNode(iVisited);
}
@Override
public Instruction visitCallNode(CallNode iVisited) {
String name = iVisited.getName();
+ List<String> arguments = getArgumentsFromFunctionCall(iVisited);
if (name.equals(PUBLIC)) {
- List<String> arguments = getArgumentsFromFunctionCall(iVisited);
for (String methodName : arguments) {
requestor.acceptMethodVisibilityChange(methodName, convertVisibility(Visibility.PUBLIC));
}
} else if (name.equals(PRIVATE)) {
- List<String> arguments = getArgumentsFromFunctionCall(iVisited);
for (String methodName : arguments) {
requestor.acceptMethodVisibilityChange(methodName, convertVisibility(Visibility.PRIVATE));
}
} else if (name.equals(PROTECTED)) {
- List<String> arguments = getArgumentsFromFunctionCall(iVisited);
for (String methodName : arguments) {
requestor.acceptMethodVisibilityChange(methodName, convertVisibility(Visibility.PROTECTED));
}
} else if (name.equals(MODULE_FUNCTION)) {
- List<String> arguments = getArgumentsFromFunctionCall(iVisited);
for (String methodName : arguments) {
requestor.acceptModuleFunction(methodName);
}
}
+ requestor.acceptMethodReference(name, arguments.size(), iVisited.getPosition().getStartOffset());
return super.visitCallNode(iVisited);
}
-
- private List<String> getArgumentsFromFunctionCall(IArgumentNode iVisited) {
- List<String> arguments = new ArrayList<String>();
- Node argsNode = iVisited.getArgsNode();
- Iterator iter = null;
- if (argsNode instanceof SplatNode) {
- SplatNode splat = (SplatNode) argsNode;
- iter = splat.childNodes().iterator();
- } else if (argsNode instanceof ArrayNode) {
- ArrayNode arrayNode = (ArrayNode) iVisited.getArgsNode();
- iter = arrayNode.childNodes().iterator();
- }
- for (; iter.hasNext();) {
- Node mixinNameNode = (Node) iter.next();
- arguments.add(ASTUtil.getNameReflectively(mixinNameNode));
- }
- return arguments;
- }
public Instruction visitAliasNode(AliasNode iVisited) {
String name = iVisited.getNewName();
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java 2007-05-23 19:01:17 UTC (rev 2530)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java 2007-05-23 19:57:18 UTC (rev 2531)
@@ -24,7 +24,9 @@
*/
package org.rubypeople.rdt.internal.core.parser;
+import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import org.jruby.ast.AliasNode;
import org.jruby.ast.AndNode;
@@ -71,10 +73,12 @@
import org.jruby.ast.GlobalAsgnNode;
import org.jruby.ast.GlobalVarNode;
import org.jruby.ast.HashNode;
+import org.jruby.ast.IArgumentNode;
import org.jruby.ast.IfNode;
import org.jruby.ast.InstAsgnNode;
import org.jruby.ast.InstVarNode;
import org.jruby.ast.IterNode;
+import org.jruby.ast.ListNode;
import org.jruby.ast.LocalAsgnNode;
import org.jruby.ast.LocalVarNode;
import org.jruby.ast.Match2Node;
@@ -123,6 +127,7 @@
import org.jruby.ast.ZSuperNode;
import org.jruby.ast.visitor.AbstractVisitor;
import org.jruby.evaluator.Instruction;
+import org.rubypeople.rdt.internal.core.util.ASTUtil;
/**
* @author Chris
@@ -1190,5 +1195,47 @@
protected Instruction visitNode(Node iVisited) {
return null;
}
+
+ protected List<String> getArgumentsFromFunctionCall(IArgumentNode iVisited) {
+ List<String> arguments = new ArrayList<String>();
+ Node argsNode = iVisited.getArgsNode();
+ Iterator iter = null;
+ if (argsNode instanceof SplatNode) {
+ SplatNode splat = (SplatNode) argsNode;
+ iter = splat.childNodes().iterator();
+ } else if (argsNode instanceof ArrayNode) {
+ ArrayNode arrayNode = (ArrayNode) iVisited.getArgsNode();
+ iter = arrayNode.childNodes().iterator();
+ } else if (argsNode == null) {
+ // Block?
+ Node iterNode = null;
+ if (iVisited instanceof FCallNode) {
+ FCallNode fcall = (FCallNode) iVisited;
+ iterNode = fcall.getIterNode();
+ } else if (iVisited instanceof CallNode) {
+ CallNode call = (CallNode) iVisited;
+ iterNode = call.getIterNode();
+ }
+ if (iterNode == null) return arguments;
+ if (iterNode instanceof IterNode) { // yup, it has a block
+ IterNode yeah = (IterNode) iterNode;
+ Node varNode = yeah.getVarNode();
+ if (varNode instanceof DAsgnNode) { // single variable in block
+ DAsgnNode dassgn = (DAsgnNode) varNode;
+ arguments.add(dassgn.getName());
+ } else if (varNode instanceof MultipleAsgnNode) { // multiple variables in block
+ MultipleAsgnNode multi = (MultipleAsgnNode) varNode;
+ ListNode list = multi.getHeadNode();
+ iter = list.iterator();
+ }
+ }
+ }
+ if (iter == null) return arguments;
+ for (; iter.hasNext();) {
+ Node argument = (Node) iter.next();
+ arguments.add(ASTUtil.getNameReflectively(argument));
+ }
+ return arguments;
+ }
}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/FieldLocator.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/FieldLocator.java 2007-05-23 19:01:17 UTC (rev 2530)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/FieldLocator.java 2007-05-23 19:57:18 UTC (rev 2531)
@@ -33,8 +33,11 @@
@Override
public void reportMatches(final RubyScript script, final MatchLocator locator) {
-// reportMatches((IParent) script, locator);
- reportASTMatches(script, locator);
+ if (!this.pattern.findReferences) { // just traverse our own model
+ reportMatches((IParent) script, locator);
+ } else { // they want references too, so we need to traverse the AST
+ reportASTMatches(script, locator);
+ }
}
private void reportASTMatches(final RubyScript script, final MatchLocator locator) {
@@ -43,6 +46,7 @@
if (ast == null) {
ast = new RubyParser().parse(script.getSource());
}
+ final boolean findDeclarations = this.pattern.findDeclarations;
new InOrderVisitor() {
@Override
@@ -51,7 +55,7 @@
return super.visitInstVarNode(iVisited);
}
- // XXX Handle constants!
+ // XXX Handle constant references!
@Override
public Instruction visitGlobalVarNode(GlobalVarNode iVisited) {
@@ -61,13 +65,13 @@
@Override
public Instruction visitConstDeclNode(ConstDeclNode iVisited) {
- match(iVisited);
+ if (findDeclarations) match(iVisited);
return super.visitConstDeclNode(iVisited);
}
@Override
public Instruction visitGlobalAsgnNode(GlobalAsgnNode iVisited) {
- match(iVisited);
+ match(iVisited); // TODO check whether we want to find write references
return super.visitGlobalAsgnNode(iVisited);
}
@@ -79,13 +83,13 @@
@Override
public Instruction visitClassVarAsgnNode(ClassVarAsgnNode iVisited) {
- match(iVisited);
+ match(iVisited); // TODO check whether we want to find write references
return super.visitClassVarAsgnNode(iVisited);
}
@Override
public Instruction visitInstAsgnNode(InstAsgnNode iVisited) {
- match(iVisited);
+ match(iVisited); // TODO check whether we want to find write references
return super.visitInstAsgnNode(iVisited);
}
@@ -154,10 +158,8 @@
private int getAccuracy(String name) {
if (this.pattern.findReferences)
- // must be a write only access with an initializer
- if (this.pattern.writeAccess)
- if (matchesName(this.pattern.name, name.toCharArray()))
- return ACCURATE_MATCH;
+ if (matchesName(this.pattern.name, name.toCharArray()))
+ return ACCURATE_MATCH;
if (this.pattern.findDeclarations) {
if (matchesName(this.pattern.name, name.toCharArray()))
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MatchLocator.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MatchLocator.java 2007-05-23 19:01:17 UTC (rev 2530)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MatchLocator.java 2007-05-23 19:57:18 UTC (rev 2531)
@@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@@ -532,6 +533,7 @@
public SearchMatch newMethodReferenceMatch(
IRubyElement enclosingElement,
IRubyElement binding,
+ List<String> arguments,
int accuracy,
int offset,
int length,
@@ -539,7 +541,7 @@
Node reference) {
SearchParticipant participant = getParticipant();
IResource resource = this.currentPossibleMatch.resource;
- return new MethodReferenceMatch(enclosingElement, binding, accuracy, offset, length, isConstructor, false, participant, resource);
+ return new MethodReferenceMatch(enclosingElement, binding, arguments, accuracy, offset, length, isConstructor, false, participant, resource);
}
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MethodLocator.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MethodLocator.java 2007-05-23 19:01:17 UTC (rev 2530)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MethodLocator.java 2007-05-23 19:57:18 UTC (rev 2531)
@@ -1,13 +1,28 @@
package org.rubypeople.rdt.internal.core.search.matching;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.core.runtime.CoreException;
+import org.jruby.ast.CallNode;
+import org.jruby.ast.DefnNode;
+import org.jruby.ast.DefsNode;
+import org.jruby.ast.FCallNode;
+import org.jruby.ast.IArgumentNode;
+import org.jruby.ast.Node;
+import org.jruby.ast.VCallNode;
+import org.jruby.ast.types.INameNode;
+import org.jruby.evaluator.Instruction;
import org.rubypeople.rdt.core.IMember;
import org.rubypeople.rdt.core.IMethod;
import org.rubypeople.rdt.core.IParent;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.ISourceRange;
+import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.core.RubyScript;
+import org.rubypeople.rdt.internal.core.parser.InOrderVisitor;
+import org.rubypeople.rdt.internal.core.parser.RubyParser;
public class MethodLocator extends PatternLocator {
@@ -20,16 +35,119 @@
@Override
public void reportMatches(RubyScript script, MatchLocator locator) {
- reportMatches((IParent) script, locator);
+ if (!this.pattern.findReferences) {
+ reportMatches((IParent) script, locator);
+ } else {
+ reportASTMatches(script, locator);
+ }
}
+ private void reportASTMatches(final RubyScript script, final MatchLocator locator) {
+ try {
+ Node ast = script.lastGoodAST;
+ if (ast == null) {
+ ast = new RubyParser().parse(script.getSource());
+ }
+ final boolean findDeclarations = this.pattern.findDeclarations;
+ new InOrderVisitor() {
+
+ @Override
+ public Instruction visitVCallNode(VCallNode iVisited) {
+ match(iVisited, 0);
+ return super.visitVCallNode(iVisited);
+ }
+
+ @Override
+ public Instruction visitFCallNode(FCallNode iVisited) {
+ Node args = iVisited.getArgsNode(); // FIXME Grab the actual argument count
+ match(iVisited, 0);
+ return super.visitFCallNode(iVisited);
+ }
+
+ @Override
+ public Instruction visitCallNode(CallNode iVisited) {
+ Node args = iVisited.getArgsNode();
+ match(iVisited, 0); // FIXME Grab the actual arg count
+ return super.visitCallNode(iVisited);
+ }
+
+ @Override
+ public Instruction visitDefnNode(DefnNode iVisited) {
+ if (findDeclarations) matchDeclaration(iVisited, iVisited.getArgsNode().getArgsCount());
+ return super.visitDefnNode(iVisited);
+ }
+
+ @Override
+ public Instruction visitDefsNode(DefsNode iVisited) {
+ if (findDeclarations) matchDeclaration(iVisited, iVisited.getArgsNode().getArgsCount());
+ return super.visitDefsNode(iVisited);
+ }
+
+ private void match(Node iVisited, int arity) {
+ String name = ((INameNode)iVisited).getName();
+ int accuracy = getAccuracy(name, arity);
+ if (accuracy != IMPOSSIBLE_MATCH) {
+ try {
+ IRubyElement element = script.getElementAt(iVisited.getPosition().getStartOffset());
+ if (element == null) element = script;
+ if (locator.encloses(element)) {
+ IRubyElement binding = resolve(element, iVisited);
+ int start = iVisited.getPosition().getStartOffset();
+ int length = iVisited.getPosition().getEndOffset() - start;
+ boolean isConstructor = false;
+ if (name.equals("new")) {
+ isConstructor = true;
+ }
+ List<String> args = new ArrayList<String>();
+ if (iVisited instanceof IArgumentNode) {
+ args = getArgumentsFromFunctionCall((IArgumentNode) iVisited);
+ }
+ locator.report(locator.newMethodReferenceMatch(element, binding, args, accuracy,
+ start, length, isConstructor, iVisited));
+ }
+ } catch (CoreException e) {
+ RubyCore.log(e);
+ }
+ }
+ }
+
+ private IRubyElement resolve(IRubyElement element, Node visited) {
+ // TODO resolve a method call to it's declaration!
+ return element;
+ }
+
+ private void matchDeclaration(Node iVisited, int arity) {
+ String name = ((INameNode)iVisited).getName();
+ int accuracy = getAccuracy(name, arity);
+ if (accuracy != IMPOSSIBLE_MATCH) {
+ try {
+ IRubyElement element = script.getElementAt(iVisited.getPosition().getStartOffset());
+ if (element == null) element = script;
+ if (locator.encloses(element)) {
+ int start = iVisited.getPosition().getStartOffset();
+ int length = iVisited.getPosition().getEndOffset() - start;
+ locator.report(locator.newDeclarationMatch(element, accuracy,
+ start, length));
+ }
+ } catch (CoreException e) {
+ RubyCore.log(e);
+ }
+ }
+ }
+ }.acceptNode(ast);
+ } catch(RubyModelException e) {
+ RubyCore.log(e);
+ }
+ }
+
private void reportMatches(IParent parent, MatchLocator locator) {
try {
IRubyElement[] children = parent.getChildren();
for (int i = 0; i < children.length; i++) {
IRubyElement child = children[i];
- if (child.isType(IRubyElement.METHOD) && locator.encloses(child)) {
- int accuracy = getAccuracy((IMethod) child);
+ if (child.isType(IRubyElement.METHOD) && locator.encloses(child)) {
+ IMethod method = (IMethod) child;
+ int accuracy = getAccuracy(method.getElementName(), method.getParameterNames().length);
if (accuracy != IMPOSSIBLE_MATCH) {
IMember member = (IMember) child;
ISourceRange range = member.getSourceRange();
@@ -52,29 +170,19 @@
}
}
- private int getAccuracy(IMethod method) {
- if (!this.pattern.findDeclarations)
- return IMPOSSIBLE_MATCH;
-
+ private int getAccuracy(String name, int arity) {
// Verify method name
- if (!matchesName(this.pattern.selector, method.getElementName().toCharArray()))
+ if (!matchesName(this.pattern.selector, name.toCharArray()))
return IMPOSSIBLE_MATCH;
// Verify parameter count
if (this.pattern.parameterNames != null) {
int length = this.pattern.parameterNames.length;
- String[] args = null;
- try {
- args = method.getParameterNames();
- } catch (RubyModelException e) {
- // ignore
- }
- int argsLength = args == null ? 0 : args.length;
- if (length != argsLength)
+ if (length != arity)
return IMPOSSIBLE_MATCH;
}
- // Method declaration may match pattern
+ // Method may match pattern
return ACCURATE_MATCH;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-23 19:01:23
|
Revision: 2530
http://svn.sourceforge.net/rubyeclipse/?rev=2530&view=rev
Author: cawilliams
Date: 2007-05-23 12:01:17 -0700 (Wed, 23 May 2007)
Log Message:
-----------
new method to create a method reference match
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MatchLocator.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MatchLocator.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MatchLocator.java 2007-05-23 19:00:51 UTC (rev 2529)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MatchLocator.java 2007-05-23 19:01:17 UTC (rev 2530)
@@ -22,6 +22,7 @@
import org.rubypeople.rdt.core.search.FieldReferenceMatch;
import org.rubypeople.rdt.core.search.IRubySearchScope;
import org.rubypeople.rdt.core.search.MethodDeclarationMatch;
+import org.rubypeople.rdt.core.search.MethodReferenceMatch;
import org.rubypeople.rdt.core.search.SearchDocument;
import org.rubypeople.rdt.core.search.SearchMatch;
import org.rubypeople.rdt.core.search.SearchParticipant;
@@ -527,4 +528,18 @@
return new FieldReferenceMatch(enclosingElement, binding, accuracy, offset, length, isReadAccess, isWriteAccess, false, participant, resource);
}
+
+ public SearchMatch newMethodReferenceMatch(
+ IRubyElement enclosingElement,
+ IRubyElement binding,
+ int accuracy,
+ int offset,
+ int length,
+ boolean isConstructor,
+ Node reference) {
+ SearchParticipant participant = getParticipant();
+ IResource resource = this.currentPossibleMatch.resource;
+ return new MethodReferenceMatch(enclosingElement, binding, accuracy, offset, length, isConstructor, false, participant, resource);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-23 19:00:57
|
Revision: 2529
http://svn.sourceforge.net/rubyeclipse/?rev=2529&view=rev
Author: cawilliams
Date: 2007-05-23 12:00:51 -0700 (Wed, 23 May 2007)
Log Message:
-----------
new method reference match class
Added Paths:
-----------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/MethodReferenceMatch.java
Added: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/MethodReferenceMatch.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/MethodReferenceMatch.java (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/MethodReferenceMatch.java 2007-05-23 19:00:51 UTC (rev 2529)
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.core.search;
+
+import org.eclipse.core.resources.IResource;
+import org.rubypeople.rdt.core.IRubyElement;
+
+/**
+ * A Java search match that represents a method reference.
+ * The element is the inner-most enclosing member that references this method.
+ * <p>
+ * This class is intended to be instantiated and subclassed by clients.
+ * </p>
+ *
+ * @since 3.0
+ */
+public class MethodReferenceMatch extends SearchMatch {
+ private boolean constructor;
+ private IRubyElement binding;
+
+ /**
+ * Creates a new method reference match.
+ *
+ * @param enclosingElement the inner-most enclosing member that references this method
+ * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
+ * @param offset the offset the match starts at, or -1 if unknown
+ * @param length the length of the match, or -1 if unknown
+ * @param insideDocComment <code>true</code> if this search match is inside a doc
+ * comment, and <code>false</code> otherwise
+ * @param participant the search participant that created the match
+ * @param resource the resource of the element
+ */
+ public MethodReferenceMatch(IRubyElement enclosingElement, int accuracy, int offset, int length, boolean insideDocComment, SearchParticipant participant, IResource resource) {
+ super(enclosingElement, accuracy, offset, length, participant, resource);
+ setInsideDocComment(insideDocComment);
+ }
+
+ /**
+ * Creates a new method reference match.
+ *
+ * @param enclosingElement the inner-most enclosing member that references this method
+ * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
+ * @param offset the offset the match starts at, or -1 if unknown
+ * @param length the length of the match, or -1 if unknown
+ * @param constructor <code>true</code> if this search match a constructor
+ * <code>false</code> otherwise
+ * @param insideDocComment <code>true</code> if this search match is inside a doc
+ * comment, and <code>false</code> otherwise
+ * @param participant the search participant that created the match
+ * @param resource the resource of the element
+ * @since 1.0
+ */
+ public MethodReferenceMatch(IRubyElement enclosingElement, IRubyElement binding, int accuracy, int offset, int length, boolean constructor, boolean insideDocComment, SearchParticipant participant, IResource resource) {
+ this(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource);
+ this.constructor = constructor;
+ this.binding = binding;
+ }
+
+ /**
+ * Returns whether the reference is on a constructor.
+ *
+ * @return Returns whether the reference is on a constructor or not.
+ * @since 3.1
+ */
+ public final boolean isConstructor() {
+ return this.constructor;
+ }
+
+ public IRubyElement getBinding() {
+ return this.binding;
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-23 18:01:48
|
Revision: 2528
http://svn.sourceforge.net/rubyeclipse/?rev=2528&view=rev
Author: cawilliams
Date: 2007-05-23 11:01:44 -0700 (Wed, 23 May 2007)
Log Message:
-----------
check if a root is external (not archive) to get path differently than grabbing resource
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/RubySearchScope.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/RubySearchScope.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/RubySearchScope.java 2007-05-23 18:00:45 UTC (rev 2527)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/RubySearchScope.java 2007-05-23 18:01:44 UTC (rev 2528)
@@ -354,7 +354,7 @@
break;
case IRubyElement.SOURCE_FOLDER:
root = (ISourceFolderRoot)element.getParent();
- if (root.isArchive()) {
+ if (root.isExternal()) {
String relativePath = Util.concatWith(((SourceFolder) element).names, '/');
containerPath = root.getPath();
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-23 18:00:46
|
Revision: 2527
http://svn.sourceforge.net/rubyeclipse/?rev=2527&view=rev
Author: cawilliams
Date: 2007-05-23 11:00:45 -0700 (Wed, 23 May 2007)
Log Message:
-----------
make sure element is enclosed by scope before reporting match
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MethodLocator.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MethodLocator.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MethodLocator.java 2007-05-23 16:01:12 UTC (rev 2526)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MethodLocator.java 2007-05-23 18:00:45 UTC (rev 2527)
@@ -28,7 +28,7 @@
IRubyElement[] children = parent.getChildren();
for (int i = 0; i < children.length; i++) {
IRubyElement child = children[i];
- if (child.isType(IRubyElement.METHOD)) {
+ if (child.isType(IRubyElement.METHOD) && locator.encloses(child)) {
int accuracy = getAccuracy((IMethod) child);
if (accuracy != IMPOSSIBLE_MATCH) {
IMember member = (IMember) child;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-23 16:01:17
|
Revision: 2526
http://svn.sourceforge.net/rubyeclipse/?rev=2526&view=rev
Author: cawilliams
Date: 2007-05-23 09:01:12 -0700 (Wed, 23 May 2007)
Log Message:
-----------
implement finding field references (not just declarations)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/FieldReferenceMatch.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/FieldLocator.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MatchLocator.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/FieldReferenceMatch.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/FieldReferenceMatch.java 2007-05-23 16:00:37 UTC (rev 2525)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/FieldReferenceMatch.java 2007-05-23 16:01:12 UTC (rev 2526)
@@ -26,11 +26,13 @@
private boolean isReadAccess;
private boolean isWriteAccess;
+ private IRubyElement binding;
/**
* Creates a new field reference match.
*
* @param enclosingElement the inner-most enclosing member that references this field
+ * @param binding The actual field we are referring to
* @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
* @param offset the offset the match starts at, or -1 if unknown
* @param length the length of the match, or -1 if unknown
@@ -41,9 +43,10 @@
* @param participant the search participant that created the match
* @param resource the resource of the element
*/
- public FieldReferenceMatch(IRubyElement enclosingElement, int accuracy, int offset, int length, boolean isReadAccess, boolean isWriteAccess, boolean insideDocComment, SearchParticipant participant, IResource resource) {
+ public FieldReferenceMatch(IRubyElement enclosingElement, IRubyElement binding, int accuracy, int offset, int length, boolean isReadAccess, boolean isWriteAccess, boolean insideDocComment, SearchParticipant participant, IResource resource) {
super(enclosingElement, accuracy, offset, length, participant, resource);
- this.isReadAccess = isReadAccess;
+ this.binding = binding;
+ this.isReadAccess = isReadAccess;
this.isWriteAccess = isWriteAccess;
setInsideDocComment(insideDocComment);
}
@@ -68,4 +71,8 @@
return this.isWriteAccess;
}
+ public IRubyElement getBinding() {
+ return this.binding;
+ }
+
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/FieldLocator.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/FieldLocator.java 2007-05-23 16:00:37 UTC (rev 2525)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/FieldLocator.java 2007-05-23 16:01:12 UTC (rev 2526)
@@ -1,13 +1,26 @@
package org.rubypeople.rdt.internal.core.search.matching;
import org.eclipse.core.runtime.CoreException;
-import org.rubypeople.rdt.core.IField;
+import org.jruby.ast.ClassVarAsgnNode;
+import org.jruby.ast.ClassVarNode;
+import org.jruby.ast.ConstDeclNode;
+import org.jruby.ast.GlobalAsgnNode;
+import org.jruby.ast.GlobalVarNode;
+import org.jruby.ast.InstAsgnNode;
+import org.jruby.ast.InstVarNode;
+import org.jruby.ast.Node;
+import org.jruby.ast.types.INameNode;
+import org.jruby.evaluator.Instruction;
import org.rubypeople.rdt.core.IMember;
import org.rubypeople.rdt.core.IParent;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.ISourceRange;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.core.RubyScript;
+import org.rubypeople.rdt.internal.core.parser.InOrderVisitor;
+import org.rubypeople.rdt.internal.core.parser.RubyParser;
public class FieldLocator extends PatternLocator {
@@ -19,10 +32,95 @@
}
@Override
- public void reportMatches(RubyScript script, MatchLocator locator) {
- reportMatches((IParent) script, locator);
+ public void reportMatches(final RubyScript script, final MatchLocator locator) {
+// reportMatches((IParent) script, locator);
+ reportASTMatches(script, locator);
}
+ private void reportASTMatches(final RubyScript script, final MatchLocator locator) {
+ try {
+ Node ast = script.lastGoodAST;
+ if (ast == null) {
+ ast = new RubyParser().parse(script.getSource());
+ }
+ new InOrderVisitor() {
+
+ @Override
+ public Instruction visitInstVarNode(InstVarNode iVisited) {
+ match(iVisited);
+ return super.visitInstVarNode(iVisited);
+ }
+
+ // XXX Handle constants!
+
+ @Override
+ public Instruction visitGlobalVarNode(GlobalVarNode iVisited) {
+ match(iVisited);
+ return super.visitGlobalVarNode(iVisited);
+ }
+
+ @Override
+ public Instruction visitConstDeclNode(ConstDeclNode iVisited) {
+ match(iVisited);
+ return super.visitConstDeclNode(iVisited);
+ }
+
+ @Override
+ public Instruction visitGlobalAsgnNode(GlobalAsgnNode iVisited) {
+ match(iVisited);
+ return super.visitGlobalAsgnNode(iVisited);
+ }
+
+ @Override
+ public Instruction visitClassVarNode(ClassVarNode iVisited) {
+ match(iVisited);
+ return super.visitClassVarNode(iVisited);
+ }
+
+ @Override
+ public Instruction visitClassVarAsgnNode(ClassVarAsgnNode iVisited) {
+ match(iVisited);
+ return super.visitClassVarAsgnNode(iVisited);
+ }
+
+ @Override
+ public Instruction visitInstAsgnNode(InstAsgnNode iVisited) {
+ match(iVisited);
+ return super.visitInstAsgnNode(iVisited);
+ }
+
+ private void match(Node iVisited) {
+ int accuracy = getAccuracy(((INameNode)iVisited).getName());
+ if (accuracy != IMPOSSIBLE_MATCH) {
+ try {
+ IRubyElement element = script.getElementAt(iVisited.getPosition().getStartOffset());
+ if (locator.encloses(element)) {
+ IRubyElement binding = resolve(element, ((INameNode)iVisited).getName());
+ locator.report(locator.newFieldReferenceMatch(element, binding, accuracy,
+ iVisited.getPosition().getStartOffset(), iVisited.getPosition().getEndOffset(), iVisited));
+ }
+ } catch (CoreException e) {
+ RubyCore.log(e);
+ }
+ }
+ }
+
+ private IRubyElement resolve(IRubyElement element, String name) {
+ if (element instanceof IMember) {
+ IMember member = (IMember) element;
+ IType type = member.getDeclaringType();
+ return type.getField(name);
+ }
+ return null;
+ }
+
+
+ }.acceptNode(ast);
+ } catch(RubyModelException e) {
+ RubyCore.log(e);
+ }
+ }
+
private void reportMatches(IParent parent, MatchLocator locator) {
try {
IRubyElement[] children = parent.getChildren();
@@ -33,15 +131,14 @@
child.isType(IRubyElement.CONSTANT) ||
child.isType(IRubyElement.CLASS_VAR) ||
child.isType(IRubyElement.INSTANCE_VAR)) {
- int accuracy = getAccuracy((IField) child);
+ int accuracy = getAccuracy(child.getElementName());
if (accuracy != IMPOSSIBLE_MATCH) {
IMember member = (IMember) child;
ISourceRange range = member.getSourceRange();
try {
locator.report(locator.newDeclarationMatch(child, accuracy, range.getOffset(), range.getLength()));
} catch (CoreException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ RubyCore.log(e);
}
}
}
@@ -51,20 +148,19 @@
}
}
} catch (RubyModelException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ RubyCore.log(e);
}
}
- private int getAccuracy(IField field) {
+ private int getAccuracy(String name) {
if (this.pattern.findReferences)
// must be a write only access with an initializer
if (this.pattern.writeAccess)
- if (matchesName(this.pattern.name, field.getElementName().toCharArray()))
+ if (matchesName(this.pattern.name, name.toCharArray()))
return ACCURATE_MATCH;
if (this.pattern.findDeclarations) {
- if (matchesName(this.pattern.name, field.getElementName().toCharArray()))
+ if (matchesName(this.pattern.name, name.toCharArray()))
return ACCURATE_MATCH;
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MatchLocator.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MatchLocator.java 2007-05-23 16:00:37 UTC (rev 2525)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/MatchLocator.java 2007-05-23 16:01:12 UTC (rev 2526)
@@ -10,11 +10,16 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
+import org.jruby.ast.ClassVarAsgnNode;
+import org.jruby.ast.GlobalAsgnNode;
+import org.jruby.ast.InstAsgnNode;
+import org.jruby.ast.Node;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyProject;
import org.rubypeople.rdt.core.IRubyScript;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.core.search.FieldDeclarationMatch;
+import org.rubypeople.rdt.core.search.FieldReferenceMatch;
import org.rubypeople.rdt.core.search.IRubySearchScope;
import org.rubypeople.rdt.core.search.MethodDeclarationMatch;
import org.rubypeople.rdt.core.search.SearchDocument;
@@ -335,6 +340,10 @@
}
}
+ protected boolean encloses(IRubyElement element) {
+ return element != null && this.scope.encloses(element);
+ }
+
protected void report(SearchMatch match) throws CoreException {
long start = -1;
if (BasicSearchEngine.VERBOSE) {
@@ -499,4 +508,23 @@
return new TypeReferenceMatch(enclosingElement, accuracy, offset, length, participant, resource);
}
+ public SearchMatch newFieldReferenceMatch(
+ IRubyElement enclosingElement,
+ IRubyElement binding, int accuracy,
+ int offset,
+ int length,
+ Node reference) {
+ boolean isReadAccess = false;
+ boolean isWriteAccess = false;
+ if ((reference instanceof GlobalAsgnNode) || (reference instanceof ClassVarAsgnNode) ||
+ (reference instanceof InstAsgnNode)) {
+ isWriteAccess = true;
+ } else {
+ isReadAccess = true;
+ }
+ SearchParticipant participant = getParticipant();
+ IResource resource = this.currentPossibleMatch.resource;
+ return new FieldReferenceMatch(enclosingElement, binding, accuracy, offset, length, isReadAccess, isWriteAccess, false, participant, resource);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-23 16:00:44
|
Revision: 2524
http://svn.sourceforge.net/rubyeclipse/?rev=2524&view=rev
Author: cawilliams
Date: 2007-05-23 09:00:24 -0700 (Wed, 23 May 2007)
Log Message:
-----------
make RubyField abstract, force creation of subclasses
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyField.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyType.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyField.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyField.java 2007-05-23 03:02:18 UTC (rev 2523)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyField.java 2007-05-23 16:00:24 UTC (rev 2524)
@@ -32,7 +32,7 @@
* @author Chris
*
*/
-public class RubyField extends NamedMember implements IField {
+public abstract class RubyField extends NamedMember implements IField {
// FIXME Combine the Variables into a single class?
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyType.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyType.java 2007-05-23 03:02:18 UTC (rev 2523)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyType.java 2007-05-23 16:00:24 UTC (rev 2524)
@@ -85,7 +85,16 @@
* @see IType#getField
*/
public IField getField(String fieldName) {
- return new RubyField(this, fieldName);
+ if (fieldName.startsWith("@@"))
+ return new RubyClassVar(this, fieldName);
+ if (fieldName.startsWith("@"))
+ return new RubyInstVar(this, fieldName);
+ if (fieldName.startsWith("$"))
+ return new RubyGlobal(this, fieldName);
+ if (Character.isUpperCase(fieldName.charAt(0)))
+ return new RubyConstant(this, fieldName);
+ Assert.isTrue(false, "Tried to access a field which isn't an instance variable, class variable, global or constant");
+ return null;
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-23 16:00:41
|
Revision: 2525
http://svn.sourceforge.net/rubyeclipse/?rev=2525&view=rev
Author: cawilliams
Date: 2007-05-23 09:00:37 -0700 (Wed, 23 May 2007)
Log Message:
-----------
report field references
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceElementParser.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceElementParser.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceElementParser.java 2007-05-23 16:00:24 UTC (rev 2524)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceElementParser.java 2007-05-23 16:00:37 UTC (rev 2525)
@@ -35,6 +35,7 @@
import org.jruby.ast.CallNode;
import org.jruby.ast.ClassNode;
import org.jruby.ast.ClassVarAsgnNode;
+import org.jruby.ast.ClassVarNode;
import org.jruby.ast.Colon2Node;
import org.jruby.ast.ConstDeclNode;
import org.jruby.ast.ConstNode;
@@ -44,8 +45,10 @@
import org.jruby.ast.DefsNode;
import org.jruby.ast.FCallNode;
import org.jruby.ast.GlobalAsgnNode;
+import org.jruby.ast.GlobalVarNode;
import org.jruby.ast.IArgumentNode;
import org.jruby.ast.InstAsgnNode;
+import org.jruby.ast.InstVarNode;
import org.jruby.ast.IterNode;
import org.jruby.ast.LocalAsgnNode;
import org.jruby.ast.ModuleNode;
@@ -279,6 +282,12 @@
return super.visitClassVarAsgnNode(iVisited);
}
+ @Override
+ public Instruction visitClassVarNode(ClassVarNode iVisited) {
+ requestor.acceptFieldReference(iVisited.getName(), iVisited.getPosition().getStartOffset());
+ return super.visitClassVarNode(iVisited);
+ }
+
public Instruction visitLocalAsgnNode(LocalAsgnNode iVisited) {
FieldInfo field = createFieldInfo(iVisited);
field.name = iVisited.getName();
@@ -297,6 +306,12 @@
}
@Override
+ public Instruction visitInstVarNode(InstVarNode iVisited) {
+ requestor.acceptFieldReference(iVisited.getName(), iVisited.getPosition().getStartOffset());
+ return super.visitInstVarNode(iVisited);
+ }
+
+ @Override
public Instruction visitGlobalAsgnNode(GlobalAsgnNode iVisited) {
FieldInfo field = createFieldInfo(iVisited);
field.name = iVisited.getName();
@@ -304,6 +319,12 @@
exitField(iVisited);
return super.visitGlobalAsgnNode(iVisited);
}
+
+ @Override
+ public Instruction visitGlobalVarNode(GlobalVarNode iVisited) {
+ requestor.acceptFieldReference(iVisited.getName(), iVisited.getPosition().getStartOffset());
+ return super.visitGlobalVarNode(iVisited);
+ }
private void exitField(AssignableNode iVisited) {
requestor.exitField(iVisited.getPosition().getEndOffset() - 1);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-05-23 03:02:32
|
Revision: 2523
http://svn.sourceforge.net/rubyeclipse/?rev=2523&view=rev
Author: cawilliams
Date: 2007-05-22 20:02:18 -0700 (Tue, 22 May 2007)
Log Message:
-----------
move the code which grabbed comments/docs for an IRubyElement into the util class in rdt.core. Now just refer to that class to grab them
Modified Paths:
--------------
trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java
Modified: trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java 2007-05-23 03:01:47 UTC (rev 2522)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java 2007-05-23 03:02:18 UTC (rev 2523)
@@ -1,18 +1,13 @@
package com.aptana.rdt.internal.ui.text.ruby.hover;
-import java.util.Collection;
-
import org.eclipse.jface.text.DefaultInformationControl;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
-import org.jruby.ast.CommentNode;
-import org.jruby.lexer.yacc.ISourcePosition;
import org.rubypeople.rdt.core.IMember;
import org.rubypeople.rdt.core.IRubyElement;
-import org.rubypeople.rdt.core.RubyModelException;
-import org.rubypeople.rdt.internal.core.parser.RubyParser;
+import org.rubypeople.rdt.core.util.RDocUtil;
import org.rubypeople.rdt.internal.ui.text.HTMLPrinter;
import org.rubypeople.rdt.internal.ui.text.HTMLTextPresenter;
import org.rubypeople.rdt.internal.ui.text.ruby.IInformationControlExtension4;
@@ -39,61 +34,6 @@
*/
private IInformationControlCreator fPresenterControlCreator;
- /**
- * Grabs the comment from any comment node that follows this element (has to be on the same line)
- * @param comments
- * @param elementStart
- * @param src
- * @return
- */
- private String getFollowingComment(Collection<CommentNode> comments, int elementStart, String src) {
- for (CommentNode comment : comments) {
- ISourcePosition pos = comment.getPosition();
- if (pos.getStartOffset() < elementStart) continue;
- String between = src.substring(elementStart, pos.getStartOffset());
- if (between.contains("\n")) continue; // if there's a newline between the positions - it's not on same line
- String com = comment.getContent();
- if (com != null && com.length() > 0)
- return removePrecedingHashes(com);
- }
- return null;
- }
-
- /**
- * Grabs and merges together all comment nodes which immediately preced the elementStart offset.
- * @param comments
- * @param elementStart
- * @param src
- * @return a combined string of all immediately preceding comments
- */
- private String getPrecedingComment(Collection<CommentNode> comments, int elementStart, String src) {
- for (CommentNode comment : comments) {
- ISourcePosition pos = comment.getPosition();
- if (pos.getEndOffset() > elementStart) continue;
- String between = src.substring(pos.getEndOffset(), elementStart);
- if (between.trim().length() > 0)
- continue; // if there's anything but whitespace between (\n\r\t ), move to next comment
- String preceding = getPrecedingComment(comments, pos.getStartOffset(), src);
- if (preceding == null) {
- preceding = removePrecedingHashes(comment.getContent());
- } else {
- preceding += "\n" + removePrecedingHashes(comment.getContent());
- }
- return preceding;
- }
- return null;
- }
-
- /**
- * Trims the string and drops the beginning hash mark (#)
- * @param comment
- * @return
- */
- private String removePrecedingHashes(String comment) {
- comment = comment.trim();
- return comment.substring(1);
- }
-
/*
* @see RubyElementHover
*/
@@ -123,7 +63,7 @@
if (curr instanceof IMember) {
IMember member= (IMember) curr;
HTMLPrinter.addSmallHeader(buffer, getInfoText(member));
- String contents = getContents(member);
+ String contents = RDocUtil.getDocumentation(member);
if (contents != null) {
HTMLPrinter.addParagraph(buffer, contents);
}
@@ -145,24 +85,6 @@
return null;
}
-
- private String getContents(IMember member) {
- String src = "";
- int elementOffset = -1;
- try {
- src = member.getRubyScript().getSource();
- elementOffset = member.getSourceRange().getOffset();
- } catch (RubyModelException e) {
- return null;
- }
- RubyParser parser = new RubyParser();
- parser.parse(src); // parse so we can grab the comment nodes
- Collection<CommentNode> comments = parser.getComments();
- if (member.isType(IRubyElement.TYPE) || member.isType(IRubyElement.METHOD) || member.isType(IRubyElement.CONSTANT)) {
- return getPrecedingComment(comments, elementOffset, src);
- }
- return getFollowingComment(comments, elementOffset, src);
- }
/*
* @see IInformationProviderExtension2#getInformationPresenterControlCreator()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|