|
From: <caw...@us...> - 2007-05-23 03:02:32
|
Revision: 2523
http://svn.sourceforge.net/rubyeclipse/?rev=2523&view=rev
Author: cawilliams
Date: 2007-05-22 20:02:18 -0700 (Tue, 22 May 2007)
Log Message:
-----------
move the code which grabbed comments/docs for an IRubyElement into the util class in rdt.core. Now just refer to that class to grab them
Modified Paths:
--------------
trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java
Modified: trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java 2007-05-23 03:01:47 UTC (rev 2522)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/internal/ui/text/ruby/hover/CommentHoverProvider.java 2007-05-23 03:02:18 UTC (rev 2523)
@@ -1,18 +1,13 @@
package com.aptana.rdt.internal.ui.text.ruby.hover;
-import java.util.Collection;
-
import org.eclipse.jface.text.DefaultInformationControl;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
-import org.jruby.ast.CommentNode;
-import org.jruby.lexer.yacc.ISourcePosition;
import org.rubypeople.rdt.core.IMember;
import org.rubypeople.rdt.core.IRubyElement;
-import org.rubypeople.rdt.core.RubyModelException;
-import org.rubypeople.rdt.internal.core.parser.RubyParser;
+import org.rubypeople.rdt.core.util.RDocUtil;
import org.rubypeople.rdt.internal.ui.text.HTMLPrinter;
import org.rubypeople.rdt.internal.ui.text.HTMLTextPresenter;
import org.rubypeople.rdt.internal.ui.text.ruby.IInformationControlExtension4;
@@ -39,61 +34,6 @@
*/
private IInformationControlCreator fPresenterControlCreator;
- /**
- * Grabs the comment from any comment node that follows this element (has to be on the same line)
- * @param comments
- * @param elementStart
- * @param src
- * @return
- */
- private String getFollowingComment(Collection<CommentNode> comments, int elementStart, String src) {
- for (CommentNode comment : comments) {
- ISourcePosition pos = comment.getPosition();
- if (pos.getStartOffset() < elementStart) continue;
- String between = src.substring(elementStart, pos.getStartOffset());
- if (between.contains("\n")) continue; // if there's a newline between the positions - it's not on same line
- String com = comment.getContent();
- if (com != null && com.length() > 0)
- return removePrecedingHashes(com);
- }
- return null;
- }
-
- /**
- * Grabs and merges together all comment nodes which immediately preced the elementStart offset.
- * @param comments
- * @param elementStart
- * @param src
- * @return a combined string of all immediately preceding comments
- */
- private String getPrecedingComment(Collection<CommentNode> comments, int elementStart, String src) {
- for (CommentNode comment : comments) {
- ISourcePosition pos = comment.getPosition();
- if (pos.getEndOffset() > elementStart) continue;
- String between = src.substring(pos.getEndOffset(), elementStart);
- if (between.trim().length() > 0)
- continue; // if there's anything but whitespace between (\n\r\t ), move to next comment
- String preceding = getPrecedingComment(comments, pos.getStartOffset(), src);
- if (preceding == null) {
- preceding = removePrecedingHashes(comment.getContent());
- } else {
- preceding += "\n" + removePrecedingHashes(comment.getContent());
- }
- return preceding;
- }
- return null;
- }
-
- /**
- * Trims the string and drops the beginning hash mark (#)
- * @param comment
- * @return
- */
- private String removePrecedingHashes(String comment) {
- comment = comment.trim();
- return comment.substring(1);
- }
-
/*
* @see RubyElementHover
*/
@@ -123,7 +63,7 @@
if (curr instanceof IMember) {
IMember member= (IMember) curr;
HTMLPrinter.addSmallHeader(buffer, getInfoText(member));
- String contents = getContents(member);
+ String contents = RDocUtil.getDocumentation(member);
if (contents != null) {
HTMLPrinter.addParagraph(buffer, contents);
}
@@ -145,24 +85,6 @@
return null;
}
-
- private String getContents(IMember member) {
- String src = "";
- int elementOffset = -1;
- try {
- src = member.getRubyScript().getSource();
- elementOffset = member.getSourceRange().getOffset();
- } catch (RubyModelException e) {
- return null;
- }
- RubyParser parser = new RubyParser();
- parser.parse(src); // parse so we can grab the comment nodes
- Collection<CommentNode> comments = parser.getComments();
- if (member.isType(IRubyElement.TYPE) || member.isType(IRubyElement.METHOD) || member.isType(IRubyElement.CONSTANT)) {
- return getPrecedingComment(comments, elementOffset, src);
- }
- return getFollowingComment(comments, elementOffset, src);
- }
/*
* @see IInformationProviderExtension2#getInformationPresenterControlCreator()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|