Permalink
Browse files

integrating the code review comments of Iulian + doing small other fixes

  • Loading branch information...
1 parent e7dae2f commit d4923fcca50db2664096fd1e8f1f950b815df801 @danielratiu danielratiu committed Jun 27, 2011
View
1 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaHover.scala
@@ -199,6 +199,7 @@ trait CommentToHtmlTransformer { self : ScalaPresentationCompiler =>
val resp = new Response[Tree]
val range = compiler.rangePos(src, pos, pos, pos + sym.name.length)
askTypeAt(range, resp)
+ resp.get
})();
case _ =>
}
View
116 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaSourceViewerConfiguration.scala
@@ -158,12 +158,114 @@ class ScalaSourceViewerConfiguration(store: IPreferenceStore, scalaPreferenceSto
override def getInformationPresenter(sourceViewer: ISourceViewer) = {
val informationPresenter = super.getInformationPresenter(sourceViewer)
val scalaHover = new ScalaHover(getCodeAssist)
- scalaHover.setEditor(this.getEditor())
- val informationProvider = informationPresenter.getInformationProvider(IDocument.DEFAULT_CONTENT_TYPE).asInstanceOf[JavaInformationProvider]
- val implementation =
- getDeclaredField(classOf[JavaInformationProvider], "fImplementation").
- get(informationProvider).asInstanceOf[JavaTypeHover]
- getDeclaredField(classOf[JavaTypeHover], "fJavadocHover").set(implementation, scalaHover);
- informationPresenter;
+ scalaHover.setEditor(this.getEditor())
+
+ //the next commented lines are replaced by the explicit reimplementation of the JavaInformationProvider and JavaTypeHover classes through
+ //ScalaInformationProvider and ScalaJavaTypeHover respectively
+
+// val informationProvider = informationPresenter.getInformationProvider(IDocument.DEFAULT_CONTENT_TYPE).asInstanceOf[JavaInformationProvider]
+// val implementation =
+// getDeclaredField(classOf[JavaInformationProvider], "fImplementation").
+// get(informationProvider).asInstanceOf[JavaTypeHover]
+// getDeclaredField(classOf[JavaTypeHover], "fJavadocHover").set(implementation, scalaHover);
+
+ import org.eclipse.jface.text.information.InformationPresenter
+ val newInformationProvider = new ScalaInformationProvider(getEditor(), scalaHover)
+ informationPresenter.asInstanceOf[InformationPresenter].setInformationProvider(newInformationProvider, IDocument.DEFAULT_CONTENT_TYPE)
+ informationPresenter;
}
+
+
+ import org.eclipse.ui.IEditorPart;
+ import org.eclipse.jface.text.information.IInformationProvider;
+ import org.eclipse.jface.text.information.IInformationProviderExtension;
+ import org.eclipse.jface.text.information.IInformationProviderExtension2;
+
+ /**
+ * A reimplementation of the JavaInformationProvider. The only difference is that the field fImplementation is now initialized with a
+ * ScalaJavaTypeHover object
+ */
+ class ScalaInformationProvider(editor : IEditorPart, scalaHover : ScalaHover) extends IInformationProvider with IInformationProviderExtension with IInformationProviderExtension2 {
+ import org.eclipse.jface.text.IInformationControlCreator;
+ import org.eclipse.jface.text.IRegion;
+ import org.eclipse.jface.text.ITextViewer;
+ import org.eclipse.jdt.internal.ui.text.JavaWordFinder;
+
+ val fImplementation : ScalaJavaTypeHover =
+ if (editor != null) {
+ val scalaJavaTypeHover = new ScalaJavaTypeHover(scalaHover)
+ scalaJavaTypeHover.setEditor(editor);
+ scalaJavaTypeHover
+ } else
+ null
+
+ def getSubject(textViewer : ITextViewer, offset : Int) : IRegion =
+ if (textViewer != null) JavaWordFinder.findWord(textViewer.getDocument(), offset)
+ else null
+
+ def getInformation(textViewer : ITextViewer, subject : IRegion) : String = {
+ if (fImplementation != null) {
+ val s= fImplementation.getHoverInfo(textViewer, subject);
+ if (s != null && s.trim().length() > 0)
+ return s;
+ }
+ return null;
+ }
+
+ def getInformation2(textViewer : ITextViewer, subject : IRegion) : Object =
+ if (fImplementation == null) null
+ else fImplementation.getHoverInfo2(textViewer, subject);
+
+ def getInformationPresenterControlCreator() : IInformationControlCreator =
+ if (fImplementation == null) null
+ else fImplementation.getInformationPresenterControlCreator();
+ }
+
+ import org.eclipse.jface.text.ITextHoverExtension;
+ import org.eclipse.jface.text.ITextHoverExtension2;
+ import org.eclipse.jdt.ui.text.java.hover.IJavaEditorTextHover;
+
+ /**
+ * A reimplementation of JavaTypeHover. The only difference is that the field fJavadocHover is set to an object of class ScalaHover
+ */
+ class ScalaJavaTypeHover(scalaHover : ScalaHover) extends IJavaEditorTextHover with ITextHoverExtension with ITextHoverExtension2 {
+ import org.eclipse.jface.text.IInformationControlCreator;
+ import org.eclipse.jface.text.IRegion;
+ import org.eclipse.jface.text.ITextViewer;
+ import org.eclipse.ui.IEditorPart;
+ import org.eclipse.jdt.internal.ui.text.java.hover.ProblemHover;
+
+ val fProblemHover : AbstractJavaEditorTextHover = new ProblemHover();
+ val fJavadocHover : AbstractJavaEditorTextHover = scalaHover;
+ var fCurrentHover : AbstractJavaEditorTextHover = null;
+
+ def setEditor(editor : IEditorPart) {
+ fProblemHover.setEditor(editor);
+ fJavadocHover.setEditor(editor);
+ fCurrentHover= null;
+ }
+
+ def getHoverRegion(textViewer : ITextViewer, offset : Int) : IRegion =
+ fJavadocHover.getHoverRegion(textViewer, offset);
+
+ def getHoverInfo(textViewer : ITextViewer, hoverRegion : IRegion) : String =
+ String.valueOf(getHoverInfo2(textViewer, hoverRegion));
+
+ def getHoverInfo2(textViewer : ITextViewer, hoverRegion : IRegion) : Object = {
+ val hoverInfo= fProblemHover.getHoverInfo2(textViewer, hoverRegion);
+ if (hoverInfo != null) {
+ fCurrentHover= fProblemHover;
+ hoverInfo;
+ } else {
+ fCurrentHover= fJavadocHover;
+ fJavadocHover.getHoverInfo2(textViewer, hoverRegion);
+ }
+ }
+
+ def getHoverControlCreator() : IInformationControlCreator =
+ if (fCurrentHover == null) null else fCurrentHover.getHoverControlCreator();
+
+ def getInformationPresenterControlCreator() : IInformationControlCreator =
+ if (fCurrentHover == null) null else fCurrentHover.getInformationPresenterControlCreator();
+ }
}
View
32 ...ala-ide.sdt.core/src/scala/tools/eclipse/completion/ScalaCompletionProposalComputer.scala
@@ -149,20 +149,24 @@ class ScalaCompletionProposalComputer extends IJavaCompletionProposalComputer wi
": " + tpe.finalResultType.toString}
else name
- def additionalInfoBuilder() : JavadocBrowserInformationControlInput = {
+ def additionalInfoBuilder() : JavadocBrowserInformationControlInput = {
+ import org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2
val buffer = new StringBuffer();
HTMLPrinter.insertPageProlog(buffer, 0, styleSheet);
-
- compiler.getJavaElement2(sym) match {
- case Some(element) =>
- val info = element.getAttachedJavadoc(null)
- if (info != null && info.length() > 0)
- buffer.append(info);
- else
- buffer.append(compiler.buildCommentAsHtml(scu, sym, tpe))
- case _ =>
- buffer.append(compiler.buildCommentAsHtml(scu, sym, tpe))
- }
+
+ if (sym.hasFlag(Flags.JAVA))
+ compiler.getJavaElement2(sym) match {
+ case Some(element) =>
+ val info = JavadocContentAccess2.getHTMLContent(element, true) //element.getAttachedJavadoc(null)
+ if (info != null && info.length() > 0)
+ buffer.append(info);
+ else
+ buffer.append(compiler.buildCommentAsHtml(scu, sym, tpe))
+ case _ =>
+ throw new IllegalStateException("getJavaElement2 did not find the corresponding Java element for symbol " + sym.fullName)
+ }
+ else
+ buffer.append(compiler.buildCommentAsHtml(scu, sym, tpe))
HTMLPrinter.addPageEpilog(buffer);
return new JavadocBrowserInformationControlInput(null, null, buffer.toString, 0);
@@ -182,6 +186,8 @@ class ScalaCompletionProposalComputer extends IJavaCompletionProposalComputer wi
}
val contextString = sym.paramss.map(_.map(p => "%s: %s".format(p.decodedName, p.tpe)).mkString("(", ", ", ")")).mkString("")
+
+ //create a new completion proposal object. The execution of 'additionalInfoBuilder' is deferred until the information is really needed
buff += new ScalaCompletionProposal(start, name, signature, contextString, additionalInfoBuilder, relevance, image, context.getViewer.getSelectionProvider)
}
@@ -232,7 +238,7 @@ class ScalaCompletionProposalComputer extends IJavaCompletionProposalComputer wi
lazy val informationControlCreator = {
import org.eclipse.jdt.internal.ui.JavaPlugin;
val shell= JavaPlugin.getActiveWorkbenchShell();
- if (shell == null || !BrowserInformationControl.isAvailable(shell))
+ if (!BrowserInformationControl.isAvailable(shell))
null
else {
val presenterControlCreator= new JavadocHover.PresenterControlCreator(EclipseUtils.getWorkbenchSite);

0 comments on commit d4923fc

Please sign in to comment.