Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added open scala console action to j2se project.

  • Loading branch information...
commit f6317bd851075d7a1a566724cc016fc3c8062cdd 1 parent 4a85f1a
@dcaoyuan authored
View
17 scala.console/src/main/resources/org/netbeans/modules/scala/console/resources/layer.xml
@@ -6,6 +6,9 @@
<folder name="Window">
<file name="org-netbeans-modules-scala-console-old-ScalaConsoleAction.instance"/>
</folder>
+ <folder name="Projects">
+ <file name="org-netbeans-modules-scala-console-shell-ScalaConsoleAction.instance"/>
+ </folder>
</folder>
<folder name="Menu">
@@ -35,8 +38,18 @@
<folder name="Projects">
<folder name="org-netbeans-modules-maven">
<folder name="Actions">
- <file name="org-netbeans-modules-scala-console-shell-ScalaConsoleAction.instance">
- <attr name="position" intvalue="910"/>
+ <file name="ScalaConsoleAction.shadow">
+ <attr name="originalFile" stringvalue="Actions/Projects/org-netbeans-modules-scala-console-shell-ScalaConsoleAction.instance"/>
+ <attr name="position" intvalue="900"/>
+ </file>
+ </folder>
+ </folder>
+
+ <folder name="org-netbeans-modules-java-j2seproject">
+ <folder name="Actions">
+ <file name="ScalaConsoleAction.shadow">
+ <attr name="originalFile" stringvalue="Actions/Projects/org-netbeans-modules-scala-console-shell-ScalaConsoleAction.instance"/>
+ <attr name="position" intvalue="750"/>
</file>
</folder>
</folder>
View
3  scala.console/src/main/scala/org/netbeans/modules/scala/console/ConsoleOutputStream.scala
@@ -88,7 +88,8 @@ class ConsoleOutputStream(val area: JTextPane, pipedIn: PipedInputStream, welcom
private val buf = new StringBuffer(1000)
private val linesBuf = new ArrayBuffer[String]()
private var isWaitingUserInput = false
- private val outputCapturer = new ConsoleCapturer()
+
+ protected val outputCapturer = new ConsoleCapturer()
lazy val defaultStyle = {
val x = new SimpleAttributeSet()
View
8 ....console/src/main/scala/org/netbeans/modules/scala/console/shell/ScalaConsoleAction.scala
@@ -4,6 +4,7 @@ import java.awt.event.ActionEvent
import javax.swing.AbstractAction
import javax.swing.Action
import org.netbeans.api.project.Project
+import org.netbeans.modules.scala.core.ProjectResources
import org.openide.awt.DynamicMenuContent
import org.openide.util.ContextAwareAction
import org.openide.util.Lookup
@@ -25,8 +26,13 @@ class ScalaConsoleAction extends AbstractAction with ContextAwareAction {
private final class ContextAction(context: Lookup) extends AbstractAction {
val project = context.lookup(classOf[Project])
-
+
setEnabled(true)
+// if (ProjectResources.getScalaJavaSourceGroups(project).length > 0) {
+// setEnabled(true) // sbt and maven root project may has empty source group
+// } else {
+// setEnabled(false)
+// }
putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true)
putValue(Action.NAME, NbBundle.getMessage(classOf[ScalaConsoleAction], "CTL_ScalaConsoleAction"))
View
25 scala.core/src/main/scala/org/netbeans/modules/scala/core/ProjectResources.scala
@@ -10,6 +10,7 @@ import org.netbeans.api.java.classpath.ClassPath
import org.netbeans.api.project.FileOwnerQuery
import org.netbeans.api.project.Project
import org.netbeans.api.project.ProjectUtils
+import org.netbeans.api.project.SourceGroup
import org.netbeans.spi.java.queries.BinaryForSourceQueryImplementation
import org.openide.filesystems.FileObject
import org.openide.filesystems.FileStateInvalidException
@@ -26,6 +27,11 @@ import scala.reflect.io.AbstractFile
object ProjectResources {
private val log = Logger.getLogger(getClass.getName)
+ /** @see org.netbeans.api.java.project.JavaProjectConstants */
+ val SOURCES_TYPE_JAVA = "java"
+ /** a source group type for separate scala source roots, as seen in maven projects for example */
+ val SOURCES_TYPE_SCALA = "scala"
+
private val projectToResources = new mutable.WeakHashMap[Project, ProjectResource]
class ProjectResource {
@@ -89,8 +95,8 @@ object ProjectResources {
None
}
+ /** is this `fo` under test source? */
def isForTest(resource: ProjectResource, fo: FileObject) = {
- // * is this `fo` under test source?
resource.testToOut exists {case (src, _) => src.equals(fo) || FileUtil.isParentOf(src, fo)}
}
@@ -103,16 +109,23 @@ object ProjectResources {
}
}
}
-
+
+ def getScalaJavaSourceGroups(project: Project): Array[SourceGroup] = {
+ val sources = ProjectUtils.getSources(project)
+ val scalaSgs = sources.getSourceGroups(SOURCES_TYPE_SCALA)
+ val javaSgs = sources.getSourceGroups(SOURCES_TYPE_JAVA)
+ scalaSgs ++ javaSgs
+ }
+
def findProjectResource(project: Project): ProjectResource = {
val resource = new ProjectResource
val sources = ProjectUtils.getSources(project)
- val scalaSgs = sources.getSourceGroups(ScalaSourceUtil.SOURCES_TYPE_SCALA)
- val javaSgs = sources.getSourceGroups(ScalaSourceUtil.SOURCES_TYPE_JAVA)
+ val scalaSgs = sources.getSourceGroups(SOURCES_TYPE_SCALA)
+ val javaSgs = sources.getSourceGroups(SOURCES_TYPE_JAVA)
- log.fine((scalaSgs map (_.getRootFolder.getPath)).mkString("Project's src group[ScalaType] dir: [", ", ", "]"))
- log.fine((javaSgs map (_.getRootFolder.getPath)).mkString("Project's src group[JavaType] dir: [", ", ", "]"))
+ log.fine((scalaSgs map (_.getRootFolder.getPath)).mkString("Project's src group[Scala] dir: [", ", ", "]"))
+ log.fine((javaSgs map (_.getRootFolder.getPath)).mkString("Project's src group[Java] dir: [", ", ", "]"))
List(scalaSgs, javaSgs) foreach {
case Array(srcSg) =>
View
29 scala.core/src/main/scala/org/netbeans/modules/scala/core/ScalaSourceUtil.scala
@@ -37,9 +37,6 @@ import org.netbeans.api.java.classpath.GlobalPathRegistry
import org.netbeans.api.java.queries.SourceForBinaryQuery
import org.netbeans.api.java.source.ClasspathInfo
import org.netbeans.api.lexer.TokenHierarchy
-import org.netbeans.api.project.Project
-import org.netbeans.api.project.ProjectUtils
-import org.netbeans.api.project.SourceGroup
import org.netbeans.editor.BaseDocument
import org.netbeans.modules.classfile.ClassFile
import org.netbeans.modules.csl.api.{ElementKind, OffsetRange}
@@ -67,13 +64,7 @@ import scala.reflect.internal.{Flags, Symbols}
* @author Caoyuan Deng
*/
object ScalaSourceUtil {
-
- val logger = Logger.getLogger(getClass.getName)
-
- /** @see org.netbeans.api.java.project.JavaProjectConstants */
- val SOURCES_TYPE_JAVA = "java" // NOI18N
- /** a source group type for separate scala source roots, as seen in maven projects for example */
- val SOURCES_TYPE_SCALA = "scala" //NOI18N
+ private val logger = Logger.getLogger(getClass.getName)
def isScalaFile(f: FileObject): Boolean = {
ScalaMimeResolver.MIME_TYPE.equals(f.getMIMEType)
@@ -454,13 +445,6 @@ object ScalaSourceUtil {
}
- def getScalaJavaSourceGroups(p: Project): Array[SourceGroup] = {
- val sources = ProjectUtils.getSources(p)
- val scalaSgs = sources.getSourceGroups(ScalaSourceUtil.SOURCES_TYPE_SCALA)
- val javaSgs = sources.getSourceGroups(ScalaSourceUtil.SOURCES_TYPE_JAVA)
- scalaSgs ++ javaSgs
- }
-
/** @see org.netbeans.api.java.source.SourceUtils#getDependentRoots */
def getDependentRoots(root: URL): Set[URL] = {
val deps = IndexingController.getDefault.getRootDependencies
@@ -835,24 +819,21 @@ object ScalaSourceUtil {
def getClasspathInfo(fo: FileObject): Option[ClasspathInfo] = {
val bootCp = ClassPath.getClassPath(fo, ClassPath.BOOT)
val compCp = ClassPath.getClassPath(fo, ClassPath.COMPILE)
- val srcCp = ClassPath.getClassPath(fo, ClassPath.SOURCE)
+ val srcCp = ClassPath.getClassPath(fo, ClassPath.SOURCE)
- if ((bootCp eq null) || (compCp eq null) || (srcCp eq null)) {
+ if (bootCp == null || compCp == null || srcCp == null) {
/** @todo why? at least I saw this happens on "Scala project created from existing sources" */
logger.warning("No classpath for " + fo)
None
} else {
- ClasspathInfo.create(bootCp, compCp, srcCp) match {
- case null => None
- case x => Some(x)
- }
+ Option(ClasspathInfo.create(bootCp, compCp, srcCp))
}
}
def getClassPath(fo: FileObject) = {
val bootCp = ClassPath.getClassPath(fo, ClassPath.BOOT)
val compCp = ClassPath.getClassPath(fo, ClassPath.COMPILE)
- val srcCp = ClassPath.getClassPath(fo, ClassPath.SOURCE)
+ val srcCp = ClassPath.getClassPath(fo, ClassPath.SOURCE)
ClassPathSupport.createProxyClassPath(Array(bootCp, compCp, srcCp): _*)
}
View
3  ....project/src/main/java/org/netbeans/modules/scala/project/ui/J2SELogicalViewProvider.java
@@ -343,10 +343,9 @@ public HelpCtx getHelpCtx() {
List<Action> actions = new ArrayList<Action>();
- actions.add(ProjectSensitiveActions.projectCommandAction(J2SEActionProvider.COMMAND_SCALA_CONSOLE, bundle.getString("LBL_ScalaConsole_Name"), null)); // NOI18N
- actions.add(null);
actions.add(CommonProjectActions.newFileAction());
actions.add(null);
+ actions.add(ProjectSensitiveActions.projectCommandAction(J2SEActionProvider.COMMAND_SCALA_CONSOLE, bundle.getString("LBL_ScalaConsole_Name"), null)); // NOI18N
actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_BUILD, bundle.getString("LBL_BuildAction_Name"), null)); // NOI18N
actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_REBUILD, bundle.getString("LBL_RebuildAction_Name"), null)); // NOI18N
actions.add(ProjectSensitiveActions.projectCommandAction(ActionProvider.COMMAND_CLEAN, bundle.getString("LBL_CleanAction_Name"), null)); // NOI18N
View
7 scala.refactoring/src/main/scala/org/netbeans/modules/scala/refactoring/RetoucheUtils.scala
@@ -67,11 +67,12 @@ import org.netbeans.api.lexer.TokenSequence;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectUtils;
-import org.netbeans.api.project.SourceGroup;
import org.netbeans.api.project.Sources;
import org.netbeans.api.project.ui.OpenProjects;
import org.netbeans.modules.csl.api.ElementKind
-import org.netbeans.modules.scala.core.{ScalaMimeResolver, ScalaParserResult, ScalaSourceUtil}
+import org.netbeans.modules.scala.core.ScalaMimeResolver
+import org.netbeans.modules.scala.core.ScalaSourceUtil
+import org.netbeans.modules.scala.core.ProjectResources
import org.netbeans.modules.scala.core.ast.ScalaItems
import org.netbeans.modules.scala.core.lexer.ScalaTokenId
import org.netbeans.modules.parsing.spi.Parser;
@@ -420,7 +421,7 @@ object RetoucheUtils {
dependentRoots += sourceRoot
}
- val sgs = ScalaSourceUtil.getScalaJavaSourceGroups(p)
+ val sgs = ProjectResources.getScalaJavaSourceGroups(p)
dependentRoots ++= sgs.map(root => URLMapper.findURL(root.getRootFolder, URLMapper.INTERNAL))
} else {
val srcCps = GlobalPathRegistry.getDefault.getPaths(ClassPath.SOURCE).iterator
View
5 ...ing/src/main/scala/org/netbeans/modules/scala/refactoring/ui/WhereUsedRefactoringUI.scala
@@ -45,7 +45,6 @@ import java.util.ResourceBundle
import javax.swing.event.ChangeListener
import org.netbeans.api.java.source.ClasspathInfo
import org.netbeans.api.project.FileOwnerQuery
-import org.netbeans.api.project.ProjectUtils
import org.netbeans.modules.csl.api.ElementKind
import org.netbeans.modules.refactoring.api.AbstractRefactoring
import org.netbeans.modules.refactoring.api.Problem
@@ -58,7 +57,7 @@ import org.openide.util.HelpCtx
import org.openide.util.NbBundle
import org.openide.util.lookup.Lookups
-import org.netbeans.modules.scala.core.ScalaSourceUtil
+import org.netbeans.modules.scala.core.ProjectResources
import org.netbeans.modules.scala.core.ast.ScalaItems
import org.netbeans.modules.scala.refactoring.RetoucheUtils
import org.netbeans.modules.scala.refactoring.WhereUsedQueryConstants
@@ -111,7 +110,7 @@ class WhereUsedRefactoringUI(query: WhereUsedQuery, name: String, kind: ElementK
} else {
val cpInfo = query.getContext.lookup(classOf[ClasspathInfo])
val p = FileOwnerQuery.getOwner(handle.fo.get)
- val roots = new HashSet[FileObject] ++= ScalaSourceUtil.getScalaJavaSourceGroups(p).map(_.getRootFolder)
+ val roots = new HashSet[FileObject] ++= ProjectResources.getScalaJavaSourceGroups(p).map(_.getRootFolder)
val srcCp = ClassPathSupport.createClassPath(roots.toArray: _*)
val bootCp = cpInfo.getClassPath(ClasspathInfo.PathKind.BOOT)
View
3  scala.sbt/src/main/scala/org/netbeans/modules/scala/sbt/project/SBTProjectLogicalView.scala
@@ -59,11 +59,10 @@ class SBTProjectLogicalView(project: Project) extends LogicalViewProvider {
override
def getActions(arg0: Boolean): Array[Action] = Array(
- ProjectSensitiveActions.projectCommandAction(SBTActionProvider.COMMAND_SCALA_CONSOLE, NbBundle.getMessage(classOf[SBTActionProvider], "CTL_OpenScalaAction"), null),
- null,
ProjectSensitiveActions.projectCommandAction(SBTActionProvider.COMMAND_SBT_CONSOLE, NbBundle.getMessage(classOf[SBTActionProvider], "CTL_OpenSbtAction"), null),
ProjectSensitiveActions.projectCommandAction(SBTActionProvider.COMMAND_SBT_RELOAD, NbBundle.getMessage(classOf[SBTActionProvider], "CTL_ReloadSbtAction"), null),
null,
+ ProjectSensitiveActions.projectCommandAction(SBTActionProvider.COMMAND_SCALA_CONSOLE, NbBundle.getMessage(classOf[SBTActionProvider], "CTL_OpenScalaAction"), null),
ProjectSensitiveActions.projectCommandAction(SBTActionProvider.COMMAND_BUILD, NbBundle.getMessage(classOf[SBTActionProvider], "CTL_BuildAction"), null),
ProjectSensitiveActions.projectCommandAction(SBTActionProvider.COMMAND_CLEAN, NbBundle.getMessage(classOf[SBTActionProvider], "CTL_CleanAction"), null),
ProjectSensitiveActions.projectCommandAction(SBTActionProvider.COMMAND_REBUILD, NbBundle.getMessage(classOf[SBTActionProvider], "CTL_RebuildAction"), null),

0 comments on commit f6317bd

Please sign in to comment.
Something went wrong with that request. Please try again.