From 88848b8e7ec0c9ef372cb59901d74e1edc4b6096 Thu, 12 Aug 2010 13:57:48 +0800 From: Jin Mingjian Date: Sun, 8 Aug 2010 16:11:11 +0800 Subject: [PATCH] add the Implicit Args annonations implementation(shared preferences with that of implicit conversion) diff --git a/org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaSourceFileEditor.scala b/org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaSourceFileEditor.scala index 5b257ed..08d2d0d 100644 --- a/org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaSourceFileEditor.scala +++ b/org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaSourceFileEditor.scala @@ -149,8 +149,7 @@ // val presenter = new SemanticHighlightingPresenter(this,getSourceViewer()) getSourceViewer().getDocument().addDocumentListener(presenter) -// getSourceViewer().addTextInputListener(presenter) -// getSourceViewer().asInstanceOf[org.eclipse.jface.text.TextViewer].addTextPresentationListener(presenter) + presenter.update() } } diff --git a/org.scala-ide.sdt.core/src/scala/tools/eclipse/ui/semantic/highlighting/SemanticHighlightingPresenter.scala b/org.scala-ide.sdt.core/src/scala/tools/eclipse/ui/semantic/highlighting/SemanticHighlightingPresenter.scala index 282af9e..5be4bcd 100644 --- a/org.scala-ide.sdt.core/src/scala/tools/eclipse/ui/semantic/highlighting/SemanticHighlightingPresenter.scala +++ b/org.scala-ide.sdt.core/src/scala/tools/eclipse/ui/semantic/highlighting/SemanticHighlightingPresenter.scala @@ -11,18 +11,13 @@ import org.eclipse.jface.preference.IPreferenceStore import org.eclipse.jface.preference.PreferenceConverter - import org.eclipse.jface.text.source.ISourceViewer; - import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentListener; -import org.eclipse.jface.text.ITextInputListener; -import org.eclipse.jface.text.ITextPresentationListener; import org.eclipse.jface.text.TextPresentation; import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jface.text.source.{IAnnotationAccess,AnnotationPainter,IAnnotationModelExtension}; - +import org.eclipse.jface.text.source.{ IAnnotationAccess, AnnotationPainter, IAnnotationModelExtension }; import org.eclipse.swt.SWT import scala.tools.eclipse.javaelements.ScalaCompilationUnit; @@ -35,90 +30,99 @@ * @author Jin Mingjian * */ -class SemanticHighlightingPresenter(fEditor: CompilationUnitEditor, fSourceViewer: ISourceViewer) extends IDocumentListener { - - var currentAnnotations: Array[Annotation] = _ - +class SemanticHighlightingPresenter(fEditor: CompilationUnitEditor, fSourceViewer: ISourceViewer) + extends IDocumentListener { + + var currentAnnotations: List[Annotation] = List() + val annotationAccess = new IAnnotationAccess() { def getType(annotation: Annotation) = annotation.getType(); - def isMultiLine(annotation: Annotation) = true + def isMultiLine(annotation: Annotation) = true def isTemporary(annotation: Annotation) = true }; val painter = new AnnotationPainter(fSourceViewer, annotationAccess); import scala.tools.eclipse.ui.preferences.ScalaEditorColoringPreferencePage._ val fUnderlineStyle = getPreferenceStore().getInt(P_UNDERLINE) match { - case 1 => SWT.UNDERLINE_SQUIGGLE - case 2 => SWT.UNDERLINE_DOUBLE - case 3 => SWT.UNDERLINE_SINGLE - case 4 => 8 // for no underline case + case 1 => SWT.UNDERLINE_SQUIGGLE + case 2 => SWT.UNDERLINE_DOUBLE + case 3 => SWT.UNDERLINE_SINGLE + case 4 => 8 // for no underline case } - val fFontStyle1 = getPreferenceStore().getBoolean(P_BLOD) match { - case true => SWT.BOLD - case _ => SWT.NORMAL + val fFontStyle1 = getPreferenceStore().getBoolean(P_BLOD) match { + case true => SWT.BOLD + case _ => SWT.NORMAL } - val fFontStyle2 = getPreferenceStore().getBoolean(P_ITALIC) match { - case true => SWT.ITALIC - case _ => SWT.NORMAL + val fFontStyle2 = getPreferenceStore().getBoolean(P_ITALIC) match { + case true => SWT.ITALIC + case _ => SWT.NORMAL } - val fColorValue = PreferenceConverter.getColor(getPreferenceStore(),P_COLOR) - painter.addTextStyleStrategy(ImplicitConversionsOrArgsAnnotation.KIND, - new ImplicitConversionsOrArgsDrawingStrategy(fUnderlineStyle,fFontStyle1 | fFontStyle2) ); + val fColorValue = PreferenceConverter.getColor(getPreferenceStore(), P_COLOR) + painter.addTextStyleStrategy(ImplicitConversionsOrArgsAnnotation.KIND, + new ImplicitConversionsOrArgsDrawingStrategy(fUnderlineStyle, fFontStyle1 | fFontStyle2)); painter.addAnnotationType(ImplicitConversionsOrArgsAnnotation.KIND, ImplicitConversionsOrArgsAnnotation.KIND); - painter.setAnnotationTypeColor(ImplicitConversionsOrArgsAnnotation.KIND, - ColorManager.getDefault.getColor(fColorValue)) + painter.setAnnotationTypeColor(ImplicitConversionsOrArgsAnnotation.KIND, + ColorManager.getDefault.getColor(fColorValue)) fSourceViewer.asInstanceOf[org.eclipse.jface.text.TextViewer].addPainter(painter); fSourceViewer.asInstanceOf[org.eclipse.jface.text.TextViewer].addTextPresentationListener(painter); - - - /** - * The manipulation described by the document event will be performed. - * - * @param event the document event describing the document change - */ - override def documentAboutToBeChanged(event: DocumentEvent){} + + /** + * The manipulation described by the document event will be performed. + * + * @param event the document event describing the document change + */ + override def documentAboutToBeChanged(event: DocumentEvent) {} + + /** + * The manipulation described by the document event has been performed. + * + * @param event the document event describing the document change + */ + override def documentChanged(event: DocumentEvent) { + update() + } + + def update() { + val cu = JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput()); + val scu = cu.asInstanceOf[ScalaCompilationUnit] + scu.withCompilerResult({ crh => + import crh._ + + val toAdds = new java.util.HashMap[Annotation, org.eclipse.jface.text.Position] + var toAddAnnotations = List[Annotation]() + object viewsCollector extends compiler.Traverser { + override def traverse(t: compiler.Tree): Unit = t match { + case v: compiler.ApplyImplicitView => + val ia = new ImplicitConversionsOrArgsAnnotation(ImplicitConversionsOrArgsAnnotation.KIND, + false, + v.fun.toString) + val pos = new org.eclipse.jface.text.Position(v.pos.start, v.pos.end - v.pos.start); + toAdds.put(ia, pos) + toAddAnnotations = ia :: toAddAnnotations + println(v) + super.traverse(t) + case v: compiler.ApplyToImplicitArgs => + val ia = new ImplicitConversionsOrArgsAnnotation(ImplicitConversionsOrArgsAnnotation.KIND, + false, + v.fun.toString) + val pos = new org.eclipse.jface.text.Position(v.pos.start, v.pos.end - v.pos.start); + toAdds.put(ia, pos) + toAddAnnotations = ia :: toAddAnnotations + println(v) + super.traverse(t) + case _ => + super.traverse(t) + } + } + viewsCollector.traverse(body) + + val model = fSourceViewer.getAnnotationModel() + if (model != null) model.asInstanceOf[IAnnotationModelExtension].replaceAnnotations(currentAnnotations.toArray, toAdds); + currentAnnotations = toAddAnnotations + }) + } + + def getPreferenceStore(): IPreferenceStore = { + scala.tools.eclipse.ScalaPlugin.plugin.getPreferenceStore() + } - /** - * The manipulation described by the document event has been performed. - * - * @param event the document event describing the document change - */ - override def documentChanged(event: DocumentEvent) { - update() - } - - - def update() { - val cu = JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput()); - val scu = cu.asInstanceOf[ScalaCompilationUnit] - scu.withCompilerResult({ crh => - import crh._ - - val toAdds = new java.util.HashMap[Annotation,org.eclipse.jface.text.Position] - var toAddAnnotations = List[Annotation]() - object viewsCollector extends compiler.Traverser { - override def traverse(t: compiler.Tree): Unit = t match { - case v: compiler.ApplyImplicitView => - val ia = new ImplicitConversionsOrArgsAnnotation(ImplicitConversionsOrArgsAnnotation.KIND, - false, - v.fun.toString) - val pos = new org.eclipse.jface.text.Position(v.pos.start, v.pos.end-v.pos.start); - toAdds.put(ia,pos) - toAddAnnotations = ia::toAddAnnotations - println(v) - super.traverse(t) - case _ => - super.traverse(t) - } - } - viewsCollector.traverse(body) - - fSourceViewer.getAnnotationModel().asInstanceOf[IAnnotationModelExtension].replaceAnnotations(currentAnnotations,toAdds); - currentAnnotations = toAddAnnotations.toArray - }) - } - - def getPreferenceStore(): IPreferenceStore = { - scala.tools.eclipse.ScalaPlugin.plugin.getPreferenceStore() - } - } \ No newline at end of file -- Git Team Provider UI (Incubation) 0.8.4