Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression evaluator #906

Merged
merged 20 commits into from Apr 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitattributes
@@ -1,6 +1,9 @@
*.aj eol=lf
.classpath eol=lf
*.java eol=lf
*.MD eol=lf
*.MF eol=lf
.project eol=lf
*.properties eol=lf
*.pom eol=lf
*.scala eol=lf
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Expand Up @@ -2,4 +2,11 @@
**/*.tmpBin
target/
org.scala-ide.sdt.core/META-INF/MANIFEST.MF
org.scala-ide.sdt.debug/META-INF/MANIFEST.MF
org.scala-ide.sdt.update-site/site.xml
org.scala-ide.sdt.feature/feature.xml
org.scala-ide.sdt.source.feature/feature.xml
.idea
.metadata
*~
**/.settings/
5 changes: 5 additions & 0 deletions AUTHORS
Expand Up @@ -21,9 +21,11 @@ Ivan Kuraj <(λx.λy.x@y) (ivan.kuraj)(epfl.ch)>
James Earl Douglas <(λx.λy.x@y) (james)(earldouglas.com)>
Jedd Haberstro <(λx.λy.x@y) (jedd.haberstro)(typesafe.com)>
Jeremy Heiner <(λx.λy.x@y) (ScalaProtractor)(gmail.com)>
Jerzy Müller <(λx.λy.x@y) (sidus.gemini)(gmail.com)>
Jin Mingjian <(λx.λy.x@y) (jin.phd)(gmail.com)>
Jon Mundorf <(λx.λy.x@y) (ejmundorf)(gmail.com)>
Joshua Suereth <(λx.λy.x@y) (joshua.suereth)(typesafe.com)>
Krzysztof Romanowski <(λx.λy.x@y) (romanowski.kr)(gmail.com)>
Luc Bourlier <(λx.λy.x@y) (luc.bourlier)(typesafe.com)>
Mads Hartmann Jensen <(λx.λy.x@y) (mads379)(gmail.com)>
Lanna Marconi <(λx.λy.x@y) (marconi.lanna)(gmail.com)>
Expand All @@ -32,10 +34,13 @@ Matthew Farwell <(λx.λy.x@y) (matthew)(farwell.co.uk)>
Matthew Neeley <(λx.λy.x@y) (mneeley)(gmail.com)>
Matt Russell <(λx.λy.x@y) (MattRussellUK)(gmail.com)>
Michael Holzer <(λx.λy.x@y) (michi_holzer)(gmx.at)>
Michał Pociecha <(λx.λy.x@y) (michal.pociecha)(gmail.com)>
Miles Sabin <(λx.λy.x@y) (miles)(milessabin.com)>
Mirco Dotta <(λx.λy.x@y) (mirco.dotta)(typesafe.com)>
Mirko Stocker <(λx.λy.x@y) (me)(misto.ch)>
Paul Phillips <(λx.λy.x@y) (paulp)(improving.org)>
Paweł Batko <(λx.λy.x@y) (pawel.batko)(gmail.com)>
Piotr Kukiełka <(λx.λy.x@y) (piotr.kukielka)(gmail.com)>
Rafał Krzewski <(λx.λy.x@y) (rafal.krzewski)(caltha.pl)>
Richard O. Legendi <(λx.λy.x@y) (richard.legendi)(gmail.com)>
Robin Green <(λx.λy.x@y) (greenrd)(greenrd.org)>
Expand Down
2 changes: 2 additions & 0 deletions org.scala-ide.sdt.build/pom.xml
Expand Up @@ -24,6 +24,8 @@
<module>../org.scala-ide.sdt.spy</module>
<module>../org.scala-ide.sdt.debug</module>
<module>../org.scala-ide.sdt.debug.tests</module>
<module>../org.scala-ide.sdt.debug.expression</module>
<module>../org.scala-ide.sdt.debug.expression.tests</module>
<module>../org.scala-ide.sdt.weaving.feature</module>
<module>../org.scala-ide.sdt.feature</module>
<module>../org.scala-ide.sdt.dev.feature</module>
Expand Down
@@ -1,7 +1,5 @@
/*
* Copyright (c) 2014 Contributor. All rights reserved. This program and the accompanying materials
* are made available under the terms of the Scala License which accompanies this distribution, and
* is available at http://www.scala-lang.org/license.html
* Copyright (c) 2014 Contributor. All rights reserved.
*/
package org.scalaide.core.semantic

Expand Down
@@ -1,7 +1,5 @@
/*
* Copyright (c) 2014 Contributor. All rights reserved. This program and the accompanying materials
* are made available under the terms of the Scala License which accompanies this distribution, and
* is available at http://www.scala-lang.org/license.html
* Copyright (c) 2014 Contributor. All rights reserved.
*/
package org.scalaide.core.semantic

Expand Down
@@ -1,7 +1,5 @@
/*
* Copyright (c) 2014 Contributor. All rights reserved. This program and the accompanying materials
* are made available under the terms of the Scala License which accompanies this distribution, and
* is available at http://www.scala-lang.org/license.html
* Copyright (c) 2014 Contributor. All rights reserved.
*/
package org.scalaide.core.semantic

Expand Down
@@ -1,7 +1,5 @@
/*
* Copyright (c) 2014 Contributor. All rights reserved. This program and the accompanying materials
* are made available under the terms of the Scala License which accompanies this distribution, and
* is available at http://www.scala-lang.org/license.html
* Copyright (c) 2014 Contributor. All rights reserved.
*/
package org.scalaide.core.semantic

Expand Down
@@ -1,7 +1,5 @@
/*
* Copyright (c) 2014 Contributor. All rights reserved. This program and the accompanying materials
* are made available under the terms of the Scala License which accompanies this distribution, and
* is available at http://www.scala-lang.org/license.html
* Copyright (c) 2014 Contributor. All rights reserved.
*/
package org.scalaide.core.semantic

Expand Down
@@ -1,7 +1,5 @@
/*
* Copyright (c) 2014 Contributor. All rights reserved. This program and the accompanying materials
* are made available under the terms of the Scala License which accompanies this distribution, and
* is available at http://www.scala-lang.org/license.html
* Copyright (c) 2014 Contributor. All rights reserved.
*/
package org.scalaide.core.semantic

Expand Down
@@ -1,7 +1,5 @@
/*
* Copyright (c) 2014 Contributor. All rights reserved. This program and the accompanying materials
* are made available under the terms of the Scala License which accompanies this distribution, and
* is available at http://www.scala-lang.org/license.html
* Copyright (c) 2014 Contributor. All rights reserved.
*/
package org.scalaide.core
package semantic
Expand Down
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>occurrences-hyperlinking</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.scala-ide.sdt.core.scalabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.scala-ide.sdt.core.scalanature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>occurrences-hyperlinking</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.scala-ide.sdt.core.scalabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.scala-ide.sdt.core.scalanature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
14 changes: 7 additions & 7 deletions org.scala-ide.sdt.core/plugin.xml
Expand Up @@ -1179,7 +1179,7 @@
name="Toggle Implicits Display"/>
<command
categoryId="org.eclipse.debug.ui.category.run"
id="org.scalaide.core.handler.RunSelection"
id="org.scalaide.core.handler.RunSelectionInInterpreter"
name="Send Selection to Scala Interpreter"/>
<command
categoryId="scala.tools.eclipse.category"
Expand Down Expand Up @@ -1411,7 +1411,7 @@
contextId="scala.tools.eclipse.scalaEditorScope"
sequence="M1+M2+I"/>
<key
commandId="org.scalaide.core.handler.RunSelection"
commandId="org.scalaide.core.handler.RunSelectionInInterpreter"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="scala.tools.eclipse.scalaEditorScope"
sequence="M1+M2+X"/>
Expand Down Expand Up @@ -1512,10 +1512,10 @@
class="org.scalaide.refactoring.internal.MoveConstructorToCompanionObject"
commandId="org.scalaide.refactoring.MoveConstructorToCompanionObject">
</handler>
<handler
class="org.scalaide.ui.internal.actions.RunSelection"
commandId="org.scalaide.core.handler.RunSelection">
</handler>
<handler
class="org.scalaide.ui.internal.actions.RunSelectionInInterpreter"
commandId="org.scalaide.core.handler.RunSelectionInInterpreter">
</handler>
</extension>
<extension
point="org.eclipse.ui.menus">
Expand Down Expand Up @@ -1551,7 +1551,7 @@
style="toggle">
</command>
<command
commandId="org.scalaide.core.handler.RunSelection"
commandId="org.scalaide.core.handler.RunSelectionInInterpreter"
disabledIcon="icons/full/dtool16/run_interpreter.gif"
icon="icons/full/etool16/run_interpreter.gif"
label="Run Selection in Scala Interpreter"
Expand Down
1 change: 1 addition & 0 deletions org.scala-ide.sdt.core/resources/META-INF/MANIFEST-2_10.MF
@@ -1,4 +1,5 @@
Manifest-Version: 1.0
Eclipse-ExtensibleAPI: true
Bundle-ManifestVersion: 2
Bundle-Name: Scala Plugin
Bundle-SymbolicName: org.scala-ide.sdt.core;singleton:=true
Expand Down
1 change: 1 addition & 0 deletions org.scala-ide.sdt.core/resources/META-INF/MANIFEST-2_11.MF
@@ -1,4 +1,5 @@
Manifest-Version: 1.0
Eclipse-ExtensibleAPI: true
Bundle-ManifestVersion: 2
Bundle-Name: Scala Plugin
Bundle-SymbolicName: org.scala-ide.sdt.core;singleton:=true
Expand Down
1 change: 1 addition & 0 deletions org.scala-ide.sdt.core/resources/META-INF/MANIFEST-2_12.MF
@@ -1,4 +1,5 @@
Manifest-Version: 1.0
Eclipse-ExtensibleAPI: true
Bundle-ManifestVersion: 2
Bundle-Name: Scala Plugin
Bundle-SymbolicName: org.scala-ide.sdt.core;singleton:=true
Expand Down
@@ -1,25 +1,25 @@
package org.scalaide.core.internal.jdt.model

import java.util.{ HashMap => JHashMap }
import org.scalaide.ui.ScalaImages
import java.util.{HashMap => JHashMap}

import scala.tools.eclipse.contribution.weaving.jdt.IScalaClassFile
import scala.tools.nsc.io.AbstractFile
import scala.tools.nsc.io.VirtualFile

import org.eclipse.core.resources.IResource
import org.eclipse.core.runtime.IProgressMonitor
import org.eclipse.core.runtime.IStatus
import org.eclipse.jdt.core.IJavaElement
import org.eclipse.jdt.core.IType
import org.eclipse.jdt.core.WorkingCopyOwner
import org.eclipse.jdt.core.compiler.CharOperation
import org.eclipse.jdt.core.compiler.IProblem
import org.eclipse.jdt.internal.core.BinaryType
import org.eclipse.jdt.internal.core.ClassFile
import org.eclipse.jdt.internal.core.JavaModelStatus
import org.eclipse.jdt.internal.core.PackageFragment
import org.eclipse.jdt.internal.core.util.Util
import org.scalaide.core.compiler.ISourceMap
import org.scalaide.core.compiler.ScalaCompilationProblem
import org.scalaide.ui.ScalaImages

class ScalaClassFile(parent : PackageFragment, name : String, sourceFile : String)
extends ClassFile(parent, name) with ScalaCompilationUnit with IScalaClassFile {
Expand Down Expand Up @@ -90,22 +90,24 @@ class ScalaClassFile(parent : PackageFragment, name : String, sourceFile : Strin
def getPackage(): PackageFragment = parent

def getPackageName() : Array[Array[Char]] = {
if (getPackage == null)
CharOperation.NO_CHAR_CHAR
else
Util.toCharArrays(getPackage.names)
if (getPackage == null) CharOperation.NO_CHAR_CHAR
else Util.toCharArrays(getPackage.names)
}

lazy val allTypes: Seq[IType] = {
getChildren().toList flatMap { elem: IJavaElement =>
if (elem.getElementType() == IJavaElement.TYPE) elem.asInstanceOf[IType] +: elem.asInstanceOf[IType].getTypes()
else Seq[IType]()
(this +: getChildren().toList) flatMap {
case sourceFile: ScalaClassFile =>
Seq(sourceFile.getType())
case typeElement: IType =>
typeElement +: typeElement.getTypes
case _ =>
Seq[IType]()
}
}

class ScalaBinaryType(name: String) extends BinaryType(this, name) {
lazy val mirror = {
allTypes.find(t => t.exists && (t.getElementName == name))
allTypes.find(t => t.getElementName == name)
}
override def exists = mirror.isDefined
}
Expand Down
@@ -1,7 +1,5 @@
/*
* Copyright (c) 2011 Fabian Steeg. All rights reserved. This program and the accompanying materials
* are made available under the terms of the Scala License which accompanies this distribution, and
* is available at http://www.scala-lang.org/license.html
* Copyright (c) 2011 Fabian Steeg. All rights reserved.
*/
package org.scalaide.refactoring.internal

Expand Down
@@ -1,7 +1,5 @@
/*
* Copyright (c) 2014 Contributor. All rights reserved. This program and the accompanying materials
* are made available under the terms of the Scala License which accompanies this distribution, and
* is available at http://www.scala-lang.org/license.html
* Copyright (c) 2014 Contributor. All rights reserved.
*/
package org.scalaide.ui.internal.actions

Expand Down
@@ -1,24 +1,37 @@
/*
* Copyright (c) 2014 Contributor. All rights reserved.
*/
package org.scalaide.ui.internal.actions

import org.eclipse.core.commands.AbstractHandler
import org.eclipse.core.commands.ExecutionEvent
import org.eclipse.core.resources.IProject
import org.eclipse.jface.text.ITextSelection
import org.eclipse.ui.IFileEditorInput
import org.eclipse.ui.IWorkbenchPage
import org.eclipse.ui.PlatformUI
import org.eclipse.ui.texteditor.ITextEditor
import org.scalaide.ui.internal.repl.ReplConsoleView
import org.scalaide.util.Utils.WithAsInstanceOfOpt

class RunSelection extends AbstractHandler {
class RunSelectionInInterpreter extends RunSelection {
override def doWithSelection(project: IProject, activePage: IWorkbenchPage, text: String): Unit =
ReplConsoleView.makeVisible(project, activePage).evaluate(text)
}

abstract class RunSelection extends AbstractHandler {

def doWithSelection(project: IProject, activePage: IWorkbenchPage, text: String): Unit

override def execute(e: ExecutionEvent): AnyRef = {
val workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow()

for (editor <- Option(workbenchWindow.getActivePage.getActiveEditor);
input <- editor.getEditorInput.asInstanceOfOpt[IFileEditorInput];
textEditor <- editor.asInstanceOfOpt[ITextEditor];
selection <- textEditor.getSelectionProvider.getSelection.asInstanceOfOpt[ITextSelection])
{
for {
editor <- Option(workbenchWindow.getActivePage.getActiveEditor)
input <- editor.getEditorInput.asInstanceOfOpt[IFileEditorInput]
textEditor <- editor.asInstanceOfOpt[ITextEditor]
selection <- textEditor.getSelectionProvider.getSelection.asInstanceOfOpt[ITextSelection]
} {
val project = input.getFile.getProject
var text = selection.getText

Expand All @@ -31,15 +44,12 @@ class RunSelection extends AbstractHandler {
val lineOffset = document.getLineOffset(selection.getStartLine)
val lineLength = document.getLineLength(selection.getStartLine)
text = document.get(lineOffset, lineLength)
}
finally {
} finally {
provider.disconnect(input)
}
}

if (!text.isEmpty) {
ReplConsoleView.makeVisible(project,workbenchWindow.getActivePage).evaluate(text)
}
if (!text.trim().isEmpty) doWithSelection(project, workbenchWindow.getActivePage, text)
}

null
Expand Down
@@ -1,7 +1,5 @@
/*
* Copyright (c) 2014 Contributor. All rights reserved. This program and the accompanying materials
* are made available under the terms of the Scala License which accompanies this distribution, and
* is available at http://www.scala-lang.org/license.html
* Copyright (c) 2014 Contributor. All rights reserved.
*/
package org.scalaide.ui.internal.editor.decorators

Expand Down
@@ -1,7 +1,5 @@
/*
* Copyright (c) 2014 Contributor. All rights reserved. This program and the accompanying materials
* are made available under the terms of the Scala License which accompanies this distribution, and
* is available at http://www.scala-lang.org/license.html
* Copyright (c) 2014 Contributor. All rights reserved.
*/
package org.scalaide.ui.internal.editor.decorators

Expand Down