Permalink
Browse files

Merge remote branch 'origin/wip_experiment' into wip_experiment

  • Loading branch information...
2 parents 4ca7eae + f0e1fde commit f4712c7db828eae229afc9779ee5702c81c5b66f @lindydonna lindydonna committed Apr 11, 2011
Showing with 1,077 additions and 472 deletions.
  1. +4 −2 org.scala-ide.sdt.core/.classpath
  2. +6 −0 org.scala-ide.sdt.core/.project
  3. +4 −1 org.scala-ide.sdt.core/META-INF/MANIFEST.MF
  4. +10 −9 org.scala-ide.sdt.core/build.properties
  5. BIN org.scala-ide.sdt.core/lib/miglayout-3.7.4-swt.jar
  6. +17 −1 org.scala-ide.sdt.core/plugin.xml
  7. +7 −0 org.scala-ide.sdt.core/pom.xml
  8. +3 −3 org.scala-ide.sdt.core/src/scala/tools/eclipse/LocateSymbol.scala
  9. +53 −49 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaHyperlinkDetector.scala
  10. +6 −22 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaPresentationCompiler.scala
  11. +49 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaPreviewerFactory.scala
  12. +1 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaSourceViewerConfiguration.scala
  13. +12 −2 org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaStructureSelectEnclosingAction.scala
  14. +403 −28 org.scala-ide.sdt.core/src/scala/tools/eclipse/formatter/FormatterPreferencePage.scala
  15. +75 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/formatter/FormatterPreferences.scala
  16. +2 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/formatter/ScalaFormatterCleanUpProvider.scala
  17. +23 −12 org.scala-ide.sdt.core/src/scala/tools/eclipse/formatter/ScalaFormatterPreferenceInitializer.scala
  18. +27 −21 org.scala-ide.sdt.core/src/scala/tools/eclipse/formatter/ScalaFormattingStrategy.scala
  19. +20 −16 org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaOverrideIndicatorBuilder.scala
  20. +3 −1 org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaStructureBuilder.scala
  21. +5 −2 org.scala-ide.sdt.core/src/scala/tools/eclipse/lexical/ScalaDocumentPartitioner.scala
  22. +17 −46 org.scala-ide.sdt.core/src/scala/tools/eclipse/properties/SyntaxColouringPreferencePage.scala
  23. +11 −13 org.scala-ide.sdt.core/src/scala/tools/eclipse/ui/ScalaIndenter.scala
  24. +62 −0 org.scala-ide.sdt.core/src/scala/tools/eclipse/util/SWTUtils.scala
  25. +191 −175 org.scala-ide.sdt.core/src/scala/tools/eclipse/wizards/AbstractNewElementWizardPage.scala
  26. +66 −67 org.scala-ide.sdt.core/test/scala/tools/eclipse/ReferencesSearchTest.scala
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" output="target/classes" path="src"/>
<classpathentry kind="src" output="target/test-classes" path="test"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_COMPILER_CONTAINER"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="lib/miglayout-3.7.4-swt.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.scala-ide.sdt.core.scalanature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
@@ -42,7 +42,8 @@ Require-Bundle:
org.scala-ide.scala.compiler,
org.scala-refactoring.library,
scalariform,
- org.junit4;bundle-version="4.5.0"
+ org.junit4;bundle-version="4.5.0",
+ org.eclipse.ui.browser;bundle-version="3.3.0"
Import-Package:
org.eclipse.contribution.jdt.cuprovider;apply-aspects:=false,
org.eclipse.contribution.jdt.imagedescriptor;apply-aspects:=false,
@@ -73,3 +74,5 @@ Export-Package:
scala.tools.eclipse.util,
scala.tools.eclipse.wizards
Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ClassPath: .,
+ lib/miglayout-3.7.4-swt.jar
@@ -1,12 +1,13 @@
source.. = src/
output.. = target/classes/
bin.includes = META-INF/,\
- .,\
- docs/,\
- icons/,\
- plugin.xml,\
- toc.xml,\
- license.html,\
- about.ini,\
- about.png,\
- templates/
+ .,\
+ docs/,\
+ icons/,\
+ plugin.xml,\
+ toc.xml,\
+ license.html,\
+ about.ini,\
+ about.png,\
+ templates/,\
+ lib/
Binary file not shown.
@@ -6,7 +6,23 @@
<page
class="scala.tools.eclipse.properties.CompilerSettings"
id="org.scala-ide.sdt.core.properties.compilerPropertyPage"
- name="Scala Compiler Properties">
+ name="Scala Compiler">
+ <filter
+ name="nature"
+ value="org.scala-ide.sdt.core.scalanature"/>
+ <enabledWhen>
+ <or> <instanceof value="org.eclipse.jdt.core.IJavaProject"/>
+ <instanceof value="org.eclipse.core.resources.IProject"/>
+ </or>
+ </enabledWhen>
+ </page>
+ </extension>
+ <extension
+ point="org.eclipse.ui.propertyPages">
+ <page
+ class="scala.tools.eclipse.formatter.FormatterPreferencePage"
+ id="scala.tools.eclipse.formatter.FormatterPropertyPage"
+ name="Scala Formatter">
<filter
name="nature"
value="org.scala-ide.sdt.core.scalanature"/>
@@ -17,6 +17,13 @@
<artifactId>org.scala-ide.sdt.aspects</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>com.miglayout</groupId>
+ <artifactId>miglayout</artifactId>
+ <version>3.7.4</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
<build>
@@ -22,8 +22,8 @@ import scala.tools.nsc.io.AbstractFile
import javaelements.{ScalaSourceFile, ScalaClassFile, ScalaCompilationUnit}
trait LocateSymbol { self : ScalaPresentationCompiler =>
-
- def locate(sym : Symbol, scu : ScalaCompilationUnit) = {
+
+ def locate(sym : Symbol, scu : ScalaCompilationUnit): Option[(ScalaCompilationUnit, Int)] = {
def find[T, V](arr : Array[T])(f : T => Option[V]) : Option[V] = {
for(e <- arr) {
f(e) match {
@@ -58,7 +58,7 @@ trait LocateSymbol { self : ScalaPresentationCompiler =>
(if (sym.pos eq NoPosition) {
file.withSourceFile { (f, _) =>
val pos = new Response[Position]
- getLinkPos(sym, f, pos)
+ askLinkPos(sym, f, pos)
askReload(scu, scu.getContents)
pos.get.left.toOption
} (None)
@@ -28,58 +28,62 @@ class ScalaHyperlinkDetector extends AbstractHyperlinkDetector with Logger {
val textEditor = getAdapter(classOf[ITextEditor]).asInstanceOf[ITextEditor]
detectHyperlinks(textEditor, region, canShowMultipleHyperlinks)
}
-
- def detectHyperlinks(textEditor : ITextEditor, region : IRegion, canShowMultipleHyperlinks : Boolean) : Array[IHyperlink] = {
- EditorUtility.getEditorInputJavaElement(textEditor, false) match {
- case scu : ScalaCompilationUnit =>
- scu.withSourceFile({ (sourceFile, compiler) =>
- val wordRegion = ScalaWordFinder.findWord(scu.getContents, region.getOffset)
- if (wordRegion == null || wordRegion.getLength == 0)
- null
- else {
- val pos = compiler.rangePos(sourceFile, wordRegion.getOffset, wordRegion.getOffset, wordRegion.getOffset + wordRegion.getLength)
-
- val response = new compiler.Response[compiler.Tree]
- compiler.askTypeAt(pos, response)
- val typed = response.get
-
- log("detectHyperlinks: wordRegion = "+wordRegion)
-
- compiler.ask { () =>
- case class Hyperlink(file : Openable, pos : Int) extends IHyperlink {
- def getHyperlinkRegion = wordRegion
- def getTypeLabel = null
- def getHyperlinkText = "Open Declaration"
- def open = {
- EditorUtility.openInEditor(file, true) match {
- case editor : ITextEditor => editor.selectAndReveal(pos, 0)
- case _ =>
- }
+
+ case class Hyperlink(file: Openable, pos: Int)(wordRegion: IRegion) extends IHyperlink {
+ def getHyperlinkRegion = wordRegion
+ def getTypeLabel = null
+ def getHyperlinkText = "Open Declaration"
+ def open = {
+ EditorUtility.openInEditor(file, true) match {
+ case editor: ITextEditor => editor.selectAndReveal(pos, 0)
+ case _ =>
+ }
+ }
+ }
+
+ def detectHyperlinks(textEditor: ITextEditor, region: IRegion, canShowMultipleHyperlinks: Boolean): Array[IHyperlink] = {
+ if (textEditor == null) // can be null if generated through ScalaPreviewerFactory
+ null
+ else
+ EditorUtility.getEditorInputJavaElement(textEditor, false) match {
+ case scu: ScalaCompilationUnit =>
+ scu.withSourceFile({ (sourceFile, compiler) =>
+ val wordRegion = ScalaWordFinder.findWord(scu.getContents, region.getOffset)
+ if (wordRegion == null || wordRegion.getLength == 0)
+ null
+ else {
+ val pos = compiler.rangePos(sourceFile, wordRegion.getOffset, wordRegion.getOffset, wordRegion.getOffset + wordRegion.getLength)
+
+ val response = new compiler.Response[compiler.Tree]
+ compiler.askTypeAt(pos, response)
+ val typed = response.get
+
+ log("detectHyperlinks: wordRegion = " + wordRegion)
+ val hyperlinks: Option[Hyperlink] = compiler.ask { () =>
+ import compiler.{ log => _, _ }
+
+ typed.left.toOption map {
+ case Import(expr, sels) => sels find (_.namePos >= pos.start) map (sel => expr.tpe.member(sel.name)) getOrElse NoSymbol
+ case Annotated(atp, _) => atp.symbol
+ case st: SymTree => st.symbol
+ case t => log("unhandled tree " + t); NoSymbol
+ } flatMap { sym =>
+ if (sym.isPackage || sym == NoSymbol || sym.isJavaDefined)
+ None
+ else
+ compiler.locate(sym, scu) map { case (f, pos) => Hyperlink(f, pos)(wordRegion) }
}
}
-
- import compiler.{log =>_, _}
- typed.left.toOption map ( _ match {
- case Import(expr, sels) => sels find (_.namePos >= pos.start) map (sel => expr.tpe.member(sel.name)) getOrElse NoSymbol
- case Annotated(atp, _) => atp.symbol
- case st : SymTree => st.symbol
- case t =>
- log("unhandled tree " + t); NoSymbol
- }) flatMap { sym =>
- if (sym.isPackage || sym == NoSymbol || sym.isJavaDefined)
- None
- else
- compiler.locate(sym, scu) map { case (f, pos) => Hyperlink(f, pos) }
- }
- } map (Array(_ : IHyperlink)) getOrElse {
- log("!!! Falling back to selection engine for %s!".format(typed.left), Category.ERROR)
- codeSelect(textEditor, wordRegion, scu)
+ if (!hyperlinks.isDefined) {
+ log("!!! Falling back to selection engine for %s!".format(typed.left), Category.ERROR)
+ codeSelect(textEditor, wordRegion, scu)
+ } else
+ Array(hyperlinks.get: IHyperlink)
}
- }
- }) (null)
-
- case _ => null
- }
+ })(null)
+
+ case _ => null
+ }
}
//Default path used for selecting.
@@ -51,9 +51,7 @@ class ScalaPresentationCompiler(project : ScalaProject, settings : Settings)
val response = new Response[Tree]
askLoadedTyped(unit.source, response)
response.get
- val result = unit.problems.toList flatMap presentationReporter.eclipseProblem
- //unit.problems.clear()
- result
+ unit.problems.toList flatMap presentationReporter.eclipseProblem
case None =>
Nil
}
@@ -63,27 +61,13 @@ class ScalaPresentationCompiler(project : ScalaProject, settings : Settings)
def withSourceFile[T](scu : ScalaCompilationUnit)(op : (SourceFile, ScalaPresentationCompiler) => T) : T =
op(sourceFiles(scu), this)
-
- override def ask[A](op: () => A): A = if (Thread.currentThread == compileRunner) op() else super.ask(op)
-
- override def askTypeAt(pos: Position, response: Response[Tree]) = {
- if (Thread.currentThread == compileRunner) getTypedTreeAt(pos, response) else super.askTypeAt(pos, response)
- }
-
- override def askParsedEntered(source: SourceFile, keepLoaded: Boolean, response: Response[Tree]) {
- if (Thread.currentThread == compileRunner)
- getParsedEntered(source, keepLoaded, response)
- else
- super.askParsedEntered(source, keepLoaded, response)
- }
def body(sourceFile : SourceFile) = {
- val tree = new Response[Tree]
- if (Thread.currentThread == compileRunner)
- getTypedTree(sourceFile, false, tree) else askType(sourceFile, false, tree)
- tree.get match {
- case Left(l) => l
- case Right(r) => throw r
+ val response = new Response[Tree]
+ askType(sourceFile, false, response)
+ response.get match {
+ case Left(tree) => tree
+ case Right(exc) => throw exc
}
}
@@ -0,0 +1,49 @@
+package scala.tools.eclipse
+
+import org.eclipse.jface.util.{ IPropertyChangeListener, PropertyChangeEvent }
+import org.eclipse.jface.text.IDocument
+import org.eclipse.jface.text.Document
+import lexical.ScalaDocumentPartitioner
+import org.eclipse.jdt.ui.text.IJavaPartitions
+import org.eclipse.jface.text.IDocumentPartitioner
+import org.eclipse.swt.SWT
+import org.eclipse.jdt.ui.PreferenceConstants
+import org.eclipse.jface.resource.JFaceResources
+import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer
+import org.eclipse.swt.widgets.Control
+import org.eclipse.jface.preference.IPreferenceStore
+import org.eclipse.jface.text.TextUtilities
+import java.util.HashMap
+
+import org.eclipse.swt.widgets.Composite
+
+object ScalaPreviewerFactory {
+
+ def createPreviewer(parent: Composite, preferenceStore: IPreferenceStore, initialText: String): (Control, IDocument) = {
+
+ val previewViewer = new JavaSourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, preferenceStore)
+ val font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT)
+ previewViewer.getTextWidget.setFont(font)
+ previewViewer.setEditable(false)
+
+ val configuration = new ScalaSourceViewerConfiguration(preferenceStore, preferenceStore, null)
+ previewViewer.configure(configuration)
+
+ val document = new Document
+ document.set(initialText)
+ val partitioners = new HashMap[String, IDocumentPartitioner]
+ partitioners.put(IJavaPartitions.JAVA_PARTITIONING, new ScalaDocumentPartitioner(conservative = true))
+ TextUtilities.addDocumentPartitioners(document, partitioners)
+ previewViewer.setDocument(document)
+
+ preferenceStore.addPropertyChangeListener(new IPropertyChangeListener {
+ def propertyChange(event: PropertyChangeEvent) {
+ if (configuration.affectsTextPresentation(event))
+ configuration.handlePropertyChangeEvent(event)
+ previewViewer.invalidateTextPresentation()
+ }
+ })
+ (previewViewer.getControl, document)
+ }
+
+}
@@ -123,7 +123,7 @@ class ScalaSourceViewerConfiguration(store: IPreferenceStore, scalaPreferenceSto
override def getContentFormatter(sourceViewer: ISourceViewer) = {
val contentFormatter = new ContentFormatter
contentFormatter.enablePartitionAwareFormatting(false);
- contentFormatter.setFormattingStrategy(new ScalaFormattingStrategy(sourceViewer), IDocument.DEFAULT_CONTENT_TYPE)
+ contentFormatter.setFormattingStrategy(new ScalaFormattingStrategy(editor), IDocument.DEFAULT_CONTENT_TYPE)
contentFormatter
}
@@ -5,19 +5,29 @@ import org.eclipse.jdt.internal.ui.javaeditor.selectionactions._
import org.eclipse.jface.action.Action
import org.eclipse.jface.text.ITextSelection
+import scalariform.parser.ScalaParserException
import scalariform.astselect.AstSelector
import scalariform.utils.Range
-
/**
* A Scala-aware replacement for {@link org.eclipse.jdt.internal.ui.javaeditor.selectionactions.StructureSelectEnclosingAction}.
*/
class ScalaStructureSelectEnclosingAction(editor: ScalaSourceFileEditor, selectionHistory: SelectionHistory) extends Action {
+ private var previousAstSelector: Option[(String, AstSelector)] = None
+
override def run() {
val source = editor.getDocumentProvider.getDocument(editor.getEditorInput).get
+ val astSelector = previousAstSelector match {
+ case Some((previousSource, astSelector)) if previousSource == source => astSelector
+ case _ =>
+ try new AstSelector(source)
+ catch { case _: ScalaParserException => return }
+ }
+ previousAstSelector = Some(source, astSelector)
+
val selection = editor.getSelectionProvider.getSelection.asInstanceOf[ITextSelection]
val selectionRange = Range(selection.getOffset, selection.getLength)
- for (Range(offset, length) <- AstSelector.expandSelection(source, selectionRange)) {
+ for (Range(offset, length) <- astSelector.expandSelection(selectionRange)) {
selectionHistory.remember(new SourceRange(selection.getOffset, selection.getLength))
try {
selectionHistory.ignoreSelectionChanges()
Oops, something went wrong.

0 comments on commit f4712c7

Please sign in to comment.