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
|
Revision: 1527 Author: jasonpmorrison Date: 2006-07-19 21:16:47 -0700 (Wed, 19 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1527&view=rev Log Message: ----------- - Find and match ArgumentNode - Find and match Symbol Node (HACK: JRuby positioning issue with symbols) Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java 2006-07-20 04:16:16 UTC (rev 1526) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java 2006-07-20 04:16:47 UTC (rev 1527) @@ -14,7 +14,7 @@ * Tests related to matching occurrences. * * @author Jason Morrison - * + *` */ public class MarkOccurrencesTest extends TestCase { @@ -48,6 +48,15 @@ } /** + * Match args to locals + */ + public void testArgMatches() { + String source = "class Klass;def foo(my_arg);puts my_arg*2;end;end"; + int[][] offsets = {{20,26},{33,39}}; + assertOccurrencesEqual( source, 22, "my_arg", offsets ); + } + + /** * Match locals within Kernel::DefnNode */ public void testLocalVariablesInKernelDefnScope() { @@ -102,7 +111,18 @@ assertOccurrencesEqual(source, 0, "$foo", offsets); } -//todo: Method invocation tests get into territory where a more formal approach is needed (i.e. DDP) + /** + * Test referencing a symbol in various contexts. + * + */ + public void testSymbolMatches() { + String source = "a_var = :foo;class Klass;def foo;l = :foo;end;def bar;puts :foo;end;end;puts :foo.to_s"; +// String source = "$foo = 'bar';class Klass;def foo;$foo = 5;end;def bar;puts $foo;end;end;puts $foo"; + int[][] offsets = {{8,12},{37,41},{59,63},{77,81}}; + assertOccurrencesEqual(source, 9, ":foo", offsets); + } + +//TODO: Method invocation tests need to know the type of their receiver. // Sub-goals are becoming necessary, i.e. for determining arg-type to match selectors by more // than name, and determining receiver-type to match selectors applied to other same-typed receivers. @@ -136,7 +156,19 @@ public void testTypeMatches() { String source = "f = String.new;class Klass;def foo;c = String;end;end;class MyString < String;end"; int[][] offsets = {{4,10},{39,45},{71,77}}; - assertOccurrencesEqual( source, 5, "String", offsets ); + assertOccurrencesEqual( source, 4, "String", offsets ); } +// public void testConstNodeToClassDeclNode() { +// String source = "class Klass;def foo;5;end;end;k = Klass.new"; +// int[][] offsets = {{6,11},{34,39}}; +// assertOccurrencesEqual( source, 6, "Klass", offsets ); +// } + +// public void testBlockArguments() { +// String source = "[1,2,3].each { |number| puts number }"; +// int[][] offsets = {{16,22},{29,35}}; +// assertOccurrencesEqual(source, 16, "number", offsets); +// } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <jas...@us...> - 2006-07-20 04:16:25
|
Revision: 1526 Author: jasonpmorrison Date: 2006-07-19 21:16:16 -0700 (Wed, 19 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1526&view=rev Log Message: ----------- Added refinements to locate particular ArgumentNode within an ArgsNode Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/OffsetNodeLocator.java branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/ScopedNodeLocator.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/OffsetNodeLocator.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/OffsetNodeLocator.java 2006-07-20 00:10:25 UTC (rev 1525) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/OffsetNodeLocator.java 2006-07-20 04:16:16 UTC (rev 1526) @@ -1,5 +1,9 @@ package org.rubypeople.rdt.internal.ti.util; +import java.util.Iterator; + +import org.jruby.ast.ArgsNode; +import org.jruby.ast.ArgumentNode; import org.jruby.ast.Node; import org.jruby.evaluator.Instruction; @@ -38,10 +42,32 @@ // Traverse to find closest node rootNode.accept(this); + + // Refine the node, if possible, to an inner node not covered by the visitor + // (Why? Nodes such as ArgumentNode don't like being visited, so they must be handled here.) + locatedNode = refine(locatedNode); // Return the node return locatedNode; } + + private Node refine(Node node) { + // If the search returned an ArgsNode, try to find the specific ArgumentNode matched + if ( node instanceof ArgsNode ) + { + ArgsNode argsNode = (ArgsNode)node; + if ( argsNode.getArgsCount() > 0 ) { + for (Iterator iter = argsNode.getArgs().iterator(); iter.hasNext();) { + ArgumentNode argNode = (ArgumentNode) iter.next(); + if ( nodeDoesSpanOffset(argNode, offset) ) { +// System.out.println("Refining " + node.getClass().getSimpleName() + "["+node.getPosition().getStartOffset() + ".." + node.getPosition().getEndOffset() + "] to " + argNode.getClass().getSimpleName() + "["+argNode.getPosition().getStartOffset() + ".." + argNode.getPosition().getEndOffset() + "]"); + return argNode; + } + } + } + } + return node; + } /** * For each node, see if it spans the desired offset. Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/ScopedNodeLocator.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/ScopedNodeLocator.java 2006-07-20 00:10:25 UTC (rev 1525) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/ScopedNodeLocator.java 2006-07-20 04:16:16 UTC (rev 1526) @@ -1,8 +1,11 @@ package org.rubypeople.rdt.internal.ti.util; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import org.jruby.ast.ArgsNode; +import org.jruby.ast.ArgumentNode; import org.jruby.ast.Node; import org.jruby.evaluator.Instruction; @@ -55,5 +58,32 @@ return super.handleNode(iVisited); } + /** + * Handle the parsing of ArgsNode, to get at its ArgumentNodes + * + * @see org.jruby.ast.visitor.NodeVisitor#visitArgsNode(org.jruby.ast.ArgsNode) + */ + public Instruction visitArgsNode(ArgsNode iVisited) { + if ( iVisited.getArgsCount() > 0 ) + { + for (Iterator iter = iVisited.getArgs().iterator(); iter.hasNext();) { + ArgumentNode argNode = (ArgumentNode) iter.next(); + if ( acceptor.doesAccept(argNode)) + { + locatedNodes.add(argNode); + } + } + } + + return super.visitArgsNode(iVisited); +// +// handleNode(iVisited); +// acceptNode(iVisited.getBlockArgNode()); +// if (iVisited.getOptArgs() != null) { +// visitIter(iVisited.getOptArgs().iterator()); +// } +// return null; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <caw...@us...> - 2006-07-20 00:10:29
|
Revision: 1525 Author: cawilliams Date: 2006-07-19 17:10:25 -0700 (Wed, 19 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1525&view=rev Log Message: ----------- move the mark occurrences code over to RubyAbstractEditor from RubyEditor (the line between where this stuff goes is very foggy... but I was forced to do this because of what I did next...) made the editor actually listen to user preferences for mark occurrences stuff (set in the new UI page). Turning marking on/off and sticky occurrences already work as expected. There may be a need to actually delineate between which types of occurrences to mark (local vars, fields, method calls, constants, method returns etc.) Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java 2006-07-20 00:07:27 UTC (rev 1524) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java 2006-07-20 00:10:25 UTC (rev 1525) @@ -1,20 +1,42 @@ package org.rubypeople.rdt.internal.ui.rubyeditor; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.eclipse.core.resources.ProjectScope; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.DocumentCommand; +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentExtension4; +import org.eclipse.jface.text.IDocumentListener; +import org.eclipse.jface.text.ISelectionValidator; +import org.eclipse.jface.text.ISynchronizable; +import org.eclipse.jface.text.ITextInputListener; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.ITextViewerExtension5; import org.eclipse.jface.text.IWidgetTokenKeeper; +import org.eclipse.jface.text.Position; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.contentassist.ContentAssistant; import org.eclipse.jface.text.contentassist.IContentAssistant; +import org.eclipse.jface.text.link.LinkedModeModel; +import org.eclipse.jface.text.source.Annotation; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.IAnnotationModelExtension; import org.eclipse.jface.text.source.IOverviewRuler; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.IVerticalRuler; @@ -22,7 +44,9 @@ import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.ListenerList; import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.IPostSelectionProvider; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; @@ -32,6 +56,7 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IPartService; +import org.eclipse.ui.IWindowListener; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; @@ -56,6 +81,8 @@ import org.rubypeople.rdt.core.RubyModelException; import org.rubypeople.rdt.core.formatter.DefaultCodeFormatterConstants; import org.rubypeople.rdt.internal.corext.util.CodeFormatterUtil; +import org.rubypeople.rdt.internal.ti.DefaultOccurrencesFinder; +import org.rubypeople.rdt.internal.ti.IOccurrencesFinder; import org.rubypeople.rdt.internal.ui.RubyPlugin; import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor.ITextConverter; import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor.TabConverter; @@ -81,7 +108,7 @@ protected AbstractSelectionChangedListener fOutlineSelectionChangedListener = new OutlineSelectionChangedListener(); private RubyOutlinePage fOutlinePage; /** The editor's tab converter */ - private TabConverter fTabConverter; + private TabConverter fTabConverter; // FIXME The tab conversion stuff should all be in the same class, either this one or RubyEditor /** Preference key for matching brackets */ protected final static String MATCHING_BRACKETS= PreferenceConstants.EDITOR_MATCHING_BRACKETS; @@ -96,8 +123,90 @@ /** The editor's bracket matcher */ protected RubyPairMatcher fBracketMatcher= new RubyPairMatcher(BRACKETS); + + /** + * Holds the current occurrence annotations. + * @since 3.0 + */ + private Annotation[] fOccurrenceAnnotations= null; /** + * Tells whether all occurrences of the element at the + * current caret location are automatically marked in + * this editor. + * @since 3.0 + */ + private boolean fMarkOccurrenceAnnotations; + /** + * Tells whether the occurrence annotations are sticky + * i.e. whether they stay even if there's no valid Java + * element at the current caret position. + * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. + * @since 3.0 + */ + private boolean fStickyOccurrenceAnnotations; + /** + * Tells whether to mark type occurrences in this editor. + * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. + * @since 3.0 + */ + private boolean fMarkTypeOccurrences; + /** + * Tells whether to mark method occurrences in this editor. + * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. + * @since 3.0 + */ + private boolean fMarkMethodOccurrences; + /** + * Tells whether to mark constant occurrences in this editor. + * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. + * @since 3.0 + */ + private boolean fMarkConstantOccurrences; + /** + * Tells whether to mark field occurrences in this editor. + * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. + * @since 3.0 + */ + private boolean fMarkFieldOccurrences; + /** + * Tells whether to mark local variable occurrences in this editor. + * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. + * @since 3.0 + */ + private boolean fMarkLocalVariableypeOccurrences; + /** + * Tells whether to mark method exits in this editor. + * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. + * @since 3.0 + */ + private boolean fMarkMethodExitPoints; + + /** + * The selection used when forcing occurrence marking + * through code. + * @since 3.0 + */ + private ISelection fForcedMarkOccurrencesSelection; + /** + * The document modification stamp at the time when the last + * occurrence marking took place. + * @since 3.1 + */ + //TODO: Do I need to use this? + private long fMarkOccurrenceModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; + + /** + * The internal shell activation listener for updating occurrences. + */ + private ActivationListener fActivationListener= new ActivationListener(); + private ISelectionChangedListener fPostSelectionListener; + private OccurrencesFinderJob fOccurrencesFinderJob; + /** The occurrences finder job canceler */ + private OccurrencesFinderJobCanceler fOccurrencesFinderJobCanceler; + private IOccurrencesFinder fOccurrencesFinder; + + /** * Creates and returns the preference store for this Ruby editor with the given input. * * @param input The editor input for which to create the preference store @@ -170,6 +279,14 @@ setPreferenceStore(store); RubyTextTools textTools= RubyPlugin.getDefault().getRubyTextTools(); setSourceViewerConfiguration(new RubySourceViewerConfiguration(textTools.getColorManager(), store, this, IRubyPartitions.RUBY_PARTITIONING)); + fMarkOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES); + fStickyOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES); + fMarkTypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES); + fMarkMethodOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES); + fMarkConstantOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES); + fMarkFieldOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES); + fMarkLocalVariableypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES); + fMarkMethodExitPoints= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS); } /* @@ -193,7 +310,14 @@ */ public void dispose() { super.dispose(); + // cancel possible running computation + fMarkOccurrenceAnnotations= false; + uninstallOccurrencesFinder(); + if (fActivationListener != null) { + PlatformUI.getWorkbench().removeWindowListener(fActivationListener); + fActivationListener= null; + } } public Object getAdapter(Class required) { @@ -244,7 +368,48 @@ } try { - + boolean newBooleanValue= false; + Object newValue= event.getNewValue(); + if (newValue != null) + newBooleanValue= Boolean.valueOf(newValue.toString()).booleanValue(); + if (PreferenceConstants.EDITOR_MARK_OCCURRENCES.equals(property)) { + if (newBooleanValue != fMarkOccurrenceAnnotations) { + fMarkOccurrenceAnnotations= newBooleanValue; + if (!fMarkOccurrenceAnnotations) + uninstallOccurrencesFinder(); + else + installOccurrencesFinder(true); + } + return; + } + if (PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES.equals(property)) { + fMarkTypeOccurrences= newBooleanValue; + return; + } + if (PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES.equals(property)) { + fMarkMethodOccurrences= newBooleanValue; + return; + } + if (PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES.equals(property)) { + fMarkConstantOccurrences= newBooleanValue; + return; + } + if (PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES.equals(property)) { + fMarkFieldOccurrences= newBooleanValue; + return; + } + if (PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES.equals(property)) { + fMarkLocalVariableypeOccurrences= newBooleanValue; + return; + } + if (PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS.equals(property)) { + fMarkMethodExitPoints= newBooleanValue; + return; + } + if (PreferenceConstants.EDITOR_STICKY_OCCURRENCES.equals(property)) { + fStickyOccurrenceAnnotations= newBooleanValue; + return; + } AdaptedSourceViewer sourceViewer= (AdaptedSourceViewer) getSourceViewer(); if (sourceViewer == null) return; @@ -285,8 +450,7 @@ adjustHighlightRange(selection.x, selection.y); } } - - } + } } private int getTabSize() { @@ -348,6 +512,11 @@ if (isTabConversionEnabled()) startTabConversion(); + + if (fMarkOccurrenceAnnotations) + installOccurrencesFinder(false); + + PlatformUI.getWorkbench().addWindowListener(fActivationListener); } private boolean isTabConversionEnabled() { @@ -625,6 +794,10 @@ protected abstract IRubyElement getElementAt(int offset); + public final ISourceViewer getViewer() { + return getSourceViewer(); + } + /** * Adapts an options {@link IEclipsePreferences} to {@link org.eclipse.jface.preference.IPreferenceStore}. * <p> @@ -993,4 +1166,389 @@ } } + /** + * Internal activation listener. + * @since 3.0 + */ + private class ActivationListener implements IWindowListener { + + /* + * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow) + * @since 3.1 + */ + public void windowActivated(IWorkbenchWindow window) { + if (window == getEditorSite().getWorkbenchWindow() && fMarkOccurrenceAnnotations && isActivePart()) { + fForcedMarkOccurrencesSelection= getSelectionProvider().getSelection(); + updateOccurrenceAnnotations((ITextSelection)fForcedMarkOccurrencesSelection); + } + } + + /* + * @see org.eclipse.ui.IWindowListener#windowDeactivated(org.eclipse.ui.IWorkbenchWindow) + * @since 3.1 + */ + public void windowDeactivated(IWorkbenchWindow window) { + if (window == getEditorSite().getWorkbenchWindow() && fMarkOccurrenceAnnotations && isActivePart()) + removeOccurrenceAnnotations(); + } + + /* + * @see org.eclipse.ui.IWindowListener#windowClosed(org.eclipse.ui.IWorkbenchWindow) + * @since 3.1 + */ + public void windowClosed(IWorkbenchWindow window) { + } + + /* + * @see org.eclipse.ui.IWindowListener#windowOpened(org.eclipse.ui.IWorkbenchWindow) + * @since 3.1 + */ + public void windowOpened(IWorkbenchWindow window) { + } + } + + /** + * Cancels the occurrences finder job upon document changes. + * + * @since 3.0 + */ + class OccurrencesFinderJobCanceler implements IDocumentListener, ITextInputListener { + + public void install() { + ISourceViewer sourceViewer= getSourceViewer(); + if (sourceViewer == null) + return; + + StyledText text= sourceViewer.getTextWidget(); + if (text == null || text.isDisposed()) + return; + + sourceViewer.addTextInputListener(this); + + IDocument document= sourceViewer.getDocument(); + if (document != null) + document.addDocumentListener(this); + } + + public void uninstall() { + ISourceViewer sourceViewer= getSourceViewer(); + if (sourceViewer != null) + sourceViewer.removeTextInputListener(this); + + IDocumentProvider documentProvider= getDocumentProvider(); + if (documentProvider != null) { + IDocument document= documentProvider.getDocument(getEditorInput()); + if (document != null) + document.removeDocumentListener(this); + } + } + + + /* + * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent) + */ + public void documentAboutToBeChanged(DocumentEvent event) { + if (fOccurrencesFinderJob != null) + fOccurrencesFinderJob.doCancel(); + } + + /* + * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent) + */ + public void documentChanged(DocumentEvent event) { + } + + /* + * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument) + */ + public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { + if (oldInput == null) + return; + + oldInput.removeDocumentListener(this); + } + + /* + * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument) + */ + public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { + if (newInput == null) + return; + newInput.addDocumentListener(this); + } + } + + /** + * Finds and marks occurrence annotations. + * + * @since 3.0 + */ + class OccurrencesFinderJob extends Job { + + private IDocument fDocument; + private ISelection fSelection; + private ISelectionValidator fPostSelectionValidator; + private boolean fCanceled= false; + private IProgressMonitor fProgressMonitor; + private Position[] fPositions; + + public OccurrencesFinderJob(IDocument document, Position[] positions, ISelection selection) { + //TODO: Refactor job name to resource string somewhere + super("OccurrencesFinderJob"); + fDocument= document; + fSelection= selection; + fPositions= positions; + + if (getSelectionProvider() instanceof ISelectionValidator) + fPostSelectionValidator= (ISelectionValidator)getSelectionProvider(); + } + + // cannot use cancel() because it is declared final + void doCancel() { + fCanceled= true; + cancel(); + } + + private boolean isCanceled() { + return fCanceled || fProgressMonitor.isCanceled() + || fPostSelectionValidator != null && !(fPostSelectionValidator.isValid(fSelection) || fForcedMarkOccurrencesSelection == fSelection) + || LinkedModeModel.hasInstalledModel(fDocument); + } + + /* + * @see Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + public IStatus run(IProgressMonitor progressMonitor) { + + fProgressMonitor= progressMonitor; + + if (isCanceled()) + return Status.CANCEL_STATUS; + + ITextViewer textViewer= getViewer(); + if (textViewer == null) + return Status.CANCEL_STATUS; + + IDocument document= textViewer.getDocument(); + if (document == null) + return Status.CANCEL_STATUS; + + IDocumentProvider documentProvider= getDocumentProvider(); + if (documentProvider == null) + return Status.CANCEL_STATUS; + + IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); + if (annotationModel == null) + return Status.CANCEL_STATUS; + + // Add occurrence annotations + int length= fPositions.length; + Map annotationMap= new HashMap(length); + for (int i= 0; i < length; i++) { + + if (isCanceled()) + return Status.CANCEL_STATUS; + + String message; + Position position= fPositions[i]; + + // Create & add annotation + try { + message= document.get(position.offset, position.length); + } catch (BadLocationException ex) { + // Skip this match + continue; + } + annotationMap.put( + new Annotation("org.eclipse.jdt.ui.occurrences", false, message), //$NON-NLS-1$ + position); + } + + if (isCanceled()) + return Status.CANCEL_STATUS; + + synchronized (getLockObject(annotationModel)) { + if (annotationModel instanceof IAnnotationModelExtension) { + ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap); + } else { + removeOccurrenceAnnotations(); + Iterator iter= annotationMap.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry mapEntry= (Map.Entry)iter.next(); + annotationModel.addAnnotation((Annotation)mapEntry.getKey(), (Position)mapEntry.getValue()); + } + } + fOccurrenceAnnotations= (Annotation[])annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]); + } + + return Status.OK_STATUS; + } + } + + /** + * Updates the occurrences annotations based + * on the current selection. + * + * @param selection the text selection + */ + protected void updateOccurrenceAnnotations(ITextSelection selection) { + + if (fOccurrencesFinderJob != null) + fOccurrencesFinderJob.cancel(); + + if (!fMarkOccurrenceAnnotations) + return; + + if (selection == null) + return; + + IDocument document= getDocumentProvider().getDocument(getEditorInput()); + String source = document.get(); + + // Search for occurrences + fOccurrencesFinder.initialize(source, selection.getOffset(), selection.getLength()); + List<Position> matches = fOccurrencesFinder.perform(); + + if (matches.isEmpty()) { + if (!fStickyOccurrenceAnnotations) { + removeOccurrenceAnnotations(); + } + return; + } else { + // Convert to array + //TODO: Update IOccurrencesFinder interface to return an array of Position + Position[] positions = new Position[matches.size()]; + int i = 0; + for (Position match : matches) { + positions[i++] = match; + } + + // Mark occurrences + fOccurrencesFinderJob= new OccurrencesFinderJob(document, positions, selection); + //fOccurrencesFinderJob.setPriority(Job.DECORATE); + //fOccurrencesFinderJob.setSystem(true); + //fOccurrencesFinderJob.schedule(); + fOccurrencesFinderJob.run(new NullProgressMonitor()); + } + } + + protected void installOccurrencesFinder(boolean forceUpdate) { + fMarkOccurrenceAnnotations= true; + + fOccurrencesFinder = new DefaultOccurrencesFinder(); + + fPostSelectionListener = new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + updateOccurrenceAnnotations((ITextSelection)event.getSelection()); + } + }; + + IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider)getSourceViewer().getSelectionProvider(); + postSelectionProvider.addPostSelectionChangedListener(fPostSelectionListener); + + if (forceUpdate && getSelectionProvider() != null) { + fForcedMarkOccurrencesSelection= getSelectionProvider().getSelection(); + updateOccurrenceAnnotations((ITextSelection)fForcedMarkOccurrencesSelection); + } + + if (fOccurrencesFinderJobCanceler == null) { + fOccurrencesFinderJobCanceler= new OccurrencesFinderJobCanceler(); + fOccurrencesFinderJobCanceler.install(); + } + } + + protected void uninstallOccurrencesFinder() { + fMarkOccurrenceAnnotations= false; + + if (fOccurrencesFinderJob != null) { + fOccurrencesFinderJob.cancel(); + fOccurrencesFinderJob= null; + } + + if (fOccurrencesFinderJobCanceler != null) { + fOccurrencesFinderJobCanceler.uninstall(); + fOccurrencesFinderJobCanceler= null; + } + + if (fPostSelectionListener != null) { + IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider)getSourceViewer().getSelectionProvider(); + postSelectionProvider.removePostSelectionChangedListener(fPostSelectionListener); + fPostSelectionListener = null; + } + + removeOccurrenceAnnotations(); + } + + protected boolean isMarkingOccurrences() { + return fMarkOccurrenceAnnotations; + } + +// boolean markOccurrencesOfType(IBinding binding) { +// +// if (binding == null) +// return false; +// +// int kind= binding.getKind(); +// +// if (fMarkTypeOccurrences && kind == IBinding.TYPE) +// return true; +// +// if (fMarkMethodOccurrences && kind == IBinding.METHOD) +// return true; +// +// if (kind == IBinding.VARIABLE) { +// IVariableBinding variableBinding= (IVariableBinding)binding; +// if (variableBinding.isField()) { +// int constantModifier= IModifierConstants.ACC_STATIC | IModifierConstants.ACC_FINAL; +// boolean isConstant= (variableBinding.getModifiers() & constantModifier) == constantModifier; +// if (isConstant) +// return fMarkConstantOccurrences; +// else +// return fMarkFieldOccurrences; +// } +// +// return fMarkLocalVariableypeOccurrences; +// } +// +// return false; +// } + + void removeOccurrenceAnnotations() { + fMarkOccurrenceModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; + + IDocumentProvider documentProvider= getDocumentProvider(); + if (documentProvider == null) + return; + + IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); + if (annotationModel == null || fOccurrenceAnnotations == null) + return; + + synchronized (getLockObject(annotationModel)) { + if (annotationModel instanceof IAnnotationModelExtension) { + ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, null); + } else { + for (int i= 0, length= fOccurrenceAnnotations.length; i < length; i++) + annotationModel.removeAnnotation(fOccurrenceAnnotations[i]); + } + fOccurrenceAnnotations= null; + } + } + + + /** + * Returns the lock object for the given annotation model. + * + * @param annotationModel the annotation model + * @return the annotation model's lock object + * @since 3.0 + */ + private Object getLockObject(IAnnotationModel annotationModel) { + if (annotationModel instanceof ISynchronizable) { + Object lock= ((ISynchronizable)annotationModel).getLockObject(); + if (lock != null) + return lock; + } + return annotationModel; + } } \ No newline at end of file Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java 2006-07-20 00:07:27 UTC (rev 1524) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java 2006-07-20 00:10:25 UTC (rev 1525) @@ -122,6 +122,7 @@ import org.rubypeople.rdt.ui.actions.IRubyEditorActionDefinitionIds; import org.rubypeople.rdt.ui.actions.RubyActionGroup; import org.rubypeople.rdt.ui.actions.SurroundWithBeginRescueAction; +import org.rubypeople.rdt.ui.text.RubyTextTools; import org.rubypeople.rdt.ui.text.folding.IRubyFoldingStructureProvider; import org.rubypeople.rdt.ui.text.folding.IRubyFoldingStructureProviderExtension; @@ -181,108 +182,8 @@ private FoldingActionGroup fFoldingGroup; private BracketInserter fBracketInserter = new BracketInserter(); - - /** - * Holds the current occurrence annotations. - * @since 3.0 - */ - private Annotation[] fOccurrenceAnnotations= null; - /** - * Tells whether all occurrences of the element at the - * current caret location are automatically marked in - * this editor. - * @since 3.0 - */ - private boolean fMarkOccurrenceAnnotations; - /** - * Tells whether the occurrence annotations are sticky - * i.e. whether they stay even if there's no valid Java - * element at the current caret position. - * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. - * @since 3.0 - */ - private boolean fStickyOccurrenceAnnotations; -// /** -// * Tells whether to mark type occurrences in this editor. -// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. -// * @since 3.0 -// */ -// private boolean fMarkTypeOccurrences; -// /** -// * Tells whether to mark method occurrences in this editor. -// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. -// * @since 3.0 -// */ -// private boolean fMarkMethodOccurrences; -// /** -// * Tells whether to mark constant occurrences in this editor. -// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. -// * @since 3.0 -// */ -// private boolean fMarkConstantOccurrences; -// /** -// * Tells whether to mark field occurrences in this editor. -// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. -// * @since 3.0 -// */ -// private boolean fMarkFieldOccurrences; -// /** -// * Tells whether to mark local variable occurrences in this editor. -// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. -// * @since 3.0 -// */ -// private boolean fMarkLocalVariableypeOccurrences; -// /** -// * Tells whether to mark exception occurrences in this editor. -// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. -// * @since 3.0 -// */ -// private boolean fMarkExceptions; -// /** -// * Tells whether to mark method exits in this editor. -// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. -// * @since 3.0 -// */ -// private boolean fMarkMethodExitPoints; -// -// /** -// * Tells whether to mark targets of <code>break</code> and <code>continue</code> statements in this editor. -// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. -// * @since 3.2 -// */ -// private boolean fMarkBreakContinueTargets; -// -// /** -// * Tells whether to mark implementors in this editor. -// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. -// * @since 3.1 -// */ -// private boolean fMarkImplementors; - /** - * The selection used when forcing occurrence marking - * through code. - * @since 3.0 - */ - private ISelection fForcedMarkOccurrencesSelection; - /** - * The document modification stamp at the time when the last - * occurrence marking took place. - * @since 3.1 - */ - //TODO: Do I need to use this? - private long fMarkOccurrenceModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; - /** - * The internal shell activation listener for updating occurrences. - */ - private ActivationListener fActivationListener= new ActivationListener(); - private ISelectionChangedListener fPostSelectionListener; - private OccurrencesFinderJob fOccurrencesFinderJob; - /** The occurrences finder job canceler */ - private OccurrencesFinderJobCanceler fOccurrencesFinderJobCanceler; - private IOccurrencesFinder fOccurrencesFinder; - public RubyEditor() { super(); setDocumentProvider(RubyPlugin.getDefault().getRubyDocumentProvider()); @@ -350,11 +251,7 @@ actionGroup = new RubyActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); } - - public final ISourceViewer getViewer() { - return getSourceViewer(); - } - + /** * Configures the toggle comment action * @@ -412,31 +309,8 @@ fBracketInserter.setCloseBracesEnabled(closeBraces); fBracketInserter.setCloseStringsEnabled(closeStrings); ((ITextViewerExtension) sourceViewer).prependVerifyKeyListener(fBracketInserter); - - //TODO: Pull these from prefs rather than hardcoded true values - fMarkOccurrenceAnnotations = true; - fStickyOccurrenceAnnotations = false; -// setPreferenceStore(store); -// JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools(); -// setSourceViewerConfiguration(new JavaSourceViewerConfiguration(textTools.getColorManager(), store, this, IJavaPartitions.JAVA_PARTITIONING)); -// fMarkOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES); -// fStickyOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES); -// fMarkTypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES); -// fMarkMethodOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES); -// fMarkConstantOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES); -// fMarkFieldOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES); -// fMarkLocalVariableypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES); -// fMarkExceptions= store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES); -// fMarkImplementors= store.getBoolean(PreferenceConstants.EDITOR_MARK_IMPLEMENTORS); -// fMarkMethodExitPoints= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS); -// fMarkBreakContinueTargets= store.getBoolean(PreferenceConstants.EDITOR_MARK_BREAK_CONTINUE_TARGETS); } - - if (fMarkOccurrenceAnnotations) - installOccurrencesFinder(false); - - PlatformUI.getWorkbench().addWindowListener(fActivationListener); } /** @@ -753,16 +627,7 @@ fProjectionSupport.dispose(); fProjectionSupport = null; } - - // cancel possible running computation - fMarkOccurrenceAnnotations= false; - uninstallOccurrencesFinder(); - - if (fActivationListener != null) { - PlatformUI.getWorkbench().removeWindowListener(fActivationListener); - fActivationListener= null; - } - + super.dispose(); } @@ -1716,389 +1581,4 @@ return fFoldingGroup; } - /** - * Internal activation listener. - * @since 3.0 - */ - private class ActivationListener implements IWindowListener { - - /* - * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow) - * @since 3.1 - */ - public void windowActivated(IWorkbenchWindow window) { - if (window == getEditorSite().getWorkbenchWindow() && fMarkOccurrenceAnnotations && isActivePart()) { - fForcedMarkOccurrencesSelection= getSelectionProvider().getSelection(); - updateOccurrenceAnnotations((ITextSelection)fForcedMarkOccurrencesSelection); - } - } - - /* - * @see org.eclipse.ui.IWindowListener#windowDeactivated(org.eclipse.ui.IWorkbenchWindow) - * @since 3.1 - */ - public void windowDeactivated(IWorkbenchWindow window) { - if (window == getEditorSite().getWorkbenchWindow() && fMarkOccurrenceAnnotations && isActivePart()) - removeOccurrenceAnnotations(); - } - - /* - * @see org.eclipse.ui.IWindowListener#windowClosed(org.eclipse.ui.IWorkbenchWindow) - * @since 3.1 - */ - public void windowClosed(IWorkbenchWindow window) { - } - - /* - * @see org.eclipse.ui.IWindowListener#windowOpened(org.eclipse.ui.IWorkbenchWindow) - * @since 3.1 - */ - public void windowOpened(IWorkbenchWindow window) { - } - } - - /** - * Cancels the occurrences finder job upon document changes. - * - * @since 3.0 - */ - class OccurrencesFinderJobCanceler implements IDocumentListener, ITextInputListener { - - public void install() { - ISourceViewer sourceViewer= getSourceViewer(); - if (sourceViewer == null) - return; - - StyledText text= sourceViewer.getTextWidget(); - if (text == null || text.isDisposed()) - return; - - sourceViewer.addTextInputListener(this); - - IDocument document= sourceViewer.getDocument(); - if (document != null) - document.addDocumentListener(this); - } - - public void uninstall() { - ISourceViewer sourceViewer= getSourceViewer(); - if (sourceViewer != null) - sourceViewer.removeTextInputListener(this); - - IDocumentProvider documentProvider= getDocumentProvider(); - if (documentProvider != null) { - IDocument document= documentProvider.getDocument(getEditorInput()); - if (document != null) - document.removeDocumentListener(this); - } - } - - - /* - * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent) - */ - public void documentAboutToBeChanged(DocumentEvent event) { - if (fOccurrencesFinderJob != null) - fOccurrencesFinderJob.doCancel(); - } - - /* - * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent) - */ - public void documentChanged(DocumentEvent event) { - } - - /* - * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument) - */ - public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { - if (oldInput == null) - return; - - oldInput.removeDocumentListener(this); - } - - /* - * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument) - */ - public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { - if (newInput == null) - return; - newInput.addDocumentListener(this); - } - } - - /** - * Finds and marks occurrence annotations. - * - * @since 3.0 - */ - class OccurrencesFinderJob extends Job { - - private IDocument fDocument; - private ISelection fSelection; - private ISelectionValidator fPostSelectionValidator; - private boolean fCanceled= false; - private IProgressMonitor fProgressMonitor; - private Position[] fPositions; - - public OccurrencesFinderJob(IDocument document, Position[] positions, ISelection selection) { - //TODO: Refactor job name to resource string somewhere - super("OccurrencesFinderJob"); - fDocument= document; - fSelection= selection; - fPositions= positions; - - if (getSelectionProvider() instanceof ISelectionValidator) - fPostSelectionValidator= (ISelectionValidator)getSelectionProvider(); - } - - // cannot use cancel() because it is declared final - void doCancel() { - fCanceled= true; - cancel(); - } - - private boolean isCanceled() { - return fCanceled || fProgressMonitor.isCanceled() - || fPostSelectionValidator != null && !(fPostSelectionValidator.isValid(fSelection) || fForcedMarkOccurrencesSelection == fSelection) - || LinkedModeModel.hasInstalledModel(fDocument); - } - - /* - * @see Job#run(org.eclipse.core.runtime.IProgressMonitor) - */ - public IStatus run(IProgressMonitor progressMonitor) { - - fProgressMonitor= progressMonitor; - - if (isCanceled()) - return Status.CANCEL_STATUS; - - ITextViewer textViewer= getViewer(); - if (textViewer == null) - return Status.CANCEL_STATUS; - - IDocument document= textViewer.getDocument(); - if (document == null) - return Status.CANCEL_STATUS; - - IDocumentProvider documentProvider= getDocumentProvider(); - if (documentProvider == null) - return Status.CANCEL_STATUS; - - IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); - if (annotationModel == null) - return Status.CANCEL_STATUS; - - // Add occurrence annotations - int length= fPositions.length; - Map annotationMap= new HashMap(length); - for (int i= 0; i < length; i++) { - - if (isCanceled()) - return Status.CANCEL_STATUS; - - String message; - Position position= fPositions[i]; - - // Create & add annotation - try { - message= document.get(position.offset, position.length); - } catch (BadLocationException ex) { - // Skip this match - continue; - } - annotationMap.put( - new Annotation("org.eclipse.jdt.ui.occurrences", false, message), //$NON-NLS-1$ - position); - } - - if (isCanceled()) - return Status.CANCEL_STATUS; - - synchronized (getLockObject(annotationModel)) { - if (annotationModel instanceof IAnnotationModelExtension) { - ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap); - } else { - removeOccurrenceAnnotations(); - Iterator iter= annotationMap.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry mapEntry= (Map.Entry)iter.next(); - annotationModel.addAnnotation((Annotation)mapEntry.getKey(), (Position)mapEntry.getValue()); - } - } - fOccurrenceAnnotations= (Annotation[])annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]); - } - - return Status.OK_STATUS; - } - } - - /** - * Updates the occurrences annotations based - * on the current selection. - * - * @param selection the text selection - */ - protected void updateOccurrenceAnnotations(ITextSelection selection) { - - if (fOccurrencesFinderJob != null) - fOccurrencesFinderJob.cancel(); - - if (!fMarkOccurrenceAnnotations) - return; - - if (selection == null) - return; - - IDocument document= getDocumentProvider().getDocument(getEditorInput()); - String source = document.get(); - - // Search for occurrences - fOccurrencesFinder.initialize(source, selection.getOffset(), selection.getLength()); - List<Position> matches = fOccurrencesFinder.perform(); - - if (matches.isEmpty()) { - if (!fStickyOccurrenceAnnotations) { - removeOccurrenceAnnotations(); - } - return; - } else { - // Convert to array - //TODO: Update IOccurrencesFinder interface to return an array of Position - Position[] positions = new Position[matches.size()]; - int i = 0; - for (Position match : matches) { - positions[i++] = match; - } - - // Mark occurrences - fOccurrencesFinderJob= new OccurrencesFinderJob(document, positions, selection); - //fOccurrencesFinderJob.setPriority(Job.DECORATE); - //fOccurrencesFinderJob.setSystem(true); - //fOccurrencesFinderJob.schedule(); - fOccurrencesFinderJob.run(new NullProgressMonitor()); - } - } - - protected void installOccurrencesFinder(boolean forceUpdate) { - fMarkOccurrenceAnnotations= true; - - fOccurrencesFinder = new DefaultOccurrencesFinder(); - - fPostSelectionListener = new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - updateOccurrenceAnnotations((ITextSelection)event.getSelection()); - } - }; - - IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider)getSourceViewer().getSelectionProvider(); - postSelectionProvider.addPostSelectionChangedListener(fPostSelectionListener); - - if (forceUpdate && getSelectionProvider() != null) { - fForcedMarkOccurrencesSelection= getSelectionProvider().getSelection(); - updateOccurrenceAnnotations((ITextSelection)fForcedMarkOccurrencesSelection); - } - - if (fOccurrencesFinderJobCanceler == null) { - fOccurrencesFinderJobCanceler= new OccurrencesFinderJobCanceler(); - fOccurrencesFinderJobCanceler.install(); - } - } - - protected void uninstallOccurrencesFinder() { - fMarkOccurrenceAnnotations= false; - - if (fOccurrencesFinderJob != null) { - fOccurrencesFinderJob.cancel(); - fOccurrencesFinderJob= null; - } - - if (fOccurrencesFinderJobCanceler != null) { - fOccurrencesFinderJobCanceler.uninstall(); - fOccurrencesFinderJobCanceler= null; - } - - if (fPostSelectionListener != null) { - IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider)getSourceViewer().getSelectionProvider(); - postSelectionProvider.removePostSelectionChangedListener(fPostSelectionListener); - fPostSelectionListener = null; - } - - removeOccurrenceAnnotations(); - } - - protected boolean isMarkingOccurrences() { - return fMarkOccurrenceAnnotations; - } - -// boolean markOccurrencesOfType(IBinding binding) { -// -// if (binding == null) -// return false; -// -// int kind= binding.getKind(); -// -// if (fMarkTypeOccurrences && kind == IBinding.TYPE) -// return true; -// -// if (fMarkMethodOccurrences && kind == IBinding.METHOD) -// return true; -// -// if (kind == IBinding.VARIABLE) { -// IVariableBinding variableBinding= (IVariableBinding)binding; -// if (variableBinding.isField()) { -// int constantModifier= IModifierConstants.ACC_STATIC | IModifierConstants.ACC_FINAL; -// boolean isConstant= (variableBinding.getModifiers() & constantModifier) == constantModifier; -// if (isConstant) -// return fMarkConstantOccurrences; -// else -// return fMarkFieldOccurrences; -// } -// -// return fMarkLocalVariableypeOccurrences; -// } -// -// return false; -// } - - void removeOccurrenceAnnotations() { - fMarkOccurrenceModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; - - IDocumentProvider documentProvider= getDocumentProvider(); - if (documentProvider == null) - return; - - IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); - if (annotationModel == null || fOccurrenceAnnotations == null) - return; - - synchronized (getLockObject(annotationModel)) { - if (annotationModel instanceof IAnnotationModelExtension) { - ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, null); - } else { - for (int i= 0, length= fOccurrenceAnnotations.length; i < length; i++) - annotationModel.removeAnnotation(fOccurrenceAnnotations[i]); - } - fOccurrenceAnnotations= null; - } - } - - /** - * Returns the lock object for the given annotation model. - * - * @param annotationModel the annotation model - * @return the annotation model's lock object - * @since 3.0 - */ - private Object getLockObject(IAnnotationModel annotationModel) { - if (annotationModel instanceof ISynchronizable) { - Object lock= ((ISynchronizable)annotationModel).getLockObject(); - if (lock != null) - return lock; - } - return annotationModel; - } - } \ 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...> - 2006-07-20 00:07:31
|
Revision: 1524 Author: cawilliams Date: 2006-07-19 17:07:27 -0700 (Wed, 19 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1524&view=rev Log Message: ----------- eliminate problem where UI preference pages were having a reconciler attached which would throw NullPointer exceptions Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2006-07-20 00:06:30 UTC (rev 1523) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2006-07-20 00:07:27 UTC (rev 1524) @@ -375,15 +375,18 @@ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer) */ public IReconciler getReconciler(ISourceViewer sourceViewer) { - RubyReconciler reconciler = new RubyReconciler(fTextEditor, new RubyReconcilingStrategy( - (RubyAbstractEditor) fTextEditor), true); - reconciler.setIsIncrementalReconciler(false); - // TODO Uncomment when we move to Eclipse 3.2 - // ECLIPSE 3.2 - //reconciler.setIsAllowedToModifyDocument(false); - reconciler.setProgressMonitor(new NullProgressMonitor()); - reconciler.setDelay(500); - return reconciler; + final ITextEditor editor = getEditor(); + if (editor != null && editor.isEditable()) { + RubyReconciler reconciler = new RubyReconciler(fTextEditor, + new RubyReconcilingStrategy( + (RubyAbstractEditor) fTextEditor), true); + reconciler.setIsIncrementalReconciler(false); + reconciler.setIsAllowedToModifyDocument(false); + reconciler.setProgressMonitor(new NullProgressMonitor()); + reconciler.setDelay(500); + return reconciler; + } + return null; } private IRubyProject getProject() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <caw...@us...> - 2006-07-20 00:06:42
|
Revision: 1523 Author: cawilliams Date: 2006-07-19 17:06:30 -0700 (Wed, 19 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1523&view=rev Log Message: ----------- Add preference pages to UI to allow users to control mark occurrences behavior Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/plugin.properties branches/type_inferrence/trunk/org.rubypeople.rdt.ui/plugin.xml branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.java branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.properties branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/PreferenceConstants.java Added Paths: ----------- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/MarkOccurrencesConfigurationBlock.java branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/MarkOccurrencesPreferencePage.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.ui/plugin.properties =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/plugin.properties 2006-07-19 23:21:17 UTC (rev 1522) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.ui/plugin.properties 2006-07-20 00:06:30 UTC (rev 1523) @@ -50,6 +50,7 @@ preferenceKeywords.syntaxcoloring=Ruby editor colors semantic coloring highlighting Rdoc html links tags multi line single line comment task tag method invocation static field annotation autoboxing unboxing boxing constant deprecated field keywords local variable operators brackets strings type variable inherited method declaration preferenceKeywords.templates=Ruby editor templates snippet macros preferenceKeywords.folding=Ruby editor folding section comment comments header method import inner type +preferenceKeywords.markoccurrences=Ruby editor occurrence mark highlight type method constant field exception PerspectiveRuby.name=Ruby @@ -70,6 +71,7 @@ editorSyntaxColoringPage=Syntax Coloring editorFoldingPage=Folding editorTypingPage=Typing +editorMarkOccurrencesPage=Mark Occurrences EditorRubyFile.name=Ruby Editor EditorRubyFile.extension=rb, rbw, cgi, fcgi, rake, rjs, rxml Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.ui/plugin.xml =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/plugin.xml 2006-07-19 23:21:17 UTC (rev 1522) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.ui/plugin.xml 2006-07-20 00:06:30 UTC (rev 1523) @@ -80,6 +80,13 @@ id="org.rubypeople.rdt.ui.preferences.SmartTypingPreferencePage"> <keywordReference id="org.rubypeople.rdt.ui.smarttyping"/> </page> + <page + name="%editorMarkOccurrencesPage" + category="org.rubypeople.rdt.ui.preferences.PreferencePageRubyEditor" + class="org.rubypeople.rdt.internal.ui.preferences.MarkOccurrencesPreferencePage" + id="org.rubypeople.rdt.ui.preferences.MarkOccurrencesPreferencePage"> + <keywordReference id="org.rubypeople.rdt.ui.markoccurrences"/> + </page> </extension> <!-- =========================================================================== --> <!-- Ruby Perspective --> @@ -333,6 +340,9 @@ <keyword label="%preferenceKeywords.folding" id="org.rubypeople.rdt.ui.folding"/> + <keyword + label="%preferenceKeywords.markoccurrences" + id="org.rubypeople.rdt.ui.markoccurrences"/> </extension> <extension point="org.eclipse.ui.views"> Added: branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/MarkOccurrencesConfigurationBlock.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/MarkOccurrencesConfigurationBlock.java (rev 0) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/MarkOccurrencesConfigurationBlock.java 2006-07-20 00:06:30 UTC (rev 1523) @@ -0,0 +1,232 @@ +/******************************************************************************* + * 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.preferences; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.text.Assert; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.rubypeople.rdt.internal.ui.dialogs.StatusInfo; +import org.rubypeople.rdt.internal.ui.util.PixelConverter; +import org.rubypeople.rdt.ui.PreferenceConstants; + +/** + * Configures Ruby Editor mark occurrences preferences. + * + * @since 0.9.0 + */ +class MarkOccurrencesConfigurationBlock implements IPreferenceConfigurationBlock { + + private OverlayPreferenceStore fStore; + + + private Map fCheckBoxes= new HashMap(); + private SelectionListener fCheckBoxListener= new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + Button button= (Button) e.widget; + fStore.setValue((String) fCheckBoxes.get(button), button.getSelection()); + } + }; + + /** + * List of master/slave listeners when there's a dependency. + * + * @see #createDependency(Button, String, Control) + * @since 3.0 + */ + private ArrayList fMasterSlaveListeners= new ArrayList(); + + private StatusInfo fStatus; + + public MarkOccurrencesConfigurationBlock(OverlayPreferenceStore store) { + Assert.isNotNull(store); + fStore= store; + + fStore.addKeys(createOverlayStoreKeys()); + } + + private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() { + + ArrayList overlayKeys= new ArrayList(); + + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_OCCURRENCES)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_STICKY_OCCURRENCES)); + + OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; + overlayKeys.toArray(keys); + return keys; + } + + /** + * Creates page for mark occurrences preferences. + * + * @param parent the parent composite + * @return the control for the preference page + */ + public Control createControl(Composite parent) { + + Composite composite= new Composite(parent, SWT.NONE); + GridLayout layout= new GridLayout(); + layout.numColumns= 1; + composite.setLayout(layout); + + String label; + + label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markOccurrences; + Button master= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_OCCURRENCES, 0); + + label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markTypeOccurrences; + Button slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES, 0); + createDependency(master, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, slave); + + label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodOccurrences; + slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, 0); + createDependency(master, PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, slave); + + label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markConstantOccurrences; + slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, 0); + createDependency(master, PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, slave); + + label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markFieldOccurrences; + slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, 0); + createDependency(master, PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, slave); + + label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markLocalVariableOccurrences; + slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, 0); + createDependency(master, PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, slave); + + label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodExitPoints; + slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, 0); + createDependency(master, PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, slave); + + addFiller(composite); + + label= PreferencesMessages.MarkOccurrencesConfigurationBlock_stickyOccurrences; + slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, 0); + createDependency(master, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, slave); + + return composite; + } + + private void addFiller(Composite composite) { + PixelConverter pixelConverter= new PixelConverter(composite); + + Label filler= new Label(composite, SWT.LEFT ); + GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gd.horizontalSpan= 2; + gd.heightHint= pixelConverter.convertHeightInCharsToPixels(1) / 2; + filler.setLayoutData(gd); + } + + private Button addCheckBox(Composite parent, String label, String key, int indentation) { + Button checkBox= new Button(parent, SWT.CHECK); + checkBox.setText(label); + + GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + gd.horizontalIndent= indentation; + gd.horizontalSpan= 2; + checkBox.setLayoutData(gd); + checkBox.addSelectionListener(fCheckBoxListener); + + fCheckBoxes.put(checkBox, key); + + return checkBox; + } + + private void createDependency(final Button master, String masterKey, final Control slave) { + indent(slave); + boolean masterState= fStore.getBoolean(masterKey); + slave.setEnabled(masterState); + SelectionListener listener= new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + slave.setEnabled(master.getSelection()); + } + + public void widgetDefaultSelected(SelectionEvent e) {} + }; + master.addSelectionListener(listener); + fMasterSlaveListeners.add(listener); + } + + private static void indent(Control control) { + GridData gridData= new GridData(); + gridData.horizontalIndent= 20; + control.setLayoutData(gridData); + } + + public void initialize() { + initializeFields(); + } + + void initializeFields() { + + Iterator iter= fCheckBoxes.keySet().iterator(); + while (iter.hasNext()) { + Button b= (Button) iter.next(); + String key= (String) fCheckBoxes.get(b); + b.setSelection(fStore.getBoolean(key)); + } + + // Update slaves + iter= fMasterSlaveListeners.iterator(); + while (iter.hasNext()) { + SelectionListener listener= (SelectionListener)iter.next(); + listener.widgetSelected(null); + } + + } + + public void performOk() { + } + + public void performDefaults() { + restoreFromPreferences(); + initializeFields(); + } + + private void restoreFromPreferences() { + + } + + IStatus getStatus() { + if (fStatus == null) + fStatus= new StatusInfo(); + return fStatus; + } + + /* + * @see org.eclipse.jdt.internal.ui.preferences.IPreferenceConfigurationBlock#dispose() + * @since 3.0 + */ + public void dispose() { + } +} Added: branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/MarkOccurrencesPreferencePage.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/MarkOccurrencesPreferencePage.java (rev 0) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/MarkOccurrencesPreferencePage.java 2006-07-20 00:06:30 UTC (rev 1523) @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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.preferences; + + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds; +import org.rubypeople.rdt.internal.ui.RubyPlugin; + + +/** + * The page for setting the editor options. + */ +public final class MarkOccurrencesPreferencePage extends AbstractConfigurationBlockPreferencePage { + + /* + * @see org.eclipse.ui.internal.editors.text.AbstractConfigureationBlockPreferencePage#getHelpId() + */ + protected String getHelpId() { + return IRubyHelpContextIds.RUBY_EDITOR_PREFERENCE_PAGE; + } + + /* + * @see org.eclipse.ui.internal.editors.text.AbstractConfigurationBlockPreferencePage#setDescription() + */ + protected void setDescription() { + String description= PreferencesMessages.MarkOccurrencesConfigurationBlock_title; + setDescription(description); + } + + /* + * @see org.org.eclipse.ui.internal.editors.text.AbstractConfigurationBlockPreferencePage#setPreferenceStore() + */ + protected void setPreferenceStore() { + setPreferenceStore(RubyPlugin.getDefault().getPreferenceStore()); + } + + + protected Label createDescriptionLabel(Composite parent) { + return null; // no description for new look. + } + + /* + * @see org.eclipse.ui.internal.editors.text.AbstractConfigureationBlockPreferencePage#createConfigurationBlock(org.eclipse.ui.internal.editors.text.OverlayPreferenceStore) + */ + protected IPreferenceConfigurationBlock createConfigurationBlock(OverlayPreferenceStore overlayPreferenceStore) { + return new MarkOccurrencesConfigurationBlock(overlayPreferenceStore); + } + +} Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.java 2006-07-19 23:21:17 UTC (rev 1522) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.java 2006-07-20 00:06:30 UTC (rev 1523) @@ -138,6 +138,15 @@ public static String ProblemSeveritiesConfigurationBlock_pb_unused_private_label; public static String ProblemSeveritiesConfigurationBlock_pb_unnecessary_else_label; public static String RubyEditorPreferencePage_background_color; + public static String MarkOccurrencesConfigurationBlock_markOccurrences; + public static String MarkOccurrencesConfigurationBlock_markTypeOccurrences; + public static String MarkOccurrencesConfigurationBlock_markMethodOccurrences; + public static String MarkOccurrencesConfigurationBlock_markConstantOccurrences; + public static String MarkOccurrencesConfigurationBlock_markFieldOccurrences; + public static String MarkOccurrencesConfigurationBlock_markLocalVariableOccurrences; + public static String MarkOccurrencesConfigurationBlock_markMethodExitPoints; + public static String MarkOccurrencesConfigurationBlock_stickyOccurrences; + public static String MarkOccurrencesConfigurationBlock_title; static { NLS.initializeMessages(BUNDLE_NAME, PreferencesMessages.class); Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.properties =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.properties 2006-07-19 23:21:17 UTC (rev 1522) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/PreferencesMessages.properties 2006-07-20 00:06:30 UTC (rev 1523) @@ -157,3 +157,14 @@ ProblemSeveritiesConfigurationBlock_pb_unused_parameter_label=Parameter is never read: ProblemSeveritiesConfigurationBlock_pb_unused_private_label=Unused local or private member: ProblemSeveritiesConfigurationBlock_pb_unnecessary_else_label=Unnecessary else statement: + +MarkOccurrencesConfigurationBlock_title= &Mark Occurrences +MarkOccurrencesConfigurationBlock_markOccurrences= Mark &occurrences of the selected element in the current file. +MarkOccurrencesConfigurationBlock_markTypeOccurrences= &Types +MarkOccurrencesConfigurationBlock_markMethodOccurrences= &Methods +MarkOccurrencesConfigurationBlock_markConstantOccurrences= &Constants +MarkOccurrencesConfigurationBlock_markFieldOccurrences= &Non-constant fields +MarkOccurrencesConfigurationBlock_markLocalVariableOccurrences= &Local variables +MarkOccurrencesConfigurationBlock_markMethodExitPoints= Method &exits +MarkOccurrencesConfigurationBlock_stickyOccurrences= &Keep marks when the selection changes + Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/PreferenceConstants.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/PreferenceConstants.java 2006-07-19 23:21:17 UTC (rev 1522) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/PreferenceConstants.java 2006-07-20 00:06:30 UTC (rev 1523) @@ -486,6 +486,91 @@ */ public final static String EDITOR_CLOSE_BRACES= "closeBraces"; //$NON-NLS-1$ + + /** + * A named preference that controls whether occurrences are marked in the editor. + * <p> + * Value is of type <code>Boolean</code>. + * </p> + * + * @since 0.9.0 + */ + public static final String EDITOR_MARK_OCCURRENCES= "markOccurrences"; //$NON-NLS-1$ + + /** + * A named preference that controls whether occurrences are sticky in the editor. + * <p> + * Value is of type <code>Boolean</code>. + * </p> + * + * @since 0.9.0 + */ + public static final String EDITOR_STICKY_OCCURRENCES= "stickyOccurrences"; //$NON-NLS-1$ + + /** + * A named preference that controls whether type occurrences are marked. + * Only valid if {@link #EDITOR_MARK_OCCURRENCES} is <code>true</code>. + * <p> + * Value is of type <code>Boolean</code>. + * </p> + * + * @since 0.9.0 + */ + public static final String EDITOR_MARK_TYPE_OCCURRENCES= "markTypeOccurrences"; //$NON-NLS-1$ + + /** + * A named preference that controls whether method occurrences are marked. + * Only valid if {@link #EDITOR_MARK_OCCURRENCES} is <code>true</code>. + * <p> + * Value is of type <code>Boolean</code>. + * </p> + * + * @since 0.9.0 + */ + public static final String EDITOR_MARK_METHOD_OCCURRENCES= "markMethodOccurrences"; //$NON-NLS-1$ + /** + * A named preference that controls whether non-constant field occurrences are marked. + * Only valid if {@link #EDITOR_MARK_OCCURRENCES} is <code>true</code>. + * <p> + * Value is of type <code>Boolean</code>. + * </p> + * + * @since 0.9.0 + */ + public static final String EDITOR_MARK_FIELD_OCCURRENCES= "markFieldOccurrences"; //$NON-NLS-1$ + /** + * A named preference that controls whether constant (static final) occurrences are marked. + * Only valid if {@link #EDITOR_MARK_OCCURRENCES} is <code>true</code>. + * <p> + * Value is of type <code>Boolean</code>. + * </p> + * + * @since 0.9.0 + */ + public static final String EDITOR_MARK_CONSTANT_OCCURRENCES= "markConstantOccurrences"; //$NON-NLS-1$ + + /** + * A named preference that controls whether local variable occurrences are marked. + * Only valid if {@link #EDITOR_MARK_OCCURRENCES} is <code>true</code>. + * <p> + * Value is of type <code>Boolean</code>. + * </p> + * + * @since 0.9.0 + */ + public static final String EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES= "markLocalVariableOccurrences"; //$NON-NLS-1$ + + /** + * A named preference that controls whether method exit points are marked. + * Only valid if {@link #EDITOR_MARK_OCCURRENCES} is <code>true</code>. + * <p> + * Value is of type <code>Boolean</code>. + * </p> + * + * @since 0.9.0 + */ + public static final String EDITOR_MARK_METHOD_EXIT_POINTS= "markMethodExitPoints"; //$NON-NLS-1$ + public static void initializeDefaultValues(IPreferenceStore store) { store.setDefault(PreferenceConstants.EDITOR_SHOW_SEGMENTS, false); @@ -551,6 +636,16 @@ store.setDefault(PreferenceConstants.EDITOR_CLOSE_STRINGS, true); store.setDefault(PreferenceConstants.EDITOR_CLOSE_BRACKETS, true); store.setDefault(PreferenceConstants.EDITOR_CLOSE_BRACES, true); + + // mark occurrences + store.setDefault(PreferenceConstants.EDITOR_MARK_OCCURRENCES, true); + store.setDefault(PreferenceConstants.EDITOR_STICKY_OCCURRENCES, true); + store.setDefault(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES, true); + store.setDefault(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, true); + store.setDefault(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, true); + store.setDefault(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, true); + store.setDefault(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, true); + store.setDefault(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, true); } private static String getDefaultPath(String programName) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <caw...@us...> - 2006-07-19 23:21:22
|
Revision: 1522 Author: cawilliams Date: 2006-07-19 16:21:17 -0700 (Wed, 19 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1522&view=rev Log Message: ----------- add dependency on org.eclipse.jface.text Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/plugin.xml Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/plugin.xml =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/plugin.xml 2006-07-19 05:47:24 UTC (rev 1521) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/plugin.xml 2006-07-19 23:21:17 UTC (rev 1522) @@ -19,6 +19,7 @@ <import plugin="org.rubypeople.eclipse.shams"/> <import plugin="org.rubypeople.eclipse.testutils"/> <import plugin="org.jruby"/> + <import plugin="org.eclipse.jface.text"/> </requires> </plugin> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <jas...@us...> - 2006-07-19 05:47:34
|
Revision: 1521 Author: jasonpmorrison Date: 2006-07-18 22:47:24 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1521&view=rev Log Message: ----------- Glued up the Mark Occurrence code so it is actually invoked! Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java 2006-07-19 05:42:24 UTC (rev 1520) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java 2006-07-19 05:47:24 UTC (rev 1521) @@ -2,7 +2,10 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.HashMap; import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Stack; import org.eclipse.core.resources.IMarker; @@ -11,9 +14,13 @@ import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Preferences; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; @@ -25,12 +32,17 @@ import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentExtension; +import org.eclipse.jface.text.IDocumentExtension4; import org.eclipse.jface.text.IDocumentListener; import org.eclipse.jface.text.ILineTracker; import org.eclipse.jface.text.IPositionUpdater; import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ISelectionValidator; +import org.eclipse.jface.text.ISynchronizable; +import org.eclipse.jface.text.ITextInputListener; 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.ITextViewerExtension5; import org.eclipse.jface.text.ITypedRegion; @@ -46,6 +58,7 @@ import org.eclipse.jface.text.link.LinkedModeUI.IExitPolicy; import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.IAnnotationModelExtension; import org.eclipse.jface.text.source.ICharacterPairMatcher; import org.eclipse.jface.text.source.IOverviewRuler; import org.eclipse.jface.text.source.ISourceViewer; @@ -54,9 +67,12 @@ import org.eclipse.jface.text.source.projection.ProjectionSupport; import org.eclipse.jface.text.source.projection.ProjectionViewer; import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.IPostSelectionProvider; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.custom.VerifyKeyListener; @@ -67,9 +83,12 @@ import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPartListener2; import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWindowListener; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.SelectionEnabler; import org.eclipse.ui.actions.ActionContext; import org.eclipse.ui.actions.ActionGroup; @@ -77,6 +96,7 @@ import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.ui.texteditor.AnnotationPreference; import org.eclipse.ui.texteditor.ContentAssistAction; +import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.IEditorStatusLine; import org.eclipse.ui.texteditor.ITextEditorActionConstants; import org.eclipse.ui.texteditor.MarkerAnnotation; @@ -87,6 +107,8 @@ import org.rubypeople.rdt.core.IRubyScript; import org.rubypeople.rdt.core.RubyModelException; import org.rubypeople.rdt.internal.corext.util.RubyModelUtil; +import org.rubypeople.rdt.internal.ti.DefaultOccurrencesFinder; +import org.rubypeople.rdt.internal.ti.IOccurrencesFinder; import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds; import org.rubypeople.rdt.internal.ui.RubyPlugin; import org.rubypeople.rdt.internal.ui.RubyUIMessages; @@ -159,7 +181,108 @@ private FoldingActionGroup fFoldingGroup; private BracketInserter fBracketInserter = new BracketInserter(); + + /** + * Holds the current occurrence annotations. + * @since 3.0 + */ + private Annotation[] fOccurrenceAnnotations= null; + /** + * Tells whether all occurrences of the element at the + * current caret location are automatically marked in + * this editor. + * @since 3.0 + */ + private boolean fMarkOccurrenceAnnotations; + /** + * Tells whether the occurrence annotations are sticky + * i.e. whether they stay even if there's no valid Java + * element at the current caret position. + * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. + * @since 3.0 + */ + private boolean fStickyOccurrenceAnnotations; +// /** +// * Tells whether to mark type occurrences in this editor. +// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. +// * @since 3.0 +// */ +// private boolean fMarkTypeOccurrences; +// /** +// * Tells whether to mark method occurrences in this editor. +// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. +// * @since 3.0 +// */ +// private boolean fMarkMethodOccurrences; +// /** +// * Tells whether to mark constant occurrences in this editor. +// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. +// * @since 3.0 +// */ +// private boolean fMarkConstantOccurrences; +// /** +// * Tells whether to mark field occurrences in this editor. +// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. +// * @since 3.0 +// */ +// private boolean fMarkFieldOccurrences; +// /** +// * Tells whether to mark local variable occurrences in this editor. +// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. +// * @since 3.0 +// */ +// private boolean fMarkLocalVariableypeOccurrences; +// /** +// * Tells whether to mark exception occurrences in this editor. +// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. +// * @since 3.0 +// */ +// private boolean fMarkExceptions; +// /** +// * Tells whether to mark method exits in this editor. +// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. +// * @since 3.0 +// */ +// private boolean fMarkMethodExitPoints; +// +// /** +// * Tells whether to mark targets of <code>break</code> and <code>continue</code> statements in this editor. +// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. +// * @since 3.2 +// */ +// private boolean fMarkBreakContinueTargets; +// +// /** +// * Tells whether to mark implementors in this editor. +// * Only valid if {@link #fMarkOccurrenceAnnotations} is <code>true</code>. +// * @since 3.1 +// */ +// private boolean fMarkImplementors; + /** + * The selection used when forcing occurrence marking + * through code. + * @since 3.0 + */ + private ISelection fForcedMarkOccurrencesSelection; + /** + * The document modification stamp at the time when the last + * occurrence marking took place. + * @since 3.1 + */ + //TODO: Do I need to use this? + private long fMarkOccurrenceModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; + /** + * The internal shell activation listener for updating occurrences. + */ + private ActivationListener fActivationListener= new ActivationListener(); + private ISelectionChangedListener fPostSelectionListener; + private OccurrencesFinderJob fOccurrencesFinderJob; + /** The occurrences finder job canceler */ + private OccurrencesFinderJobCanceler fOccurrencesFinderJobCanceler; + private IOccurrencesFinder fOccurrencesFinder; + + public RubyEditor() { super(); setDocumentProvider(RubyPlugin.getDefault().getRubyDocumentProvider()); @@ -289,7 +412,31 @@ fBracketInserter.setCloseBracesEnabled(closeBraces); fBracketInserter.setCloseStringsEnabled(closeStrings); ((ITextViewerExtension) sourceViewer).prependVerifyKeyListener(fBracketInserter); + + //TODO: Pull these from prefs rather than hardcoded true values + fMarkOccurrenceAnnotations = true; + fStickyOccurrenceAnnotations = false; +// setPreferenceStore(store); +// JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools(); +// setSourceViewerConfiguration(new JavaSourceViewerConfiguration(textTools.getColorManager(), store, this, IJavaPartitions.JAVA_PARTITIONING)); +// fMarkOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_MARK_OCCURRENCES); +// fStickyOccurrenceAnnotations= store.getBoolean(PreferenceConstants.EDITOR_STICKY_OCCURRENCES); +// fMarkTypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES); +// fMarkMethodOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES); +// fMarkConstantOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES); +// fMarkFieldOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES); +// fMarkLocalVariableypeOccurrences= store.getBoolean(PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES); +// fMarkExceptions= store.getBoolean(PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES); +// fMarkImplementors= store.getBoolean(PreferenceConstants.EDITOR_MARK_IMPLEMENTORS); +// fMarkMethodExitPoints= store.getBoolean(PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS); +// fMarkBreakContinueTargets= store.getBoolean(PreferenceConstants.EDITOR_MARK_BREAK_CONTINUE_TARGETS); } + + + if (fMarkOccurrenceAnnotations) + installOccurrencesFinder(false); + + PlatformUI.getWorkbench().addWindowListener(fActivationListener); } /** @@ -606,6 +753,16 @@ fProjectionSupport.dispose(); fProjectionSupport = null; } + + // cancel possible running computation + fMarkOccurrenceAnnotations= false; + uninstallOccurrencesFinder(); + + if (fActivationListener != null) { + PlatformUI.getWorkbench().removeWindowListener(fActivationListener); + fActivationListener= null; + } + super.dispose(); } @@ -1558,4 +1715,390 @@ public FoldingActionGroup getFoldingActionGroup() { return fFoldingGroup; } + + /** + * Internal activation listener. + * @since 3.0 + */ + private class ActivationListener implements IWindowListener { + + /* + * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow) + * @since 3.1 + */ + public void windowActivated(IWorkbenchWindow window) { + if (window == getEditorSite().getWorkbenchWindow() && fMarkOccurrenceAnnotations && isActivePart()) { + fForcedMarkOccurrencesSelection= getSelectionProvider().getSelection(); + updateOccurrenceAnnotations((ITextSelection)fForcedMarkOccurrencesSelection); + } + } + + /* + * @see org.eclipse.ui.IWindowListener#windowDeactivated(org.eclipse.ui.IWorkbenchWindow) + * @since 3.1 + */ + public void windowDeactivated(IWorkbenchWindow window) { + if (window == getEditorSite().getWorkbenchWindow() && fMarkOccurrenceAnnotations && isActivePart()) + removeOccurrenceAnnotations(); + } + + /* + * @see org.eclipse.ui.IWindowListener#windowClosed(org.eclipse.ui.IWorkbenchWindow) + * @since 3.1 + */ + public void windowClosed(IWorkbenchWindow window) { + } + + /* + * @see org.eclipse.ui.IWindowListener#windowOpened(org.eclipse.ui.IWorkbenchWindow) + * @since 3.1 + */ + public void windowOpened(IWorkbenchWindow window) { + } + } + + /** + * Cancels the occurrences finder job upon document changes. + * + * @since 3.0 + */ + class OccurrencesFinderJobCanceler implements IDocumentListener, ITextInputListener { + + public void install() { + ISourceViewer sourceViewer= getSourceViewer(); + if (sourceViewer == null) + return; + + StyledText text= sourceViewer.getTextWidget(); + if (text == null || text.isDisposed()) + return; + + sourceViewer.addTextInputListener(this); + + IDocument document= sourceViewer.getDocument(); + if (document != null) + document.addDocumentListener(this); + } + + public void uninstall() { + ISourceViewer sourceViewer= getSourceViewer(); + if (sourceViewer != null) + sourceViewer.removeTextInputListener(this); + + IDocumentProvider documentProvider= getDocumentProvider(); + if (documentProvider != null) { + IDocument document= documentProvider.getDocument(getEditorInput()); + if (document != null) + document.removeDocumentListener(this); + } + } + + + /* + * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent) + */ + public void documentAboutToBeChanged(DocumentEvent event) { + if (fOccurrencesFinderJob != null) + fOccurrencesFinderJob.doCancel(); + } + + /* + * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent) + */ + public void documentChanged(DocumentEvent event) { + } + + /* + * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument) + */ + public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { + if (oldInput == null) + return; + + oldInput.removeDocumentListener(this); + } + + /* + * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument) + */ + public void inputDocumentChanged(IDocument oldInput, IDocument newInput) { + if (newInput == null) + return; + newInput.addDocumentListener(this); + } + } + + /** + * Finds and marks occurrence annotations. + * + * @since 3.0 + */ + class OccurrencesFinderJob extends Job { + + private IDocument fDocument; + private ISelection fSelection; + private ISelectionValidator fPostSelectionValidator; + private boolean fCanceled= false; + private IProgressMonitor fProgressMonitor; + private Position[] fPositions; + + public OccurrencesFinderJob(IDocument document, Position[] positions, ISelection selection) { + //TODO: Refactor job name to resource string somewhere + super("OccurrencesFinderJob"); + fDocument= document; + fSelection= selection; + fPositions= positions; + + if (getSelectionProvider() instanceof ISelectionValidator) + fPostSelectionValidator= (ISelectionValidator)getSelectionProvider(); + } + + // cannot use cancel() because it is declared final + void doCancel() { + fCanceled= true; + cancel(); + } + + private boolean isCanceled() { + return fCanceled || fProgressMonitor.isCanceled() + || fPostSelectionValidator != null && !(fPostSelectionValidator.isValid(fSelection) || fForcedMarkOccurrencesSelection == fSelection) + || LinkedModeModel.hasInstalledModel(fDocument); + } + + /* + * @see Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + public IStatus run(IProgressMonitor progressMonitor) { + + fProgressMonitor= progressMonitor; + + if (isCanceled()) + return Status.CANCEL_STATUS; + + ITextViewer textViewer= getViewer(); + if (textViewer == null) + return Status.CANCEL_STATUS; + + IDocument document= textViewer.getDocument(); + if (document == null) + return Status.CANCEL_STATUS; + + IDocumentProvider documentProvider= getDocumentProvider(); + if (documentProvider == null) + return Status.CANCEL_STATUS; + + IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); + if (annotationModel == null) + return Status.CANCEL_STATUS; + + // Add occurrence annotations + int length= fPositions.length; + Map annotationMap= new HashMap(length); + for (int i= 0; i < length; i++) { + + if (isCanceled()) + return Status.CANCEL_STATUS; + + String message; + Position position= fPositions[i]; + + // Create & add annotation + try { + message= document.get(position.offset, position.length); + } catch (BadLocationException ex) { + // Skip this match + continue; + } + annotationMap.put( + new Annotation("org.eclipse.jdt.ui.occurrences", false, message), //$NON-NLS-1$ + position); + } + + if (isCanceled()) + return Status.CANCEL_STATUS; + + synchronized (getLockObject(annotationModel)) { + if (annotationModel instanceof IAnnotationModelExtension) { + ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap); + } else { + removeOccurrenceAnnotations(); + Iterator iter= annotationMap.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry mapEntry= (Map.Entry)iter.next(); + annotationModel.addAnnotation((Annotation)mapEntry.getKey(), (Position)mapEntry.getValue()); + } + } + fOccurrenceAnnotations= (Annotation[])annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]); + } + + return Status.OK_STATUS; + } + } + + /** + * Updates the occurrences annotations based + * on the current selection. + * + * @param selection the text selection + */ + protected void updateOccurrenceAnnotations(ITextSelection selection) { + + if (fOccurrencesFinderJob != null) + fOccurrencesFinderJob.cancel(); + + if (!fMarkOccurrenceAnnotations) + return; + + if (selection == null) + return; + + IDocument document= getDocumentProvider().getDocument(getEditorInput()); + String source = document.get(); + + // Search for occurrences + fOccurrencesFinder.initialize(source, selection.getOffset(), selection.getLength()); + List<Position> matches = fOccurrencesFinder.perform(); + + if (matches.isEmpty()) { + if (!fStickyOccurrenceAnnotations) { + removeOccurrenceAnnotations(); + } + return; + } else { + // Convert to array + //TODO: Update IOccurrencesFinder interface to return an array of Position + Position[] positions = new Position[matches.size()]; + int i = 0; + for (Position match : matches) { + positions[i++] = match; + } + + // Mark occurrences + fOccurrencesFinderJob= new OccurrencesFinderJob(document, positions, selection); + //fOccurrencesFinderJob.setPriority(Job.DECORATE); + //fOccurrencesFinderJob.setSystem(true); + //fOccurrencesFinderJob.schedule(); + fOccurrencesFinderJob.run(new NullProgressMonitor()); + } + } + + protected void installOccurrencesFinder(boolean forceUpdate) { + fMarkOccurrenceAnnotations= true; + + fOccurrencesFinder = new DefaultOccurrencesFinder(); + + fPostSelectionListener = new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + updateOccurrenceAnnotations((ITextSelection)event.getSelection()); + } + }; + + IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider)getSourceViewer().getSelectionProvider(); + postSelectionProvider.addPostSelectionChangedListener(fPostSelectionListener); + + if (forceUpdate && getSelectionProvider() != null) { + fForcedMarkOccurrencesSelection= getSelectionProvider().getSelection(); + updateOccurrenceAnnotations((ITextSelection)fForcedMarkOccurrencesSelection); + } + + if (fOccurrencesFinderJobCanceler == null) { + fOccurrencesFinderJobCanceler= new OccurrencesFinderJobCanceler(); + fOccurrencesFinderJobCanceler.install(); + } + } + + protected void uninstallOccurrencesFinder() { + fMarkOccurrenceAnnotations= false; + + if (fOccurrencesFinderJob != null) { + fOccurrencesFinderJob.cancel(); + fOccurrencesFinderJob= null; + } + + if (fOccurrencesFinderJobCanceler != null) { + fOccurrencesFinderJobCanceler.uninstall(); + fOccurrencesFinderJobCanceler= null; + } + + if (fPostSelectionListener != null) { + IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider)getSourceViewer().getSelectionProvider(); + postSelectionProvider.removePostSelectionChangedListener(fPostSelectionListener); + fPostSelectionListener = null; + } + + removeOccurrenceAnnotations(); + } + + protected boolean isMarkingOccurrences() { + return fMarkOccurrenceAnnotations; + } + +// boolean markOccurrencesOfType(IBinding binding) { +// +// if (binding == null) +// return false; +// +// int kind= binding.getKind(); +// +// if (fMarkTypeOccurrences && kind == IBinding.TYPE) +// return true; +// +// if (fMarkMethodOccurrences && kind == IBinding.METHOD) +// return true; +// +// if (kind == IBinding.VARIABLE) { +// IVariableBinding variableBinding= (IVariableBinding)binding; +// if (variableBinding.isField()) { +// int constantModifier= IModifierConstants.ACC_STATIC | IModifierConstants.ACC_FINAL; +// boolean isConstant= (variableBinding.getModifiers() & constantModifier) == constantModifier; +// if (isConstant) +// return fMarkConstantOccurrences; +// else +// return fMarkFieldOccurrences; +// } +// +// return fMarkLocalVariableypeOccurrences; +// } +// +// return false; +// } + + void removeOccurrenceAnnotations() { + fMarkOccurrenceModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; + + IDocumentProvider documentProvider= getDocumentProvider(); + if (documentProvider == null) + return; + + IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); + if (annotationModel == null || fOccurrenceAnnotations == null) + return; + + synchronized (getLockObject(annotationModel)) { + if (annotationModel instanceof IAnnotationModelExtension) { + ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, null); + } else { + for (int i= 0, length= fOccurrenceAnnotations.length; i < length; i++) + annotationModel.removeAnnotation(fOccurrenceAnnotations[i]); + } + fOccurrenceAnnotations= null; + } + } + + /** + * Returns the lock object for the given annotation model. + * + * @param annotationModel the annotation model + * @return the annotation model's lock object + * @since 3.0 + */ + private Object getLockObject(IAnnotationModel annotationModel) { + if (annotationModel instanceof ISynchronizable) { + Object lock= ((ISynchronizable)annotationModel).getLockObject(); + if (lock != null) + return lock; + } + return annotationModel; + } + } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
Revision: 1520 Author: jasonpmorrison Date: 2006-07-18 22:42:24 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1520&view=rev Log Message: ----------- IOccurrencesFinder and implementors updated to return List<Position> Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java 2006-07-19 05:42:12 UTC (rev 1519) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java 2006-07-19 05:42:24 UTC (rev 1520) @@ -8,6 +8,7 @@ import org.rubypeople.rdt.internal.ti.util.OffsetNodeLocator; import junit.framework.TestCase; +import org.eclipse.jface.text.Position; /** * Tests related to matching occurrences. @@ -21,21 +22,19 @@ public void setUp() { occurrencesFinder = new DefaultOccurrencesFinder(); } - - private Node parse(String source) { - return new RubyParser().parse(source); - } - private void assertOccurrencesEqual( String source, int offset, String matchName, int[][] offsets ) + private void assertOccurrencesEqual(String source, int offset, String matchName, int[][] offsets ) { - occurrencesFinder.initialize(parse(source), offset, 0); - List <ISourcePosition> occurrences = occurrencesFinder.perform(); + occurrencesFinder.initialize(source, offset, 0); + List <Position> occurrences = occurrencesFinder.perform(); assertEquals( offsets.length, occurrences.size() ); for ( int i = 0; i < offsets.length; i++ ) { - assertEquals( offsets[i][0], occurrences.get(i).getStartOffset() ); - assertEquals( offsets[i][1], occurrences.get(i).getEndOffset() ); - assertEquals( matchName, source.substring(occurrences.get(i).getStartOffset(), occurrences.get(i).getEndOffset())); + int start = occurrences.get(i).getOffset(); + int end = occurrences.get(i).getOffset() + occurrences.get(i).getLength(); + assertEquals( offsets[i][0], start ); + assertEquals( offsets[i][1], end ); + assertEquals( matchName, source.substring(start, end)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <jas...@us...> - 2006-07-19 05:42:21
|
Revision: 1519 Author: jasonpmorrison Date: 2006-07-18 22:42:12 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1519&view=rev Log Message: ----------- IOccurrencesFinder and implementors updated to return List<Position> Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java 2006-07-19 05:41:35 UTC (rev 1518) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java 2006-07-19 05:42:12 UTC (rev 1519) @@ -35,7 +35,7 @@ return null; } - public String initialize(Node root, int offset, int length) { + public String initialize(String source, int offset, int length) { // TODO Auto-generated method stub return null; } Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java 2006-07-19 05:41:35 UTC (rev 1518) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java 2006-07-19 05:42:12 UTC (rev 1519) @@ -1,8 +1,10 @@ package org.rubypeople.rdt.internal.ti; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import org.eclipse.jface.text.Position; import org.jruby.ast.ArgumentNode; import org.jruby.ast.BlockNode; import org.jruby.ast.CallNode; @@ -22,6 +24,8 @@ import org.jruby.ast.VCallNode; import org.jruby.lexer.yacc.ISourcePosition; import org.jruby.lexer.yacc.SourcePosition; +import org.jruby.lexer.yacc.SyntaxException; +import org.rubypeople.rdt.internal.core.parser.RubyParser; import org.rubypeople.rdt.internal.ti.util.FirstPrecursorNodeLocator; import org.rubypeople.rdt.internal.ti.util.INodeAcceptor; import org.rubypeople.rdt.internal.ti.util.OffsetNodeLocator; @@ -40,8 +44,16 @@ // Originating node; corresponds to cursor selection private Node orig; - public String initialize(Node root, int offset, int length) { - this.root = root; + public String initialize(String source, int offset, int length) { + + try { + this.root = (new RubyParser()).parse(source); + } + //TODO: Is there anything else the parsing could choke on that should be silently ignored with no markings? + catch (SyntaxException se) + { + this.root = null; + } this.orig = OffsetNodeLocator.Instance().getNodeAtOffset(root, offset); if ( orig.getPosition().getEndOffset() > offset + length ) { @@ -55,7 +67,10 @@ /** * Determines the kind of originating node, and collects occurrences accordingly */ - public List<ISourcePosition> perform() { + public List<Position> perform() { + // Mark no occurrences if root is null (AST couldn't be parsed correctly.) + if ( root == null ) return new LinkedList<Position>(); + // occurrences to return List<ISourcePosition> occurrences = new LinkedList<ISourcePosition>(); @@ -80,7 +95,14 @@ pushConstRefs( root, orig, occurrences ); } - return occurrences; + // Convert ISourcePosition to IPosition + List<Position> positions = new LinkedList<Position>(); + for (ISourcePosition occurrence : occurrences) { + Position position = new Position(occurrence.getStartOffset(),occurrence.getEndOffset() - occurrence.getStartOffset()); + positions.add(position); + } + + return positions; } // **************************************************************************** @@ -139,7 +161,7 @@ * @param occurrences */ private void pushLocalVarRefs( Node root, Node orig, List<ISourcePosition> occurrences ) { - System.out.println("Finding occurrences for a local variable " + orig.toString()); +// System.out.println("Finding occurrences for a local variable " + orig.toString()); // Find the search space Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() { @@ -180,7 +202,7 @@ * @param occurrences */ private void pushInstVarRefs( Node root, Node orig, List<ISourcePosition> occurrences ) { - System.out.println("Finding occurrences for an instance variable " + orig.toString() ); +// System.out.println("Finding occurrences for an instance variable " + orig.toString() ); Node searchSpace; Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java 2006-07-19 05:41:35 UTC (rev 1518) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java 2006-07-19 05:42:12 UTC (rev 1519) @@ -21,15 +21,15 @@ /** * - * @param root - * root AST Node + * @param source + * Ruby source to search for occurrences * @param offset * position in source where selection is * @param length * length of the selection * @return */ - public String initialize(Node root, int offset, int length); + public String initialize(String source, int offset, int length); /** * Returns a lit of AST Nodes back (which contain their associated This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <jas...@us...> - 2006-07-19 05:41:44
|
Revision: 1518 Author: jasonpmorrison Date: 2006-07-18 22:41:35 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1518&view=rev Log Message: ----------- rdt.core exports the rdt.internal.ti package Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/META-INF/MANIFEST.MF Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/META-INF/MANIFEST.MF =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/META-INF/MANIFEST.MF 2006-07-18 21:26:48 UTC (rev 1517) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/META-INF/MANIFEST.MF 2006-07-19 05:41:35 UTC (rev 1518) @@ -18,7 +18,8 @@ org.rubypeople.rdt.internal.core.parser, org.rubypeople.rdt.internal.core.symbols, org.rubypeople.rdt.internal.core.util, - org.rubypeople.rdt.internal.formatter + org.rubypeople.rdt.internal.formatter, + org.rubypeople.rdt.internal.ti Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources, org.eclipse.team.core, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <jas...@us...> - 2006-07-18 21:28:30
|
Revision: 1517 Author: jasonpmorrison Date: 2006-07-18 14:26:48 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1517&view=rev Log Message: ----------- Resolved dependency issue by: - Removed extranneous jruby.jar instances in /lib >From http://wiki.eclipse.org/index.php/PDE: - Added lib/jruby.jar to Bundle-ClassPath in MANIFEST.MF - Added lib/jruby.jar to .classpath as an exported lib Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/.classpath branches/type_inferrence/trunk/org.rubypeople.rdt.core/META-INF/MANIFEST.MF Added Paths: ----------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/lib/jruby.jar Removed Paths: ------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/lib/jruby-head-20060620.jar branches/type_inferrence/trunk/org.rubypeople.rdt.core/lib/jruby.jar-old Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/.classpath =================================================================== (Binary files differ) Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/META-INF/MANIFEST.MF =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/META-INF/MANIFEST.MF 2006-07-18 20:48:42 UTC (rev 1516) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/META-INF/MANIFEST.MF 2006-07-18 21:26:48 UTC (rev 1517) @@ -3,7 +3,8 @@ Bundle-Name: %Plugin.name Bundle-SymbolicName: org.rubypeople.rdt.core; singleton:=true Bundle-Version: 0.0.0 -Bundle-ClassPath: rdtcore.jar +Bundle-ClassPath: rdtcore.jar, + lib/jruby.jar Bundle-Activator: org.rubypeople.rdt.core.RubyCore Bundle-Vendor: %providerName Bundle-Localization: plugin Deleted: branches/type_inferrence/trunk/org.rubypeople.rdt.core/lib/jruby-head-20060620.jar =================================================================== (Binary files differ) Added: branches/type_inferrence/trunk/org.rubypeople.rdt.core/lib/jruby.jar =================================================================== (Binary files differ) Property changes on: branches/type_inferrence/trunk/org.rubypeople.rdt.core/lib/jruby.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Deleted: branches/type_inferrence/trunk/org.rubypeople.rdt.core/lib/jruby.jar-old =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <jas...@us...> - 2006-07-18 20:48:48
|
Revision: 1516 Author: jasonpmorrison Date: 2006-07-18 13:48:42 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1516&view=rev Log Message: ----------- Removed testing code from RubyParserCmd Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/RubyParserCmd.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/RubyParserCmd.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/RubyParserCmd.java 2006-07-18 00:49:09 UTC (rev 1515) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/RubyParserCmd.java 2006-07-18 20:48:42 UTC (rev 1516) @@ -13,7 +13,6 @@ import org.jruby.ast.Node; import org.jruby.lexer.yacc.SyntaxException; import org.rubypeople.eclipse.shams.resources.ShamFile; -import org.rubypeople.rdt.core.IRubyElement; import org.rubypeople.rdt.internal.core.DefaultWorkingCopyOwner; import org.rubypeople.rdt.internal.core.RubyProject; import org.rubypeople.rdt.internal.core.RubyScript; @@ -21,13 +20,6 @@ import org.rubypeople.rdt.internal.core.RubyScriptStructureBuilder; import org.rubypeople.rdt.internal.core.parser.RdtWarnings; import org.rubypeople.rdt.internal.core.parser.RubyParser; -import org.eclipse.core.resources.IFile; -import org.rubypeople.rdt.internal.ti.BindingVisitor; -//import org.rubypeople.rdt.internal.ti.ScopingVisitor; -import org.rubypeople.rdt.internal.ti.TypeInferenceVisitor; -import org.rubypeople.rdt.internal.ti.data.RubyClass; -import org.rubypeople.rdt.internal.ti.data.RubyCompletionKB; -import org.rubypeople.rdt.internal.ti.data.RubyMethod; public class RubyParserCmd { @@ -85,10 +77,10 @@ System.err.println(fileName); } } -// System.err.println(syntaxErrorFiles.size() + " Errors; " -// + okFiles.size()+" OK"); + System.err.println(syntaxErrorFiles.size() + " Errors; " + + okFiles.size()+" OK"); -// System.err.println("NewElements: " + elements.size()) ; + System.err.println("NewElements: " + elements.size()) ; } private void parseTree(File file) throws FileNotFoundException { @@ -110,31 +102,12 @@ private void parseOneFile(String file) { RubyParser parser = new RubyParser(new RdtWarnings()); try { -// Node node = parser.parse(new ShamFile(file), new FileReader(file)); - Node node = parser.parse("class Foo;def bar(x,y,z);foo=[x,y,z];end;end"); -// RubyScriptElementInfo unitInfo = new RubyScriptElementInfo() ; -// RubyScript script = new RubyScript(new RubyProject(), null, file, DefaultWorkingCopyOwner.PRIMARY ) ; -// RubyScriptStructureBuilder visitor = new RubyScriptStructureBuilder(script, unitInfo, elements); - BindingVisitor nscope_visitor = new BindingVisitor(node); -// TypeInferenceVisitor ti_visitor = new TypeInferenceVisitor(node); - + Node node = parser.parse(new ShamFile(file), new FileReader(file)); + RubyScriptElementInfo unitInfo = new RubyScriptElementInfo() ; + RubyScript script = new RubyScript(new RubyProject(), null, file, DefaultWorkingCopyOwner.PRIMARY ) ; + RubyScriptStructureBuilder visitor = new RubyScriptStructureBuilder(script, unitInfo, elements); if (node != null) { -// ScopingVisitor scoped_visitor = new ScopingVisitor(node); -// node.accept(ti_visitor); - node.accept(nscope_visitor); - System.out.println("done!"); - System.out.println("\nKB Summary:\n"); - - for ( RubyClass klass : RubyCompletionKB.Instance().getClasses() ) - { - System.out.println(klass.getName()); - for ( RubyMethod method : klass.getMethods() ) - { - System.out.println(" " + method.toString()); - } - } - -// node.accept(visitor); + node.accept(visitor); } else { System.out.println("Node is null for : " + file) ; @@ -145,8 +118,7 @@ syntaxErrorFiles.add(file); return ; } catch (Exception e) { - e.printStackTrace(); -// System.out.println(e.getClass().getName() + "->" + e.getMessage()); + System.out.println(e.getClass().getName() + "->" + e.getMessage()); syntaxErrorFiles.add(file); return ; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <caw...@us...> - 2006-07-18 00:49:13
|
Revision: 1515 Author: cawilliams Date: 2006-07-17 17:49:09 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1515&view=rev Log Message: ----------- add org.jruby plugin as part of the feature Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt-feature/feature.xml Modified: branches/type_inferrence/trunk/org.rubypeople.rdt-feature/feature.xml =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt-feature/feature.xml 2006-07-17 23:35:03 UTC (rev 1514) +++ branches/type_inferrence/trunk/org.rubypeople.rdt-feature/feature.xml 2006-07-18 00:49:09 UTC (rev 1515) @@ -246,7 +246,7 @@ <includes id="org.rubypeople.rdt.source" version="0.0.0"/> - + <requires> <import plugin="org.eclipse.core.resources"/> <import plugin="org.eclipse.debug.core"/> @@ -329,4 +329,11 @@ install-size="0" version="0.0.0"/> + <plugin + id="org.jruby" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + </feature> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <caw...@us...> - 2006-07-17 23:35:06
|
Revision: 1514 Author: cawilliams Date: 2006-07-17 16:35:03 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1514&view=rev Log Message: ----------- make lint visitor default to creating warnings if no preference is set (not errors!) Modified Paths: -------------- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RubyLintVisitor.java Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RubyLintVisitor.java =================================================================== --- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RubyLintVisitor.java 2006-07-17 23:31:33 UTC (rev 1513) +++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RubyLintVisitor.java 2006-07-17 23:35:03 UTC (rev 1514) @@ -133,9 +133,7 @@ private IProblem createProblem(String compilerOption, ISourcePosition position, String message) { String value = RubyCore.getOption(compilerOption); - if (value == null) - return new Error(position, message); - if (value.equals(RubyCore.WARNING)) + if ((value == null) || value.equals(RubyCore.WARNING)) return new Warning(position, message); if (value.equals(RubyCore.ERROR)) return new Error(position, message); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <caw...@us...> - 2006-07-17 23:31:39
|
Revision: 1513 Author: cawilliams Date: 2006-07-17 16:31:33 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1513&view=rev Log Message: ----------- add an OSGi bundle manifest, add dependency on org.jruby plugin Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.testunit/build.properties branches/type_inferrence/trunk/org.rubypeople.rdt.testunit/plugin.xml Added Paths: ----------- branches/type_inferrence/trunk/org.rubypeople.rdt.testunit/META-INF/ branches/type_inferrence/trunk/org.rubypeople.rdt.testunit/META-INF/MANIFEST.MF Added: branches/type_inferrence/trunk/org.rubypeople.rdt.testunit/META-INF/MANIFEST.MF =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.testunit/META-INF/MANIFEST.MF (rev 0) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.testunit/META-INF/MANIFEST.MF 2006-07-17 23:31:33 UTC (rev 1513) @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.rubypeople.rdt.testunit; singleton:=true +Bundle-Version: 0.0.0 +Bundle-ClassPath: testunit.jar +Bundle-Activator: org.rubypeople.rdt.testunit.TestunitPlugin +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Export-Package: org.rubypeople.rdt.testunit.views +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.debug.core, + org.eclipse.debug.ui, + org.rubypeople.rdt.launching, + org.rubypeople.rdt.core, + org.eclipse.core.resources, + org.rubypeople.rdt.ui, + org.rubypeople.rdt.debug.ui, + org.eclipse.ui.workbench.texteditor, + org.eclipse.text, + org.jruby +Eclipse-LazyStart: true Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.testunit/build.properties =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.testunit/build.properties 2006-07-17 23:31:05 UTC (rev 1512) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.testunit/build.properties 2006-07-17 23:31:33 UTC (rev 1513) @@ -4,4 +4,5 @@ testunit.jar,\ icons/,\ plugin.properties,\ - ruby/ + ruby/,\ + META-INF/ Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.testunit/plugin.xml =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.testunit/plugin.xml 2006-07-17 23:31:05 UTC (rev 1512) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.testunit/plugin.xml 2006-07-17 23:31:33 UTC (rev 1513) @@ -1,34 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.0"?> -<plugin - id="org.rubypeople.rdt.testunit" - name="%pluginName" - version="0.0.0" - provider-name="%providerName" - class="org.rubypeople.rdt.testunit.TestunitPlugin"> +<plugin> - <runtime> - <library name="testunit.jar"> - <export name="*"/> - </library> - </runtime> + <extension-point id="internalTestRunTabs" name="%testRunTabs.name" schema="schema/internal-testRunTabs.exsd"/> - <requires> - <import plugin="org.eclipse.ui"/> - <import plugin="org.eclipse.core.runtime"/> - <import plugin="org.eclipse.debug.core"/> - <import plugin="org.eclipse.debug.ui"/> - <import plugin="org.rubypeople.rdt.launching"/> - <import plugin="org.rubypeople.rdt.core"/> - <import plugin="org.eclipse.core.resources"/> - <import plugin="org.rubypeople.rdt.ui"/> - <import plugin="org.rubypeople.rdt.debug.ui"/> - <import plugin="org.eclipse.ui.workbench.texteditor"/> - <import plugin="org.eclipse.text"/> - </requires> - - <extension-point id="internalTestRunTabs" name="%testRunTabs.name" schema="schema/internal-testRunTabs.exsd"/> - <extension point="org.rubypeople.rdt.testunit.internalTestRunTabs"> <testRunTab class="org.rubypeople.rdt.testunit.views.FailureTab"/> <testRunTab class="org.rubypeople.rdt.testunit.views.TestHierarchyTab"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <caw...@us...> - 2006-07-17 23:31:11
|
Revision: 1512 Author: cawilliams Date: 2006-07-17 16:31:05 -0700 (Mon, 17 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1512&view=rev Log Message: ----------- add an OSGi bundle maifest to fix compilation errors with Eclipse 3.2 Modified Paths: -------------- branches/type_inferrence/trunk/org.epic.regexp/build.properties branches/type_inferrence/trunk/org.epic.regexp/plugin.xml Added Paths: ----------- branches/type_inferrence/trunk/org.epic.regexp/META-INF/ branches/type_inferrence/trunk/org.epic.regexp/META-INF/MANIFEST.MF Added: branches/type_inferrence/trunk/org.epic.regexp/META-INF/MANIFEST.MF =================================================================== --- branches/type_inferrence/trunk/org.epic.regexp/META-INF/MANIFEST.MF (rev 0) +++ branches/type_inferrence/trunk/org.epic.regexp/META-INF/MANIFEST.MF 2006-07-17 23:31:05 UTC (rev 1512) @@ -0,0 +1,17 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Regexp Plug-in +Bundle-SymbolicName: org.epic.regexp; singleton:=true +Bundle-Version: 0.1.4 +Bundle-ClassPath: regexp.jar, + gnu-regexp-1.1.4.jar +Bundle-Activator: org.epic.regexp.RegExpPlugin +Bundle-Vendor: Epic Project +Bundle-Localization: plugin +Export-Package: gnu.regexp, + org.epic.regexp, + org.epic.regexp.views +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.core.resources +Eclipse-LazyStart: true Modified: branches/type_inferrence/trunk/org.epic.regexp/build.properties =================================================================== --- branches/type_inferrence/trunk/org.epic.regexp/build.properties 2006-07-11 06:11:31 UTC (rev 1511) +++ branches/type_inferrence/trunk/org.epic.regexp/build.properties 2006-07-17 23:31:05 UTC (rev 1512) @@ -3,4 +3,5 @@ *.jar,\ regexp.jar,\ shortcuts,\ - icons/ + icons/,\ + META-INF/ Modified: branches/type_inferrence/trunk/org.epic.regexp/plugin.xml =================================================================== --- branches/type_inferrence/trunk/org.epic.regexp/plugin.xml 2006-07-11 06:11:31 UTC (rev 1511) +++ branches/type_inferrence/trunk/org.epic.regexp/plugin.xml 2006-07-17 23:31:05 UTC (rev 1512) @@ -1,27 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.0"?> -<plugin - id="org.epic.regexp" - name="Regexp Plug-in" - version="0.1.4" - provider-name="Epic Project" - class="org.epic.regexp.RegExpPlugin"> +<plugin> - <runtime> - <library name="regexp.jar"> - <export name="*"/> - </library> - <library name="gnu-regexp-1.1.4.jar"> - <export name="*"/> - </library> - </runtime> - <requires> - <import plugin="org.eclipse.ui"/> - <import plugin="org.eclipse.core.runtime"/> - <import plugin="org.eclipse.core.resources"/> - </requires> - - <extension + <extension point="org.eclipse.ui.views"> <view name="RegExp" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <jas...@us...> - 2006-07-11 06:11:36
|
Revision: 1511 Author: jasonpmorrison Date: 2006-07-10 23:11:31 -0700 (Mon, 10 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1511&view=rev Log Message: ----------- Bit of refactoring Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java 2006-07-11 04:46:35 UTC (rev 1510) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java 2006-07-11 06:11:31 UTC (rev 1511) @@ -52,182 +52,94 @@ return null; } + /** + * Determines the kind of originating node, and collects occurrences accordingly + */ public List<ISourcePosition> perform() { - // References to return - List<ISourcePosition> references = new LinkedList<ISourcePosition>(); + // occurrences to return + List<ISourcePosition> occurrences = new LinkedList<ISourcePosition>(); if ( isLocalVarRef(orig) ) { - pushLocalVarRefs( root, orig, references ); + pushLocalVarRefs( root, orig, occurrences ); } if ( isInstanceVarRef(orig) ) { - pushInstVarRefs( root, orig, references ); + pushInstVarRefs( root, orig, occurrences ); } if ( isGlobalVarRef(orig) ) { - pushGlobalVarRefs( root, orig, references ); + pushGlobalVarRefs( root, orig, occurrences ); } // if ( isMethodRefNode(orig)) { - // pushMethodRefs( root, orig, references ); + // pushMethodRefs( root, orig, occurrences ); // } if ( orig instanceof ConstNode ) { - pushConstRefs( root, orig, references ); + pushConstRefs( root, orig, occurrences ); } - return references; + return occurrences; } + + // **************************************************************************** + // * + // * Reference kind definitions + // * + // **************************************************************************** - private ISourcePosition getPositionOfName(Node node, Node scope) - { - ISourcePosition pos = node.getPosition(); - - //todo: refactor the getting-of-name - String name = null; - if ( isLocalVarRef(node) ) { name = getLocalVarRefName(node, scope); } - if ( isInstanceVarRef(node) ) { name = getInstVarRefName(node, scope); } - if ( isGlobalVarRef(node) ) { name = getGlobalVarRefName(node); } - if ( node instanceof ConstNode ) { name = ((ConstNode)node).getName(); } - - if ( name == null ) - { - System.err.println("Couldn't get the name for: " + node.toString() + " in " + scope.toString() ); - } - return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), pos.getStartOffset(), pos.getStartOffset() + name.length() ); - } - + /** - * Returns the name of a local var ref (LocalAsgnNode, ArgumentNode, LocalVarNode) - * @param node Node to get the name of - * @param scope Enclosing scope (to scrape args, etc.) + * Determines whether a given node is a local variable reference + * @param node * @return */ - private String getLocalVarRefName( Node node, Node scope ) { - if (node instanceof LocalAsgnNode) { - return ((LocalAsgnNode)node).getName(); - } - - if ( node instanceof ArgumentNode ) { - return ((ArgumentNode)node).getName(); - } - - if ( node instanceof LocalVarNode ) { - if ( scope instanceof DefnNode ) { - return ((DefnNode)scope).getBodyNode().getLocalNames()[((LocalVarNode)node).getCount()]; - } - if ( scope instanceof DefsNode ) { - return ((DefsNode)scope).getBodyNode().getLocalNames()[((LocalVarNode)node).getCount()]; - } - - // No enclosing ScopeNode found, try searching backwards for an AsgnNode - final int localVarCount = ((LocalVarNode)node).getCount(); - Node previousAssign = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(scope, node.getPosition().getStartOffset(), new INodeAcceptor() { - public boolean doesAccept(Node node) { - if ( node instanceof LocalAsgnNode ) - { - return ((LocalAsgnNode)node).getCount() == localVarCount; - } - return false; - } - }); - if ( previousAssign != null ) - { - return ((LocalAsgnNode)previousAssign).getName(); - } - - System.err.println("Unhandled scope for local var ref node found: " + scope.toString() ); - //TODO: if scope instanceof Block Body? what type is this.. - } - - if ( node instanceof DVarNode ) { - return ((DVarNode)node).getName(); - } - -// System.err.println("Encountered unhandled node type in getLocalVarRefName: " + node.toString() + " in " + scope.toString()); - return null; - } - - private String getClassNodeName( ClassNode classNode ) { - if (classNode.getCPath() instanceof Colon2Node) { - Colon2Node c2node = (Colon2Node) classNode.getCPath(); - return c2node.getName(); - } - System.err.println("ClassNode.getCPath() returned other than Colon2Node: " + classNode.toString() ); - return null; - } - - - private String getInstVarRefName( Node node, Node scope ) { - if ( node instanceof InstAsgnNode ) { - return ((InstAsgnNode)node).getName(); - } - - if ( node instanceof ArgumentNode ) { - return ((InstAsgnNode)node).getName(); - } - - if ( node instanceof InstVarNode ) { - return ((InstVarNode)node).getName(); - } - - if ( node instanceof DVarNode ) { - return ((DVarNode)node).getName(); - } - -// System.err.println("Encountered unhandled node type for getInstVarRefName: " + node.toString() + " in " + scope.toString()); - return null; - } - - private String getGlobalVarRefName( Node node ) { - if ( node instanceof GlobalVarNode ) - { - return ((GlobalVarNode)node).getName(); - } - if ( node instanceof GlobalAsgnNode ) { - return ((GlobalAsgnNode)node).getName(); - } - return null; - } - - private String getMethodRefName( Node node ) { - if ( node instanceof DefnNode ) { - return ((DefnNode)node).getName(); - } - if ( node instanceof DefsNode ) { - return ((DefsNode)node).getName(); - } - if ( node instanceof CallNode ) { - return ((CallNode)node).getName(); - } - if ( node instanceof VCallNode ) { - return ((VCallNode)node).getMethodName(); - } - return null; - } - - - private boolean isLocalVarRef( Node node ) { return ( ( node instanceof LocalAsgnNode ) || ( node instanceof ArgumentNode ) || ( node instanceof LocalVarNode ) ); } + /** + * Determines whether a given node is an instance variable reference + * @param node + * @return + */ private boolean isInstanceVarRef( Node node ) { return ( ( node instanceof InstAsgnNode ) || ( node instanceof InstVarNode ) ) ; } - + + /** + * Determines whether a given node is a global variable reference + * @param node + * @return + */ private boolean isGlobalVarRef( Node node ) { return ( ( node instanceof GlobalAsgnNode ) || ( node instanceof GlobalVarNode ) ); } + /** + * Determines whether a given node is method reference (either definition or invocation) + * @param node + * @return + */ private boolean isMethodRefNode( Node node ) { return ( ( node instanceof DefnNode ) || ( node instanceof DefsNode ) || ( node instanceof CallNode ) || ( node instanceof VCallNode ) ); } - - private void pushLocalVarRefs( Node root, Node orig, List<ISourcePosition> references ) { - System.out.println("Finding references for a local variable " + orig.toString()); + // **************************************************************************** + // * + // * Worker methods - handles delegation of occurrence searches + // * + // **************************************************************************** + + /** + * Collects all corresponding local variable occurrences + * @param root Root node to search + * @param orig Originating node + * @param occurrences + */ + private void pushLocalVarRefs( Node root, Node orig, List<ISourcePosition> occurrences ) { + System.out.println("Finding occurrences for a local variable " + orig.toString()); // Find the search space Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() { @@ -251,21 +163,24 @@ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() { public boolean doesAccept(Node node) { String name = getLocalVarRefName(node, finalSearchSpace); -// System.out.println("Matching name" + name); return ( name != null && name.equals(origName)); } }); // Scrape position from pertinent nodes for ( Node searchResult : searchResults ) { - references.add(getPositionOfName(searchResult, searchSpace)); + occurrences.add(getPositionOfName(searchResult, searchSpace)); } - -// System.out.println("Searching search space " + searchSpace.toString() + searchSpace.getPosition().toString() ); } - private void pushInstVarRefs( Node root, Node orig, List<ISourcePosition> references ) { - System.out.println("Finding references for an instance variable " + orig.toString() ); + /** + * Collects all instance variable occurrences + * @param root + * @param orig + * @param occurrences + */ + private void pushInstVarRefs( Node root, Node orig, List<ISourcePosition> occurrences ) { + System.out.println("Finding occurrences for an instance variable " + orig.toString() ); Node searchSpace; @@ -301,17 +216,18 @@ } // Finalize searchSpace because Java's scoping rules are the awesome - final Node finalSearchSpace = searchSpace; + //todo: not needed? + //final Node finalSearchSpace = searchSpace; // Get name of local variable reference - final String origName = getInstVarRefName(orig,searchSpace); + final String origName = getInstVarRefName(orig); // Find all pertinent nodes List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() { public boolean doesAccept(Node node) { if ( isInstanceVarRef(node) ) { - String name = getInstVarRefName(node, finalSearchSpace); + String name = getInstVarRefName(node); return ( name != null && name.equals(origName)); } return false; @@ -320,12 +236,18 @@ // Scrape position from pertinent nodes for ( Node searchResult : searchResults ) { - references.add(getPositionOfName(searchResult, searchSpace)); + occurrences.add(getPositionOfName(searchResult, searchSpace)); } } - private void pushGlobalVarRefs( Node root, Node orig, List<ISourcePosition> references ) { + /** + * Collects all global variable occurrences + * @param root + * @param orig + * @param occurrences + */ + private void pushGlobalVarRefs( Node root, Node orig, List<ISourcePosition> occurrences ) { final Node searchSpace = root; final String origName = getGlobalVarRefName(orig); @@ -338,21 +260,21 @@ // Scrape position from pertinent nodes for ( Node searchResult : searchResults ) { - references.add(getPositionOfName(searchResult, searchSpace)); + occurrences.add(getPositionOfName(searchResult, searchSpace)); } } //todo: complete -// private void pushMethodRefs( Node root, Node orig, List<ISourcePosition> references) { +// private void pushMethodRefs( Node root, Node orig, List<ISourcePosition> occurrences) { // // // DefnNode DefsNode CallNode VCallNode // -// System.out.println("Finding references for method reference node " + orig.toString() ); +// System.out.println("Finding occurrences for method reference node " + orig.toString() ); // // final Node searchSpace = root; // String origName = getMethodRefName(orig); // -// // If orig is a method definition, find all references to that selector for the orig's enclosing type +// // If orig is a method definition, find all occurrences to that selector for the orig's enclosing type // if ( orig instanceof DefnNode || orig instanceof DefsNode ) // { // ((DefnNode)orig).g @@ -361,7 +283,10 @@ // Node receiver = getMethodReceiver(orig); // } - private void pushConstRefs( Node root, Node orig, List<ISourcePosition> references) { + /** + * Collects all pertinent ConstNode occurrences + */ + private void pushConstRefs( Node root, Node orig, List<ISourcePosition> occurrences) { if ( !( orig instanceof ConstNode) ) { return; @@ -379,7 +304,160 @@ }); for ( Node searchResult : searchResults ) { - references.add(getPositionOfName(searchResult, root ) ); + occurrences.add(getPositionOfName(searchResult, root ) ); } } + + // **************************************************************************** + // * + // * Utility methods + // * + // **************************************************************************** + + /** + * Gets the position of the name for the specified node. + * @param node Node that responds to getName() or some variant + * @param scope Scope that holds the node (pertinent for locals and args) + * @return ISourcePosition that holds the name of the node + */ + private ISourcePosition getPositionOfName(Node node, Node scope) + { + ISourcePosition pos = node.getPosition(); + + //todo: refactor the getting-of-name + String name = null; + if ( isLocalVarRef(node) ) { name = getLocalVarRefName(node, scope); } + if ( isInstanceVarRef(node) ) { name = getInstVarRefName(node ); } + if ( isGlobalVarRef(node) ) { name = getGlobalVarRefName(node); } + if ( node instanceof ConstNode ) { name = ((ConstNode)node).getName(); } + + if ( name == null ) + { + System.err.println("Couldn't get the name for: " + node.toString() + " in " + scope.toString() ); + } + return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), pos.getStartOffset(), pos.getStartOffset() + name.length() ); + } + + /** + * Returns the name of a local var ref (LocalAsgnNode, ArgumentNode, LocalVarNode) + * @param node Node to get the name of + * @param scope Enclosing scope (to scrape args, etc.) + * @return + */ + private String getLocalVarRefName( Node node, Node scope ) { + if (node instanceof LocalAsgnNode) { + return ((LocalAsgnNode)node).getName(); + } + + if ( node instanceof ArgumentNode ) { + return ((ArgumentNode)node).getName(); + } + + if ( node instanceof LocalVarNode ) { + if ( scope instanceof DefnNode ) { + return ((DefnNode)scope).getBodyNode().getLocalNames()[((LocalVarNode)node).getCount()]; + } + if ( scope instanceof DefsNode ) { + return ((DefsNode)scope).getBodyNode().getLocalNames()[((LocalVarNode)node).getCount()]; + } + + // No enclosing ScopeNode found, try searching backwards for an AsgnNode + final int localVarCount = ((LocalVarNode)node).getCount(); + Node previousAssign = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(scope, node.getPosition().getStartOffset(), new INodeAcceptor() { + public boolean doesAccept(Node node) { + if ( node instanceof LocalAsgnNode ) + { + return ((LocalAsgnNode)node).getCount() == localVarCount; + } + return false; + } + }); + if ( previousAssign != null ) + { + return ((LocalAsgnNode)previousAssign).getName(); + } + + System.err.println("Unhandled scope for local var ref node found: " + scope.toString() ); + //TODO: if scope instanceof Block Body? what type is this.. + } + + if ( node instanceof DVarNode ) { + return ((DVarNode)node).getName(); + } + + return null; + } + + /** + * Gets the name of an instance variable reference + * @param node Instanve variable reference + * @return + */ + private String getInstVarRefName( Node node ) { + if ( node instanceof InstAsgnNode ) { + return ((InstAsgnNode)node).getName(); + } + + if ( node instanceof InstVarNode ) { + return ((InstVarNode)node).getName(); + } + + if ( node instanceof DVarNode ) { + return ((DVarNode)node).getName(); + } + + return null; + } + + /** + * Gets the name of a global variable reference + * @param node + * @return + */ + private String getGlobalVarRefName( Node node ) { + if ( node instanceof GlobalVarNode ) + { + return ((GlobalVarNode)node).getName(); + } + if ( node instanceof GlobalAsgnNode ) { + return ((GlobalAsgnNode)node).getName(); + } + return null; + } + + /** + * Gets the name of a method reference (either definition or invocation) + * @param node + * @return + */ + private String getMethodRefName( Node node ) { + if ( node instanceof DefnNode ) { + return ((DefnNode)node).getName(); + } + if ( node instanceof DefsNode ) { + return ((DefsNode)node).getName(); + } + if ( node instanceof CallNode ) { + return ((CallNode)node).getName(); + } + if ( node instanceof VCallNode ) { + return ((VCallNode)node).getMethodName(); + } + return null; + } + + /** + * Helper method to get the class name froma ClassNode + * @param classNode + * @return + */ + private String getClassNodeName( ClassNode classNode ) { + if (classNode.getCPath() instanceof Colon2Node) { + Colon2Node c2node = (Colon2Node) classNode.getCPath(); + return c2node.getName(); + } + System.err.println("ClassNode.getCPath() returned other than Colon2Node: " + classNode.toString() ); + return null; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <jas...@us...> - 2006-07-11 04:46:47
|
Revision: 1510 Author: jasonpmorrison Date: 2006-07-10 21:46:35 -0700 (Mon, 10 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1510&view=rev Log Message: ----------- Update action for Mark Occurences Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java Added Paths: ----------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java Removed Paths: ------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurenceFinder.java Added: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java (rev 0) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java 2006-07-11 04:46:35 UTC (rev 1510) @@ -0,0 +1,48 @@ +package org.rubypeople.rdt.internal.ti; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.jface.text.IDocument; +import org.jruby.ast.Node; +import org.rubypeople.rdt.core.IRubyElement; + +public class AbstractOccurencesFinder implements IOccurrencesFinder { + + public void collectOccurrenceMatches(IRubyElement element, + IDocument document, Collection resultingMatches) { + // TODO Auto-generated method stub + + } + + public String getElementName() { + // TODO Auto-generated method stub + return null; + } + + public String getJobLabel() { + // TODO Auto-generated method stub + return null; + } + + public String getUnformattedPluralLabel() { + // TODO Auto-generated method stub + return null; + } + + public String getUnformattedSingularLabel() { + // TODO Auto-generated method stub + return null; + } + + public String initialize(Node root, int offset, int length) { + // TODO Auto-generated method stub + return null; + } + + public List perform() { + // TODO Auto-generated method stub + return null; + } + +} Deleted: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurenceFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurenceFinder.java 2006-07-11 04:46:28 UTC (rev 1509) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurenceFinder.java 2006-07-11 04:46:35 UTC (rev 1510) @@ -1,58 +0,0 @@ -package org.rubypeople.rdt.internal.ti; - -import java.util.Collection; -import java.util.List; - -import org.eclipse.jface.text.IDocument; -import org.jruby.ast.Node; -import org.rubypeople.rdt.core.IRubyElement; -import org.rubypeople.rdt.internal.ti.util.OffsetNodeLocator; -//import org.rubypeople.rdt.internal.ui.search.IOccurrencesFinder; - -public class DefaultOccurenceFinder /* implements IOccurrencesFinder */ { - - public void collectOccurrenceMatches(IRubyElement element, IDocument document, Collection resultingMatches) { - // TODO Auto-generated method stub - } - - public String getElementName() { - // TODO Auto-generated method stub - return null; - } - - public String getJobLabel() { - // TODO Auto-generated method stub - return null; - } - - public String getUnformattedPluralLabel() { - // TODO Auto-generated method stub - return null; - } - - public String getUnformattedSingularLabel() { - // TODO Auto-generated method stub - return null; - } - - private Node root; - private Node orig; - - public String initialize(Node root, int offset, int length) { - this.root = root; - this.orig = OffsetNodeLocator.Instance().getNodeAtOffset(root, offset); - if ( orig.getPosition().getEndOffset() > offset + length ) - { - // Selection spans nodes; not handling that for now. - return "Selection spans nodes; can only search for a single node."; - } - - return null; - } - - public List perform() { - // TODO Auto-generated method stub - return null; - } - -} Added: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java (rev 0) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java 2006-07-11 04:46:35 UTC (rev 1510) @@ -0,0 +1,385 @@ +package org.rubypeople.rdt.internal.ti; + +import java.util.LinkedList; +import java.util.List; + +import org.jruby.ast.ArgumentNode; +import org.jruby.ast.BlockNode; +import org.jruby.ast.CallNode; +import org.jruby.ast.ClassNode; +import org.jruby.ast.Colon2Node; +import org.jruby.ast.ConstNode; +import org.jruby.ast.DVarNode; +import org.jruby.ast.DefnNode; +import org.jruby.ast.DefsNode; +import org.jruby.ast.GlobalAsgnNode; +import org.jruby.ast.GlobalVarNode; +import org.jruby.ast.InstAsgnNode; +import org.jruby.ast.InstVarNode; +import org.jruby.ast.LocalAsgnNode; +import org.jruby.ast.LocalVarNode; +import org.jruby.ast.Node; +import org.jruby.ast.VCallNode; +import org.jruby.lexer.yacc.ISourcePosition; +import org.jruby.lexer.yacc.SourcePosition; +import org.rubypeople.rdt.internal.ti.util.FirstPrecursorNodeLocator; +import org.rubypeople.rdt.internal.ti.util.INodeAcceptor; +import org.rubypeople.rdt.internal.ti.util.OffsetNodeLocator; +import org.rubypeople.rdt.internal.ti.util.ScopedNodeLocator; + +/** + * Implements "Mark Occurences" feature + * @author Jason Morrison + * + */ +public class DefaultOccurrencesFinder extends AbstractOccurencesFinder { + + // Root of the document to search + private Node root; + + // Originating node; corresponds to cursor selection + private Node orig; + + public String initialize(Node root, int offset, int length) { + this.root = root; + this.orig = OffsetNodeLocator.Instance().getNodeAtOffset(root, offset); + if ( orig.getPosition().getEndOffset() > offset + length ) + { + // Selection spans nodes; not handling that for now. + return "Selection spans nodes; can only search for a single node."; + } + + return null; + } + + public List<ISourcePosition> perform() { + // References to return + List<ISourcePosition> references = new LinkedList<ISourcePosition>(); + + if ( isLocalVarRef(orig) ) { + pushLocalVarRefs( root, orig, references ); + } + + if ( isInstanceVarRef(orig) ) { + pushInstVarRefs( root, orig, references ); + } + + if ( isGlobalVarRef(orig) ) { + pushGlobalVarRefs( root, orig, references ); + } + + // if ( isMethodRefNode(orig)) { + // pushMethodRefs( root, orig, references ); + // } + + if ( orig instanceof ConstNode ) + { + pushConstRefs( root, orig, references ); + } + + return references; + } + + private ISourcePosition getPositionOfName(Node node, Node scope) + { + ISourcePosition pos = node.getPosition(); + + //todo: refactor the getting-of-name + String name = null; + if ( isLocalVarRef(node) ) { name = getLocalVarRefName(node, scope); } + if ( isInstanceVarRef(node) ) { name = getInstVarRefName(node, scope); } + if ( isGlobalVarRef(node) ) { name = getGlobalVarRefName(node); } + if ( node instanceof ConstNode ) { name = ((ConstNode)node).getName(); } + + if ( name == null ) + { + System.err.println("Couldn't get the name for: " + node.toString() + " in " + scope.toString() ); + } + return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), pos.getStartOffset(), pos.getStartOffset() + name.length() ); + } + + /** + * Returns the name of a local var ref (LocalAsgnNode, ArgumentNode, LocalVarNode) + * @param node Node to get the name of + * @param scope Enclosing scope (to scrape args, etc.) + * @return + */ + private String getLocalVarRefName( Node node, Node scope ) { + if (node instanceof LocalAsgnNode) { + return ((LocalAsgnNode)node).getName(); + } + + if ( node instanceof ArgumentNode ) { + return ((ArgumentNode)node).getName(); + } + + if ( node instanceof LocalVarNode ) { + if ( scope instanceof DefnNode ) { + return ((DefnNode)scope).getBodyNode().getLocalNames()[((LocalVarNode)node).getCount()]; + } + if ( scope instanceof DefsNode ) { + return ((DefsNode)scope).getBodyNode().getLocalNames()[((LocalVarNode)node).getCount()]; + } + + // No enclosing ScopeNode found, try searching backwards for an AsgnNode + final int localVarCount = ((LocalVarNode)node).getCount(); + Node previousAssign = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(scope, node.getPosition().getStartOffset(), new INodeAcceptor() { + public boolean doesAccept(Node node) { + if ( node instanceof LocalAsgnNode ) + { + return ((LocalAsgnNode)node).getCount() == localVarCount; + } + return false; + } + }); + if ( previousAssign != null ) + { + return ((LocalAsgnNode)previousAssign).getName(); + } + + System.err.println("Unhandled scope for local var ref node found: " + scope.toString() ); + //TODO: if scope instanceof Block Body? what type is this.. + } + + if ( node instanceof DVarNode ) { + return ((DVarNode)node).getName(); + } + +// System.err.println("Encountered unhandled node type in getLocalVarRefName: " + node.toString() + " in " + scope.toString()); + return null; + } + + private String getClassNodeName( ClassNode classNode ) { + if (classNode.getCPath() instanceof Colon2Node) { + Colon2Node c2node = (Colon2Node) classNode.getCPath(); + return c2node.getName(); + } + System.err.println("ClassNode.getCPath() returned other than Colon2Node: " + classNode.toString() ); + return null; + } + + + private String getInstVarRefName( Node node, Node scope ) { + if ( node instanceof InstAsgnNode ) { + return ((InstAsgnNode)node).getName(); + } + + if ( node instanceof ArgumentNode ) { + return ((InstAsgnNode)node).getName(); + } + + if ( node instanceof InstVarNode ) { + return ((InstVarNode)node).getName(); + } + + if ( node instanceof DVarNode ) { + return ((DVarNode)node).getName(); + } + +// System.err.println("Encountered unhandled node type for getInstVarRefName: " + node.toString() + " in " + scope.toString()); + return null; + } + + private String getGlobalVarRefName( Node node ) { + if ( node instanceof GlobalVarNode ) + { + return ((GlobalVarNode)node).getName(); + } + if ( node instanceof GlobalAsgnNode ) { + return ((GlobalAsgnNode)node).getName(); + } + return null; + } + + private String getMethodRefName( Node node ) { + if ( node instanceof DefnNode ) { + return ((DefnNode)node).getName(); + } + if ( node instanceof DefsNode ) { + return ((DefsNode)node).getName(); + } + if ( node instanceof CallNode ) { + return ((CallNode)node).getName(); + } + if ( node instanceof VCallNode ) { + return ((VCallNode)node).getMethodName(); + } + return null; + } + + + + private boolean isLocalVarRef( Node node ) { + return ( ( node instanceof LocalAsgnNode ) || ( node instanceof ArgumentNode ) || ( node instanceof LocalVarNode ) ); + } + + private boolean isInstanceVarRef( Node node ) { + return ( ( node instanceof InstAsgnNode ) || ( node instanceof InstVarNode ) ) ; + } + + private boolean isGlobalVarRef( Node node ) { + return ( ( node instanceof GlobalAsgnNode ) || ( node instanceof GlobalVarNode ) ); + } + + private boolean isMethodRefNode( Node node ) { + return ( ( node instanceof DefnNode ) || ( node instanceof DefsNode ) || ( node instanceof CallNode ) || ( node instanceof VCallNode ) ); + } + + + private void pushLocalVarRefs( Node root, Node orig, List<ISourcePosition> references ) { + System.out.println("Finding references for a local variable " + orig.toString()); + + // Find the search space + Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() { + public boolean doesAccept(Node node) { + return ( ( node instanceof DefnNode ) || ( node instanceof DefsNode ) /*TODO: Block Body? */ ); + } + }); + + // If no enclosing node found, search the entire space + if ( searchSpace == null ) { + searchSpace = root; + } + + // Finalize searchSpace because Java's scoping rules are the awesome + final Node finalSearchSpace = searchSpace; + + // Get name of local variable reference + final String origName = getLocalVarRefName(orig,searchSpace); + + // Find all pertinent nodes + List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() { + public boolean doesAccept(Node node) { + String name = getLocalVarRefName(node, finalSearchSpace); +// System.out.println("Matching name" + name); + return ( name != null && name.equals(origName)); + } + }); + + // Scrape position from pertinent nodes + for ( Node searchResult : searchResults ) { + references.add(getPositionOfName(searchResult, searchSpace)); + } + +// System.out.println("Searching search space " + searchSpace.toString() + searchSpace.getPosition().toString() ); + } + + private void pushInstVarRefs( Node root, Node orig, List<ISourcePosition> references ) { + System.out.println("Finding references for an instance variable " + orig.toString() ); + + Node searchSpace; + + // Find the name of the enclosing class + ClassNode enclosingClass = (ClassNode)FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() { + public boolean doesAccept(Node node) { + return ( node instanceof ClassNode ); + } + }); + + // If no enclosing class is identified, search root. + if ( enclosingClass == null ) { + searchSpace = root; + } + // Find the search space - all ClassNodes for that name within root scope + else { + final String className = getClassNodeName(enclosingClass); + List<Node> classNodes = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() { + public boolean doesAccept(Node node) { + if ( node instanceof ClassNode ) + { + return getClassNodeName((ClassNode)node).equals(className); + } + return false; + } + }); + BlockNode blockNode = new BlockNode(new SourcePosition("",0)); + for ( Node classNode : classNodes ) + { + blockNode.add( classNode ); + } + searchSpace = blockNode; + } + + // Finalize searchSpace because Java's scoping rules are the awesome + final Node finalSearchSpace = searchSpace; + + // Get name of local variable reference + final String origName = getInstVarRefName(orig,searchSpace); + + // Find all pertinent nodes + List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() { + public boolean doesAccept(Node node) { + if ( isInstanceVarRef(node) ) + { + String name = getInstVarRefName(node, finalSearchSpace); + return ( name != null && name.equals(origName)); + } + return false; + } + }); + + // Scrape position from pertinent nodes + for ( Node searchResult : searchResults ) { + references.add(getPositionOfName(searchResult, searchSpace)); + } + + } + + private void pushGlobalVarRefs( Node root, Node orig, List<ISourcePosition> references ) { + final Node searchSpace = root; + final String origName = getGlobalVarRefName(orig); + + // Find all pertinent nodes + List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() { + public boolean doesAccept(Node node) { + return isGlobalVarRef(node) && getGlobalVarRefName(node).equals(origName); + } + }); + + // Scrape position from pertinent nodes + for ( Node searchResult : searchResults ) { + references.add(getPositionOfName(searchResult, searchSpace)); + } + } + + //todo: complete +// private void pushMethodRefs( Node root, Node orig, List<ISourcePosition> references) { +// +// // DefnNode DefsNode CallNode VCallNode +// +// System.out.println("Finding references for method reference node " + orig.toString() ); +// +// final Node searchSpace = root; +// String origName = getMethodRefName(orig); +// +// // If orig is a method definition, find all references to that selector for the orig's enclosing type +// if ( orig instanceof DefnNode || orig instanceof DefsNode ) +// { +// ((DefnNode)orig).g +// } +// +// Node receiver = getMethodReceiver(orig); +// } + + private void pushConstRefs( Node root, Node orig, List<ISourcePosition> references) { + if ( !( orig instanceof ConstNode) ) + { + return; + } + + final String matchName = ((ConstNode)orig).getName(); + List <Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() { + public boolean doesAccept(Node node) { + if ( node instanceof ConstNode ) + { + return ((ConstNode)node).getName().equals(matchName); + } + return false; + } + }); + + for ( Node searchResult : searchResults ) { + references.add(getPositionOfName(searchResult, root ) ); + } + } +} Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java 2006-07-11 04:46:28 UTC (rev 1509) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java 2006-07-11 04:46:35 UTC (rev 1510) @@ -1,13 +1,8 @@ package org.rubypeople.rdt.internal.ti; -import java.io.FileReader; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.LinkedList; import java.util.List; -import java.util.Map; -import org.jruby.ast.ArgsNode; import org.jruby.ast.ArgumentNode; import org.jruby.ast.BlockNode; import org.jruby.ast.CallNode; @@ -21,27 +16,16 @@ import org.jruby.ast.GlobalVarNode; import org.jruby.ast.InstAsgnNode; import org.jruby.ast.InstVarNode; -import org.jruby.ast.ListNode; import org.jruby.ast.LocalAsgnNode; import org.jruby.ast.LocalVarNode; import org.jruby.ast.Node; import org.jruby.ast.VCallNode; -import org.jruby.ast.types.INameNode; import org.jruby.lexer.yacc.ISourcePosition; import org.jruby.lexer.yacc.SourcePosition; -import org.rubypeople.rdt.core.IRubyElement; -import org.rubypeople.rdt.core.ISourceRange; -import org.rubypeople.rdt.core.RubyModelException; -import org.rubypeople.rdt.internal.core.NamedMember; -import org.rubypeople.rdt.internal.core.RubyElement; -import org.rubypeople.rdt.internal.core.RubyScriptStructureBuilder; -import org.rubypeople.rdt.internal.core.SourceRange; -import org.rubypeople.rdt.internal.core.SourceRefElement; import org.rubypeople.rdt.internal.core.parser.RdtWarnings; import org.rubypeople.rdt.internal.core.parser.RubyParser; import org.rubypeople.rdt.internal.ti.util.FirstPrecursorNodeLocator; import org.rubypeople.rdt.internal.ti.util.INodeAcceptor; -import org.rubypeople.rdt.internal.ti.util.NodeLocator; import org.rubypeople.rdt.internal.ti.util.OffsetNodeLocator; import org.rubypeople.rdt.internal.ti.util.ScopedNodeLocator; @@ -74,9 +58,9 @@ pushGlobalVarRefs( root, orig, references ); } - if ( isMethodRefNode(orig)) { - pushMethodRefs( root, orig, references ); - } +// if ( isMethodRefNode(orig)) { +// pushMethodRefs( root, orig, references ); +// } if ( orig instanceof ConstNode ) { @@ -348,24 +332,25 @@ } } - private void pushMethodRefs( Node root, Node orig, List<ISourcePosition> references) { + //todo: complete +// private void pushMethodRefs( Node root, Node orig, List<ISourcePosition> references) { +// +// // DefnNode DefsNode CallNode VCallNode +// +// System.out.println("Finding references for method reference node " + orig.toString() ); +// +// final Node searchSpace = root; +// String origName = getMethodRefName(orig); +// +// // If orig is a method definition, find all references to that selector for the orig's enclosing type +// if ( orig instanceof DefnNode || orig instanceof DefsNode ) +// { +// ((DefnNode)orig).g +// } +// +// Node receiver = getMethodReceiver(orig); +// } - // DefnNode DefsNode CallNode VCallNode - - System.out.println("Finding references for method reference node " + orig.toString() ); - - final Node searchSpace = root; - String origName = getMethodRefName(orig); - - // If orig is a method definition, find all references to that selector for the orig's enclosing type - if ( orig instanceof DefnNode || orig instanceof DefsNode ) - { - ((DefnNode)orig).g - } - - Node receiver = getMethodReceiver(orig); - } - private void pushConstRefs( Node root, Node orig, List<ISourcePosition> references) { if ( !( orig instanceof ConstNode) ) { Copied: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java (from rev 1505, branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/IOccurrencesFinder.java) =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java (rev 0) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java 2006-07-11 04:46:35 UTC (rev 1510) @@ -0,0 +1,77 @@ +/******************************************************************************* + * 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.ti; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.jface.text.IDocument; +import org.jruby.ast.Node; +import org.rubypeople.rdt.core.IRubyElement; + +public interface IOccurrencesFinder { + + /** + * + * @param root + * root AST Node + * @param offset + * position in source where selection is + * @param length + * length of the selection + * @return + */ + public String initialize(Node root, int offset, int length); + + /** + * Returns a lit of AST Nodes back (which contain their associated + * positions). + * + * @return List of AST Nodes + */ + public List perform(); + + public String getJobLabel(); + + /** + * Returns the plural label for this finder with 3 placeholders: + * <ul> + * <li>{0} for the {@link #getElementName() element name}</li> + * <li>{1} for the number of results found</li> + * <li>{2} for the scope (name of the compilation unit)</li> + * </ul> + * + * @return the unformatted label + */ + public String getUnformattedPluralLabel(); + + /** + * Returns the singular label for this finder with 2 placeholders: + * <ul> + * <li>{0} for the {@link #getElementName() element name}</li> + * <li>{1} for the scope (name of the compilation unit)</li> + * </ul> + * + * @return the unformatted label + */ + public String getUnformattedSingularLabel(); + + /** + * Returns the name of the lement to look for or <code>null</code> if the + * finder hasn't been initialized yet. + * + * @return the name of the element + */ + public String getElementName(); + + public void collectOccurrenceMatches(IRubyElement element, + IDocument document, Collection resultingMatches); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
Revision: 1509 Author: jasonpmorrison Date: 2006-07-10 21:46:28 -0700 (Mon, 10 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1509&view=rev Log Message: ----------- Update action for Mark Occurences Added Paths: ----------- branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java Added: branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java (rev 0) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java 2006-07-11 04:46:28 UTC (rev 1509) @@ -0,0 +1,143 @@ +package org.rubypeople.rdt.internal.ti; + +import java.util.List; + +import org.jruby.ast.Node; +import org.jruby.lexer.yacc.ISourcePosition; +import org.rubypeople.rdt.internal.core.parser.RubyParser; +import org.rubypeople.rdt.internal.ti.util.OffsetNodeLocator; + +import junit.framework.TestCase; + +/** + * Tests related to matching occurrences. + * + * @author Jason Morrison + * + */ +public class MarkOccurrencesTest extends TestCase { + + private IOccurrencesFinder occurrencesFinder; + public void setUp() { + occurrencesFinder = new DefaultOccurrencesFinder(); + } + + private Node parse(String source) { + return new RubyParser().parse(source); + } + + private void assertOccurrencesEqual( String source, int offset, String matchName, int[][] offsets ) + { + occurrencesFinder.initialize(parse(source), offset, 0); + List <ISourcePosition> occurrences = occurrencesFinder.perform(); + assertEquals( offsets.length, occurrences.size() ); + + for ( int i = 0; i < offsets.length; i++ ) { + assertEquals( offsets[i][0], occurrences.get(i).getStartOffset() ); + assertEquals( offsets[i][1], occurrences.get(i).getEndOffset() ); + assertEquals( matchName, source.substring(occurrences.get(i).getStartOffset(), occurrences.get(i).getEndOffset())); + } + } + + /** + * Match locals within ClassNode::DefnNode + */ + public void testLocalVariableMatches() { + String source = "class Klass;def foo(x);puts x*2;end;def bar;my_var = 5;my_var = 6;puts my_var;foo(my_var);end;end"; + int[][] offsets = {{44,50},{55,61},{71,77},{82,88}}; + assertOccurrencesEqual( source, 46, "my_var", offsets ); + } + + /** + * Match locals within Kernel::DefnNode + */ + public void testLocalVariablesInKernelDefnScope() { + String source = "def foo;my_var=5;puts my_var*2;end"; + int[][] offsets = {{8,14},{22,28}}; + assertOccurrencesEqual( source, 10, "my_var", offsets ); + } + + /** + * Match locals in Kernel + */ + public void testLocalVariablesInKernelScope() { + String source = "my_var = 5;puts my_var*2;other_var = my_var * my_var"; + int[][] offsets = {{0,6},{16,22},{37,43},{46,52}}; + assertOccurrencesEqual( source, 1, "my_var", offsets ); + } + + /** + * Match instance vars inside one ClassNode across DefnNode + */ + public void testInstanceVariableMatches() { + String source = "class Klass;def foo(param);@inst_var = param;puts @inst_var;end;def bar;y @inst_var;end;end"; + int[][] offsets = {{27,36},{50,59},{74,83}}; + assertOccurrencesEqual( source, 29, "@inst_var", offsets ); + } + + /** + * Match instance vars inside two DefnNodes, each in a separate ClassNode (for the same class) + */ + public void testInstanceVariableMatchInReopenedClass() { + String source = "class Klass;def foo;@inst_var=5;end;end;class Klass;def bar;@inst_var=6;end;end"; + int[][] offsets = {{20,29},{60,69}}; + assertOccurrencesEqual( source, 23, "@inst_var", offsets ); + } + + /** + * Test matching a local variable before, inside, and after a block. + */ + public void testLocalVariableMatchesIntoBlockScope() { + String source = "class Klass;def foo;my_var = 5;5.times { puts my_var };puts my_var;end;end"; + int[][] offsets = {{20,26},{46,52},{60,66}}; + assertOccurrencesEqual( source, 23, "my_var", offsets ); + } + + /** + * Test referencing a global variable in various contexts. + * + */ + public void testGlobalVariableMatches() { + String source = "$foo = 'bar';class Klass;def foo;$foo = 5;end;def bar;puts $foo;end;end;puts $foo"; + int[][] offsets = {{0,4},{33,37},{59,63},{77,81}}; + assertOccurrencesEqual(source, 0, "$foo", offsets); + } + +//todo: Method invocation tests get into territory where a more formal approach is needed (i.e. DDP) +// Sub-goals are becoming necessary, i.e. for determining arg-type to match selectors by more +// than name, and determining receiver-type to match selectors applied to other same-typed receivers. + +// public void testMethodInvocationMatchInsideMethod() { +// String source = "class Klass;def foo;my_var = 5;y = my_var.to_s;puts y.to_s;end;end"; +// int[][] offsets = {{42,46},{54,58}}; +// assertOccurrencesEquals( source, 42, "to_s", offsets ); +// } +// +// public void testMethodInvocationMatchInKernelScope() { +// String source = "my_var = 5;y = my_var.to_s;puts y.to_s"; +// int[][] offsets = {{22,26},{34,38}}; +// assertOccurrencesEquals(source, 22, "to_s", offsets); +// } +// +// public void testStaticMethodInvocationMatchInKernelScope() { +// String source = "puts 5;puts 6;puts 7;"; +// int[][] offsets = {{0,4},{7,11},{14,18}}; +// assertOccurrencesEquals( source, 0, "puts", offsets ); +// } +// +// public void testMethodInvocationMatchAgainstMultipleInstancesOfSameType() { +// String source = "xvar = 5;yvar = 6;puts xvar.to_s;puts yvar.to_s"; +// int[][] offsets = {{28,32},{43,47}}; +// assertOccurrencesEquals(source, 28, "to_s", offsets); +// } + + /** + * Test matching against ConstNodes; specifically class occurrences + */ + public void testTypeMatches() { + String source = "f = String.new;class Klass;def foo;c = String;end;end;class MyString < String;end"; + int[][] offsets = {{4,10},{39,45},{71,77}}; + assertOccurrencesEqual( source, 5, "String", offsets ); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <jas...@us...> - 2006-07-11 04:46:27
|
Revision: 1508 Author: jasonpmorrison Date: 2006-07-10 21:46:21 -0700 (Mon, 10 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1508&view=rev Log Message: ----------- Update action for Mark Occurences Removed Paths: ------------- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/IOccurrencesFinder.java Deleted: branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/IOccurrencesFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/IOccurrencesFinder.java 2006-07-06 20:11:55 UTC (rev 1507) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/IOccurrencesFinder.java 2006-07-11 04:46:21 UTC (rev 1508) @@ -1,77 +0,0 @@ -/******************************************************************************* - * 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.search; - -import java.util.Collection; -import java.util.List; - -import org.eclipse.jface.text.IDocument; -import org.jruby.ast.Node; -import org.rubypeople.rdt.core.IRubyElement; - -public interface IOccurrencesFinder { - - /** - * - * @param root - * root AST Node - * @param offset - * position in source where selection is - * @param length - * length of the selection - * @return - */ - public String initialize(Node root, int offset, int length); - - /** - * Returns a lit of AST Nodes back (which contain their associated - * positions). - * - * @return List of AST Nodes - */ - public List perform(); - - public String getJobLabel(); - - /** - * Returns the plural label for this finder with 3 placeholders: - * <ul> - * <li>{0} for the {@link #getElementName() element name}</li> - * <li>{1} for the number of results found</li> - * <li>{2} for the scope (name of the compilation unit)</li> - * </ul> - * - * @return the unformatted label - */ - public String getUnformattedPluralLabel(); - - /** - * Returns the singular label for this finder with 2 placeholders: - * <ul> - * <li>{0} for the {@link #getElementName() element name}</li> - * <li>{1} for the scope (name of the compilation unit)</li> - * </ul> - * - * @return the unformatted label - */ - public String getUnformattedSingularLabel(); - - /** - * Returns the name of the lement to look for or <code>null</code> if the - * finder hasn't been initialized yet. - * - * @return the name of the element - */ - public String getElementName(); - - public void collectOccurrenceMatches(IRubyElement element, - IDocument document, Collection resultingMatches); -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <jas...@us...> - 2006-07-06 20:12:07
|
Revision: 1507 Author: jasonpmorrison Date: 2006-07-06 13:11:55 -0700 (Thu, 06 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1507&view=rev Log Message: ----------- Added tests for & implemented more occurence marking Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/OffsetNodeLocator.java Added Paths: ----------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurenceFinder.java Added: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurenceFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurenceFinder.java (rev 0) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurenceFinder.java 2006-07-06 20:11:55 UTC (rev 1507) @@ -0,0 +1,58 @@ +package org.rubypeople.rdt.internal.ti; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.jface.text.IDocument; +import org.jruby.ast.Node; +import org.rubypeople.rdt.core.IRubyElement; +import org.rubypeople.rdt.internal.ti.util.OffsetNodeLocator; +//import org.rubypeople.rdt.internal.ui.search.IOccurrencesFinder; + +public class DefaultOccurenceFinder /* implements IOccurrencesFinder */ { + + public void collectOccurrenceMatches(IRubyElement element, IDocument document, Collection resultingMatches) { + // TODO Auto-generated method stub + } + + public String getElementName() { + // TODO Auto-generated method stub + return null; + } + + public String getJobLabel() { + // TODO Auto-generated method stub + return null; + } + + public String getUnformattedPluralLabel() { + // TODO Auto-generated method stub + return null; + } + + public String getUnformattedSingularLabel() { + // TODO Auto-generated method stub + return null; + } + + private Node root; + private Node orig; + + public String initialize(Node root, int offset, int length) { + this.root = root; + this.orig = OffsetNodeLocator.Instance().getNodeAtOffset(root, offset); + if ( orig.getPosition().getEndOffset() > offset + length ) + { + // Selection spans nodes; not handling that for now. + return "Selection spans nodes; can only search for a single node."; + } + + return null; + } + + public List perform() { + // TODO Auto-generated method stub + return null; + } + +} Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java 2006-07-06 20:11:46 UTC (rev 1506) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java 2006-07-06 20:11:55 UTC (rev 1507) @@ -13,6 +13,7 @@ import org.jruby.ast.CallNode; import org.jruby.ast.ClassNode; import org.jruby.ast.Colon2Node; +import org.jruby.ast.ConstNode; import org.jruby.ast.DVarNode; import org.jruby.ast.DefnNode; import org.jruby.ast.DefsNode; @@ -76,6 +77,11 @@ if ( isMethodRefNode(orig)) { pushMethodRefs( root, orig, references ); } + + if ( orig instanceof ConstNode ) + { + pushConstRefs( root, orig, references ); + } return references; } @@ -85,13 +91,14 @@ ISourcePosition pos = node.getPosition(); //todo: refactor the getting-of-name - String name = getLocalVarRefName(node, scope); + String name = null; + if ( isLocalVarRef(node) ) { name = getLocalVarRefName(node, scope); } + if ( isInstanceVarRef(node) ) { name = getInstVarRefName(node, scope); } + if ( isGlobalVarRef(node) ) { name = getGlobalVarRefName(node); } + if ( node instanceof ConstNode ) { name = ((ConstNode)node).getName(); } + if ( name == null ) { - name = getInstVarRefName(node, scope); - } - if ( name == null ) - { System.err.println("Couldn't get the name for: " + node.toString() + " in " + scope.toString() ); } return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), pos.getStartOffset(), pos.getStartOffset() + name.length() ); @@ -179,6 +186,35 @@ return null; } + private String getGlobalVarRefName( Node node ) { + if ( node instanceof GlobalVarNode ) + { + return ((GlobalVarNode)node).getName(); + } + if ( node instanceof GlobalAsgnNode ) { + return ((GlobalAsgnNode)node).getName(); + } + return null; + } + + private String getMethodRefName( Node node ) { + if ( node instanceof DefnNode ) { + return ((DefnNode)node).getName(); + } + if ( node instanceof DefsNode ) { + return ((DefsNode)node).getName(); + } + if ( node instanceof CallNode ) { + return ((CallNode)node).getName(); + } + if ( node instanceof VCallNode ) { + return ((VCallNode)node).getMethodName(); + } + return null; + } + + + private boolean isLocalVarRef( Node node ) { return ( ( node instanceof LocalAsgnNode ) || ( node instanceof ArgumentNode ) || ( node instanceof LocalVarNode ) ); } @@ -262,8 +298,7 @@ return false; } }); - //todo: is this cool with the "n/a" and all? - BlockNode blockNode = new BlockNode(new SourcePosition("n/a",0));//new ListNode(new SourcePosition("n/a",0)); + BlockNode blockNode = new BlockNode(new SourcePosition("",0)); for ( Node classNode : classNodes ) { blockNode.add( classNode ); @@ -280,8 +315,12 @@ // Find all pertinent nodes List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() { public boolean doesAccept(Node node) { - String name = getInstVarRefName(node, finalSearchSpace); - return ( name != null && name.equals(origName)); + if ( isInstanceVarRef(node) ) + { + String name = getInstVarRefName(node, finalSearchSpace); + return ( name != null && name.equals(origName)); + } + return false; } }); @@ -293,13 +332,62 @@ } private void pushGlobalVarRefs( Node root, Node orig, List<ISourcePosition> references ) { + final Node searchSpace = root; + final String origName = getGlobalVarRefName(orig); + // Find all pertinent nodes + List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() { + public boolean doesAccept(Node node) { + return isGlobalVarRef(node) && getGlobalVarRefName(node).equals(origName); + } + }); + + // Scrape position from pertinent nodes + for ( Node searchResult : searchResults ) { + references.add(getPositionOfName(searchResult, searchSpace)); + } } private void pushMethodRefs( Node root, Node orig, List<ISourcePosition> references) { + + // DefnNode DefsNode CallNode VCallNode + System.out.println("Finding references for method reference node " + orig.toString() ); + + final Node searchSpace = root; + String origName = getMethodRefName(orig); + + // If orig is a method definition, find all references to that selector for the orig's enclosing type + if ( orig instanceof DefnNode || orig instanceof DefsNode ) + { + ((DefnNode)orig).g + } + + Node receiver = getMethodReceiver(orig); } + private void pushConstRefs( Node root, Node orig, List<ISourcePosition> references) { + if ( !( orig instanceof ConstNode) ) + { + return; + } + + final String matchName = ((ConstNode)orig).getName(); + List <Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() { + public boolean doesAccept(Node node) { + if ( node instanceof ConstNode ) + { + return ((ConstNode)node).getName().equals(matchName); + } + return false; + } + }); + + for ( Node searchResult : searchResults ) { + references.add(getPositionOfName(searchResult, root ) ); + } + } + } Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/OffsetNodeLocator.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/OffsetNodeLocator.java 2006-07-06 20:11:46 UTC (rev 1506) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/util/OffsetNodeLocator.java 2006-07-06 20:11:55 UTC (rev 1507) @@ -50,7 +50,7 @@ */ public Instruction handleNode(Node iVisited) { - System.out.println("Looking for node at offset, checking: " + iVisited.getClass().getName() + "[" + iVisited.getPosition().getStartOffset() + ".." + iVisited.getPosition().getEndOffset() + "]" ); +// System.out.println("Looking for node at offset, checking: " + iVisited.getClass().getName() + "[" + iVisited.getPosition().getStartOffset() + ".." + iVisited.getPosition().getEndOffset() + "]" ); if (nodeDoesSpanOffset(iVisited, offset)) { //note: careful... should this be <=? I think so; since it traverses in-order, this should find the "most specific" closest node. i.e. //def foo;x;end offset at 'x' is a 1-char ScopingNode and 1-char LocalVarNode; it should identify the LocalVarNode, which <= does. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <jas...@us...> - 2006-07-06 20:11:52
|
Revision: 1506 Author: jasonpmorrison Date: 2006-07-06 13:11:46 -0700 (Thu, 06 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1506&view=rev Log Message: ----------- Added tests for & implemented more occurence marking Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/ReferenceMatchTest.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/ReferenceMatchTest.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/ReferenceMatchTest.java 2006-07-02 13:12:17 UTC (rev 1505) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/ReferenceMatchTest.java 2006-07-06 20:11:46 UTC (rev 1506) @@ -84,5 +84,52 @@ int[][] offsets = {{20,26},{46,52},{60,66}}; assertReferencesEquals( source, 23, "my_var", offsets ); } + + /** + * Test referencing a global variable in various contexts. + * + */ + public void testGlobalVariableMatches() { + String source = "$foo = 'bar';class Klass;def foo;$foo = 5;end;def bar;puts $foo;end;end;puts $foo"; + int[][] offsets = {{0,4},{33,37},{59,63},{77,81}}; + assertReferencesEquals(source, 0, "$foo", offsets); + } +//todo: Method invocation tests get into territory where a more formal approach is needed (i.e. DDP) +// Sub-goals are becoming necessary, i.e. for determining arg-type to match selectors by more +// than name, and determining receiver-type to match selectors applied to other same-typed receivers. + +// public void testMethodInvocationMatchInsideMethod() { +// String source = "class Klass;def foo;my_var = 5;y = my_var.to_s;puts y.to_s;end;end"; +// int[][] offsets = {{42,46},{54,58}}; +// assertReferencesEquals( source, 42, "to_s", offsets ); +// } +// +// public void testMethodInvocationMatchInKernelScope() { +// String source = "my_var = 5;y = my_var.to_s;puts y.to_s"; +// int[][] offsets = {{22,26},{34,38}}; +// assertReferencesEquals(source, 22, "to_s", offsets); +// } +// +// public void testStaticMethodInvocationMatchInKernelScope() { +// String source = "puts 5;puts 6;puts 7;"; +// int[][] offsets = {{0,4},{7,11},{14,18}}; +// assertReferencesEquals( source, 0, "puts", offsets ); +// } +// +// public void testMethodInvocationMatchAgainstMultipleInstancesOfSameType() { +// String source = "xvar = 5;yvar = 6;puts xvar.to_s;puts yvar.to_s"; +// int[][] offsets = {{28,32},{43,47}}; +// assertReferencesEquals(source, 28, "to_s", offsets); +// } + + /** + * Test matching against ConstNodes; specifically class references + */ + public void testTypeMatches() { + String source = "f = String.new;class Klass;def foo;c = String;end;end;class MyString < String;end"; + int[][] offsets = {{4,10},{39,45},{71,77}}; + assertReferencesEquals( source, 5, "String", offsets ); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <caw...@us...> - 2006-07-02 13:12:23
|
Revision: 1505 Author: cawilliams Date: 2006-07-02 06:12:17 -0700 (Sun, 02 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1505&view=rev Log Message: ----------- add the interace that occurence finders shoudl implement - stolen from JDT Added Paths: ----------- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/IOccurrencesFinder.java Added: branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/IOccurrencesFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/IOccurrencesFinder.java (rev 0) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/IOccurrencesFinder.java 2006-07-02 13:12:17 UTC (rev 1505) @@ -0,0 +1,77 @@ +/******************************************************************************* + * 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.search; + +import java.util.Collection; +import java.util.List; + +import org.eclipse.jface.text.IDocument; +import org.jruby.ast.Node; +import org.rubypeople.rdt.core.IRubyElement; + +public interface IOccurrencesFinder { + + /** + * + * @param root + * root AST Node + * @param offset + * position in source where selection is + * @param length + * length of the selection + * @return + */ + public String initialize(Node root, int offset, int length); + + /** + * Returns a lit of AST Nodes back (which contain their associated + * positions). + * + * @return List of AST Nodes + */ + public List perform(); + + public String getJobLabel(); + + /** + * Returns the plural label for this finder with 3 placeholders: + * <ul> + * <li>{0} for the {@link #getElementName() element name}</li> + * <li>{1} for the number of results found</li> + * <li>{2} for the scope (name of the compilation unit)</li> + * </ul> + * + * @return the unformatted label + */ + public String getUnformattedPluralLabel(); + + /** + * Returns the singular label for this finder with 2 placeholders: + * <ul> + * <li>{0} for the {@link #getElementName() element name}</li> + * <li>{1} for the scope (name of the compilation unit)</li> + * </ul> + * + * @return the unformatted label + */ + public String getUnformattedSingularLabel(); + + /** + * Returns the name of the lement to look for or <code>null</code> if the + * finder hasn't been initialized yet. + * + * @return the name of the element + */ + public String getElementName(); + + public void collectOccurrenceMatches(IRubyElement element, + IDocument document, Collection resultingMatches); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <jas...@us...> - 2006-06-30 04:10:24
|
Revision: 1504 Author: jasonpmorrison Date: 2006-06-29 21:10:18 -0700 (Thu, 29 Jun 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1504&view=rev Log Message: ----------- - Added additional local var matching - Added instance var matching Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java 2006-06-30 04:10:03 UTC (rev 1503) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java 2006-06-30 04:10:18 UTC (rev 1504) @@ -11,6 +11,8 @@ import org.jruby.ast.ArgumentNode; import org.jruby.ast.BlockNode; import org.jruby.ast.CallNode; +import org.jruby.ast.ClassNode; +import org.jruby.ast.Colon2Node; import org.jruby.ast.DVarNode; import org.jruby.ast.DefnNode; import org.jruby.ast.DefsNode; @@ -18,6 +20,7 @@ import org.jruby.ast.GlobalVarNode; import org.jruby.ast.InstAsgnNode; import org.jruby.ast.InstVarNode; +import org.jruby.ast.ListNode; import org.jruby.ast.LocalAsgnNode; import org.jruby.ast.LocalVarNode; import org.jruby.ast.Node; @@ -58,7 +61,6 @@ System.out.println("Origin: " + orig.getClass().getName()); - // LocalAsgnNode if ( isLocalVarRef(orig) ) { pushLocalVarRefs( root, orig, references ); } @@ -81,7 +83,17 @@ private ISourcePosition getPositionOfName(Node node, Node scope) { ISourcePosition pos = node.getPosition(); + + //todo: refactor the getting-of-name String name = getLocalVarRefName(node, scope); + if ( name == null ) + { + name = getInstVarRefName(node, scope); + } + if ( name == null ) + { + System.err.println("Couldn't get the name for: " + node.toString() + " in " + scope.toString() ); + } return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), pos.getStartOffset(), pos.getStartOffset() + name.length() ); } @@ -107,6 +119,24 @@ if ( scope instanceof DefsNode ) { return ((DefsNode)scope).getBodyNode().getLocalNames()[((LocalVarNode)node).getCount()]; } + + // No enclosing ScopeNode found, try searching backwards for an AsgnNode + final int localVarCount = ((LocalVarNode)node).getCount(); + Node previousAssign = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(scope, node.getPosition().getStartOffset(), new INodeAcceptor() { + public boolean doesAccept(Node node) { + if ( node instanceof LocalAsgnNode ) + { + return ((LocalAsgnNode)node).getCount() == localVarCount; + } + return false; + } + }); + if ( previousAssign != null ) + { + return ((LocalAsgnNode)previousAssign).getName(); + } + + System.err.println("Unhandled scope for local var ref node found: " + scope.toString() ); //TODO: if scope instanceof Block Body? what type is this.. } @@ -114,9 +144,41 @@ return ((DVarNode)node).getName(); } +// System.err.println("Encountered unhandled node type in getLocalVarRefName: " + node.toString() + " in " + scope.toString()); return null; } + private String getClassNodeName( ClassNode classNode ) { + if (classNode.getCPath() instanceof Colon2Node) { + Colon2Node c2node = (Colon2Node) classNode.getCPath(); + return c2node.getName(); + } + System.err.println("ClassNode.getCPath() returned other than Colon2Node: " + classNode.toString() ); + return null; + } + + + private String getInstVarRefName( Node node, Node scope ) { + if ( node instanceof InstAsgnNode ) { + return ((InstAsgnNode)node).getName(); + } + + if ( node instanceof ArgumentNode ) { + return ((InstAsgnNode)node).getName(); + } + + if ( node instanceof InstVarNode ) { + return ((InstVarNode)node).getName(); + } + + if ( node instanceof DVarNode ) { + return ((DVarNode)node).getName(); + } + +// System.err.println("Encountered unhandled node type for getInstVarRefName: " + node.toString() + " in " + scope.toString()); + return null; + } + private boolean isLocalVarRef( Node node ) { return ( ( node instanceof LocalAsgnNode ) || ( node instanceof ArgumentNode ) || ( node instanceof LocalVarNode ) ); } @@ -135,15 +197,22 @@ private void pushLocalVarRefs( Node root, Node orig, List<ISourcePosition> references ) { -// System.out.println("Finding references for a local variable " + orig.toString()); + System.out.println("Finding references for a local variable " + orig.toString()); // Find the search space - final Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() { + Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() { public boolean doesAccept(Node node) { return ( ( node instanceof DefnNode ) || ( node instanceof DefsNode ) /*TODO: Block Body? */ ); } }); + // If no enclosing node found, search the entire space + if ( searchSpace == null ) { + searchSpace = root; + } + + // Finalize searchSpace because Java's scoping rules are the awesome + final Node finalSearchSpace = searchSpace; // Get name of local variable reference final String origName = getLocalVarRefName(orig,searchSpace); @@ -151,7 +220,7 @@ // Find all pertinent nodes List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() { public boolean doesAccept(Node node) { - String name = getLocalVarRefName(node, searchSpace); + String name = getLocalVarRefName(node, finalSearchSpace); // System.out.println("Matching name" + name); return ( name != null && name.equals(origName)); } @@ -166,7 +235,61 @@ } private void pushInstVarRefs( Node root, Node orig, List<ISourcePosition> references ) { + System.out.println("Finding references for an instance variable " + orig.toString() ); + Node searchSpace; + + // Find the name of the enclosing class + ClassNode enclosingClass = (ClassNode)FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() { + public boolean doesAccept(Node node) { + return ( node instanceof ClassNode ); + } + }); + + // If no enclosing class is identified, search root. + if ( enclosingClass == null ) { + searchSpace = root; + } + // Find the search space - all ClassNodes for that name within root scope + else { + final String className = getClassNodeName(enclosingClass); + List<Node> classNodes = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() { + public boolean doesAccept(Node node) { + if ( node instanceof ClassNode ) + { + return getClassNodeName((ClassNode)node).equals(className); + } + return false; + } + }); + //todo: is this cool with the "n/a" and all? + BlockNode blockNode = new BlockNode(new SourcePosition("n/a",0));//new ListNode(new SourcePosition("n/a",0)); + for ( Node classNode : classNodes ) + { + blockNode.add( classNode ); + } + searchSpace = blockNode; + } + + // Finalize searchSpace because Java's scoping rules are the awesome + final Node finalSearchSpace = searchSpace; + + // Get name of local variable reference + final String origName = getInstVarRefName(orig,searchSpace); + + // Find all pertinent nodes + List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() { + public boolean doesAccept(Node node) { + String name = getInstVarRefName(node, finalSearchSpace); + return ( name != null && name.equals(origName)); + } + }); + + // Scrape position from pertinent nodes + for ( Node searchResult : searchResults ) { + references.add(getPositionOfName(searchResult, searchSpace)); + } + } private void pushGlobalVarRefs( Node root, Node orig, List<ISourcePosition> references ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
|
From: <jas...@us...> - 2006-06-30 04:10:10
|
Revision: 1503 Author: jasonpmorrison Date: 2006-06-29 21:10:03 -0700 (Thu, 29 Jun 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1503&view=rev Log Message: ----------- - Added additional local var matching - Added instance var matching Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/ReferenceMatchTest.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/ReferenceMatchTest.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/ReferenceMatchTest.java 2006-06-29 19:17:08 UTC (rev 1502) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/ReferenceMatchTest.java 2006-06-30 04:10:03 UTC (rev 1503) @@ -19,8 +19,9 @@ referenceFinder = new DefaultReferenceFinder(); } - private void assertReferencesEquals( String source, List<ISourcePosition> references, int[][] offsets, String matchName ) + private void assertReferencesEquals( String source, int offset, String matchName, int[][] offsets ) { + List <ISourcePosition> references = referenceFinder.findReferences(source, offset); assertEquals( offsets.length, references.size() ); for ( int i = 0; i < offsets.length; i++ ) { @@ -29,16 +30,59 @@ assertEquals( matchName, source.substring(references.get(i).getStartOffset(), references.get(i).getEndOffset())); } } + + /** + * Match locals within ClassNode::DefnNode + */ public void testLocalVariableMatches() { String source = "class Klass;def foo(x);puts x*2;end;def bar;my_var = 5;my_var = 6;puts my_var;foo(my_var);end;end"; - List <ISourcePosition> references = referenceFinder.findReferences(source, 46); - assertEquals( 4, references.size() ); - int[][] offsets = {{44,50},{55,61},{71,77},{82,88}}; - String matchName = "my_var"; - - assertReferencesEquals( source, references, offsets, matchName ); - + assertReferencesEquals( source, 46, "my_var", offsets ); } + + /** + * Match locals within Kernel::DefnNode + */ + public void testLocalVariablesInKernelDefnScope() { + String source = "def foo;my_var=5;puts my_var*2;end"; + int[][] offsets = {{8,14},{22,28}}; + assertReferencesEquals( source, 10, "my_var", offsets ); + } + + /** + * Match locals in Kernel + */ + public void testLocalVariablesInKernelScope() { + String source = "my_var = 5;puts my_var*2;other_var = my_var * my_var"; + int[][] offsets = {{0,6},{16,22},{37,43},{46,52}}; + assertReferencesEquals( source, 1, "my_var", offsets ); + } + + /** + * Match instance vars inside one ClassNode across DefnNode + */ + public void testInstanceVariableMatches() { + String source = "class Klass;def foo(param);@inst_var = param;puts @inst_var;end;def bar;y @inst_var;end;end"; + int[][] offsets = {{27,36},{50,59},{74,83}}; + assertReferencesEquals( source, 29, "@inst_var", offsets ); + } + /** + * Match instance vars inside two DefnNodes, each in a separate ClassNode (for the same class) + */ + public void testInstanceVariableMatchInReopenedClass() { + String source = "class Klass;def foo;@inst_var=5;end;end;class Klass;def bar;@inst_var=6;end;end"; + int[][] offsets = {{20,29},{60,69}}; + assertReferencesEquals( source, 23, "@inst_var", offsets ); + } + + /** + * Test matching a local variable before, inside, and after a block. + */ + public void testLocalVariableMatchesIntoBlockScope() { + String source = "class Klass;def foo;my_var = 5;5.times { puts my_var };puts my_var;end;end"; + int[][] offsets = {{20,26},{46,52},{60,66}}; + assertReferencesEquals( source, 23, "my_var", offsets ); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |