Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

1. Upgraded to Scala 2.10.1-RC2

2. Tried to avoid race condition which may be cause by presentation compiler method running not in compileRunner thread.
  • Loading branch information...
commit 2fccd210269763d655604478c46398be6c62638a 1 parent 9137c82
@dcaoyuan authored
Showing with 1,149 additions and 1,122 deletions.
  1. BIN  libs.local/lib/continuations.jar
  2. BIN  libs.local/lib/scala-compiler.jar
  3. BIN  libs.local/lib/scala-library.jar
  4. BIN  libs.local/lib/scala-reflect.jar
  5. +2 −2 pom.xml
  6. +75 −89 scala.core/src/main/scala/org/netbeans/modules/scala/core/ScalaGlobal.scala
  7. +12 −14 scala.core/src/main/scala/org/netbeans/modules/scala/core/ScalaParserResult.scala
  8. +29 −23 scala.core/src/main/scala/org/netbeans/modules/scala/core/ScalaSourceUtil.scala
  9. +1 −1  scala.core/src/main/scala/org/netbeans/modules/scala/core/ScalaSymbolResolver.scala
  10. +305 −316 scala.core/src/main/scala/org/netbeans/modules/scala/core/ast/ScalaAstVisitor.scala
  11. +2 −9 scala.core/src/main/scala/org/netbeans/modules/scala/core/ast/ScalaDfns.scala
  12. +7 −8 scala.core/src/main/scala/org/netbeans/modules/scala/core/ast/ScalaRootScope.scala
  13. +213 −180 scala.core/src/main/scala/org/netbeans/modules/scala/core/ast/ScalaUtils.scala
  14. +10 −13 scala.core/src/main/scala/org/netbeans/modules/scala/core/element/ScalaElements.scala
  15. +116 −111 scala.editor/src/main/scala/org/netbeans/modules/scala/editor/JavaStubGenerator.scala
  16. +44 −51 scala.editor/src/main/scala/org/netbeans/modules/scala/editor/ScalaCodeCompleter.scala
  17. +80 −70 scala.editor/src/main/scala/org/netbeans/modules/scala/editor/ScalaCompletionProposals.scala
  18. +3 −4 scala.editor/src/main/scala/org/netbeans/modules/scala/editor/ScalaDeclarationFinder.scala
  19. +106 −100 scala.editor/src/main/scala/org/netbeans/modules/scala/editor/ScalaSemanticAnalyzer.scala
  20. +43 −39 scala.refactoring/src/main/scala/org/netbeans/modules/scala/refactoring/RenameRefactoringPlugin.scala
  21. +30 −28 scala.refactoring/src/main/scala/org/netbeans/modules/scala/refactoring/WhereUsedQueryPlugin.scala
  22. +1 −2  scala.refactoring/src/main/scala/org/netbeans/modules/scala/refactoring/ui/RefactoringActionsProvider.scala
  23. +70 −62 scala.refactoring/src/main/scala/org/netbeans/modules/scala/refactoring/ui/WhereUsedPanel.scala
View
BIN  libs.local/lib/continuations.jar
Binary file not shown
View
BIN  libs.local/lib/scala-compiler.jar
Binary file not shown
View
BIN  libs.local/lib/scala-library.jar
Binary file not shown
View
BIN  libs.local/lib/scala-reflect.jar
Binary file not shown
View
4 pom.xml
@@ -56,11 +56,11 @@
<netbeans.version>RELEASE73</netbeans.version>
- <scala.version>2.10.0-nbscala</scala.version> <!-- use nbscala patched scala runtime @see libs.local-->
+ <scala.version>2.10.1-nbscala</scala.version> <!-- use nbscala patched scala runtime @see libs.local-->
<sbt.version>0.12.2</sbt.version>
<!-- module versions -->
- <libs.scala.version>2.10.0.3</libs.scala.version>
+ <libs.scala.version>2.10.1.0</libs.scala.version>
<libs.sbt.version>0.12.2.1</libs.sbt.version>
<libs.xtc.version>1.15.1</libs.xtc.version>
<languages.execution.version>1.6.1</languages.execution.version>
View
164 scala.core/src/main/scala/org/netbeans/modules/scala/core/ScalaGlobal.scala
@@ -49,11 +49,11 @@ import org.openide.filesystems.FileRenameEvent
import org.openide.filesystems.FileUtil
import org.openide.filesystems.FileChangeListener
import org.openide.util.RequestProcessor
+import org.netbeans.modules.scala.core.ast.ScalaAstVisitor
import org.netbeans.modules.scala.core.ast.ScalaItems
import org.netbeans.modules.scala.core.ast.ScalaDfns
import org.netbeans.modules.scala.core.ast.ScalaRefs
import org.netbeans.modules.scala.core.ast.ScalaRootScope
-import org.netbeans.modules.scala.core.ast.ScalaAstVisitor
import org.netbeans.modules.scala.core.ast.ScalaUtils
import org.netbeans.modules.scala.core.element.ScalaElements
import org.netbeans.modules.scala.core.element.JavaElements
@@ -93,6 +93,7 @@ case class ErrorReporter(var errors: List[ScalaError] = Nil) extends Reporter {
}
class ScalaGlobal(_settings: Settings, _reporter: Reporter, projectName: String = "") extends Global(_settings, _reporter, projectName)
+ with ScalaAstVisitor
with ScalaItems
with ScalaDfns
with ScalaRefs
@@ -107,14 +108,8 @@ class ScalaGlobal(_settings: Settings, _reporter: Reporter, projectName: String
private val log1 = Logger.getLogger(this.getClass.getName)
- // Inner object inside a class is not singleton, so it's safe for each instance of ScalaGlobal,
- // but, is it thread safe? http://lampsvn.epfl.ch/trac/scala/ticket/1591
- private object scalaAstVisitor extends ScalaAstVisitor {
- val global: ScalaGlobal.this.type = ScalaGlobal.this
- }
-
@volatile private var workingSource: Option[SourceFile] = None
- var isCancelingSemantic = false
+ @volatile var isCancelingSemantic = false
private def resetReporter {
reporter match {
@@ -123,91 +118,86 @@ class ScalaGlobal(_settings: Settings, _reporter: Reporter, projectName: String
}
}
- def askForReLoad(srcFos: List[FileObject]) {
+ def askForReload(srcFiles: List[SourceFile]) {
resetReporter
- val srcFiles = srcFos map {fo =>
- val sourceFile = ScalaSourceFile.sourceFileOf(fo)
- sourceFile.refreshSnapshot
- sourceFile
- }
-
- try {
- val resp = new Response[Unit]
- askReload(srcFiles, resp)
- resp.get
- } catch {
- case ex: AssertionError =>
- /**
- * @Note: avoid scala nsc's assert error. Since global's
- * symbol table may have been broken, we have to reset ScalaGlobal
- * to clean this global
- */
- ScalaGlobal.resetLate(this, ex)
- case ex: java.lang.Error => // avoid scala nsc's Error error
- case ex: Throwable => // just ignore all ex
+ val resp = new Response[Unit]
+ askReload(srcFiles, resp)
+ resp.get match {
+ case Left(_) =>
+ case Right(ex) => ex match {
+ case _: AssertionError =>
+ /**
+ * @Note: avoid scala nsc's assert error. Since global's
+ * symbol table may have been broken, we have to reset ScalaGlobal
+ * to clean this global
+ */
+ ScalaGlobal.resetLate(this, ex)
+ case _: java.lang.Error => // avoid scala nsc's Error error
+ case _: Throwable => // just ignore all ex
+ }
}
}
- def askForType(source: ScalaSourceFile, forceReload: Boolean) {
- resetReporter
-
- try {
- val typeResp = new Response[Tree]
- askType(source, forceReload, typeResp)
- typeResp.get
- } catch {
- case ex: AssertionError =>
- /**
- * @Note: avoid scala nsc's assert error. Since global's
- * symbol table may have been broken, we have to reset ScalaGlobal
- * to clean this global
- */
- ScalaGlobal.resetLate(this, ex)
- case ex: java.lang.Error => // avoid scala nsc's Error error
- case ex: Throwable => // just ignore all ex
- }
- }
-
/**
* We should carefully design askForSemantic(.) and cancelSemantic(.) to make them thread safe,
* so cancelSemantic could be called during askForSemantic and the rootScope is always that we want.
*/
- def askForSemantic(source: ScalaSourceFile, forceReload: Boolean): ScalaRootScope = {
+ def askForSemantic(source: ScalaSourceFile): ScalaRootScope = {
resetReporter
-
+
+ askForReload(List(source))
+
workingSource = Some(source)
isCancelingSemantic = false
qualToRecoveredType.clear
- val res = try {
+ try {
if (isCancelingSemantic) return ScalaRootScope.EMPTY
+
val typeResp = new Response[Tree]
- askType(source, forceReload, typeResp)
-
- if (isCancelingSemantic) return ScalaRootScope.EMPTY
- typeResp.get
-
+ askLoadedTyped(source, typeResp)
if (isCancelingSemantic) return ScalaRootScope.EMPTY
- getSemanticRoot(source)
- } catch {
- case ex: AssertionError =>
- /**
- * @Note: avoid scala nsc's assert error. Since global's
- * symbol table may have been broken, we have to reset ScalaGlobal
- * to clean this global
- */
- ScalaGlobal.resetLate(this, ex)
- ScalaRootScope.EMPTY
- case ex: java.lang.Error => ScalaRootScope.EMPTY // avoid scala nsc's Error error
- case ex: Throwable => ScalaRootScope.EMPTY // just ignore all ex
+
+ typeResp.get match {
+ case Left(rootTree) =>
+ if (isCancelingSemantic) return ScalaRootScope.EMPTY
+
+ askForSemanticRoot(source, rootTree)
+
+ case Right(ex) => ex match {
+ case _: AssertionError =>
+ /**
+ * @Note: avoid scala nsc's assert error. Since global's
+ * symbol table may have been broken, we have to reset ScalaGlobal
+ * to clean this global
+ */
+ ScalaGlobal.resetLate(this, ex)
+ ScalaRootScope.EMPTY
+ case _: java.lang.Error => ScalaRootScope.EMPTY // avoid scala nsc's Error error
+ case _: Throwable => ScalaRootScope.EMPTY // just ignore all ex
+ }
+ }
+
+ } finally {
+ workingSource = None
}
-
- workingSource = None
- res
}
+
+ private def askForSemanticRoot(source: ScalaSourceFile, rootTree: Tree): ScalaRootScope = {
+ askForResponse {() =>
+ val start = System.currentTimeMillis
+ val rootScope = astVisit(source, rootTree, source.tokenHierarchy)
+ log1.info("Visited " + source.file.file.getName + " in " + (System.currentTimeMillis - start) + "ms")
+ rootScope
+ } get match {
+ case Left(x) => x
+ case Right(ex) => ScalaRootScope.EMPTY
+ }
+ }
+
/**
* @return will cancel
*/
@@ -268,23 +258,11 @@ class ScalaGlobal(_settings: Settings, _reporter: Reporter, projectName: String
})
}
- scalaAstVisitor.visit(unit, source.tokenHierarchy)
+ astVisit(source, unit.body, source.tokenHierarchy)
case None => ScalaRootScope.EMPTY
}
}
- private def getSemanticRoot(source: ScalaSourceFile): ScalaRootScope = {
- val start = System.currentTimeMillis
- getUnitOf(source) match {
- case Some(unit) =>
- val root = scalaAstVisitor.visit(unit, source.tokenHierarchy)
- log1.info("Visited " + source.file.file.getName + " in " + (System.currentTimeMillis - start) + "ms")
- root
- case None =>
- log1.warning("Tried to visit " + source.file.file.getName + ", but got no unit!")
- ScalaRootScope.EMPTY
- }
- }
}
object ScalaGlobal {
@@ -525,7 +503,10 @@ object ScalaGlobal {
srcCp.getRoots foreach ProjectResources.findAllSourcesOf("text/x-scala", scalaSrcs)
// the reporter should be set previous, otherwise, no java source is resolved, may throw exception already.
- global askForReLoad (javaSrcs ++= scalaSrcs).toList
+
+ val srcFiles = (javaSrcs ++= scalaSrcs).toList map toSourceFile
+
+ global askForReload srcFiles
}
}
@@ -534,6 +515,11 @@ object ScalaGlobal {
global
}
+ private def toSourceFile(fo: FileObject): ScalaSourceFile = {
+ val sourceFile = ScalaSourceFile.sourceFileOf(fo)
+ sourceFile.refreshSnapshot
+ sourceFile
+ }
private class SrcCpListener(global: ScalaGlobal, srcCp: ClassPath) extends FileChangeAdapter {
val javaMimeType = "text/x-java"
@@ -547,7 +533,7 @@ object ScalaGlobal {
def fileDataCreated(fe: FileEvent) {
val fo = fe.getFile
if (fo.getMIMEType == javaMimeType && isUnderSrcDir(fo) && (global ne null)) {
- global askForReLoad List(fo)
+ global askForReload List(toSourceFile(fo))
}
}
@@ -555,7 +541,7 @@ object ScalaGlobal {
def fileChanged(fe: FileEvent) {
val fo = fe.getFile
if (fo.getMIMEType == javaMimeType && isUnderSrcDir(fo) && (global ne null)) {
- global askForReLoad List(fo)
+ global askForReload List(toSourceFile(fo))
}
}
@@ -563,7 +549,7 @@ object ScalaGlobal {
def fileRenamed(fe: FileRenameEvent) {
val fo = fe.getFile
if (fo.getMIMEType == javaMimeType && isUnderSrcDir(fo) && (global ne null)) {
- global askForReLoad List(fo)
+ global askForReload List(toSourceFile(fo))
}
}
View
26 scala.core/src/main/scala/org/netbeans/modules/scala/core/ScalaParserResult.scala
@@ -58,11 +58,14 @@ import scala.tools.nsc.reporters.Reporter
*/
class ScalaParserResult private (snapshot: Snapshot) extends ParserResult(snapshot) {
private val fileObject = snapshot.getSource.getFileObject
- val srcFile = ScalaSourceFile.sourceFileOf(fileObject)
val global = ScalaGlobal.getGlobal(fileObject)
- srcFile.snapshot = snapshot
+ val srcFile = {
+ val x = ScalaSourceFile.sourceFileOf(fileObject)
+ x.snapshot = snapshot
+ x
+ }
- @volatile private var isInSemantic = false
+ @volatile private var isAskingSemantic = false
@volatile private var _root: ScalaRootScope = ScalaRootScope.EMPTY
private var _errors: java.util.List[Error] = java.util.Collections.emptyList[Error]
@@ -98,7 +101,7 @@ class ScalaParserResult private (snapshot: Snapshot) extends ParserResult(snapsh
/** @todo since only call rootScope will cause actual parsing, those parsing task
* that won't get rootScope will not be truly parsed, I choose this approach because
* the TaskListIndexer will re-parse all dependent source files, with bad scala
- * comiler performance right now, it's better to bypass it.
+ * compiler performance right now, it's better to bypass it.
*
* When background scanning project truly no to block the code-completion and
* other editor behavior, or, the performance of complier is not the bottleneck
@@ -107,10 +110,6 @@ class ScalaParserResult private (snapshot: Snapshot) extends ParserResult(snapsh
override
def getDiagnostics: java.util.List[_ <: Error] = _errors
- def toTyped {
- global.askForType(srcFile, true)
- }
-
def toSemanticed: Unit = _root synchronized {
// although the unit may have been ahead to typed phase during autocompletion,
// the typed trees may not be correct for semantic analysis, it's better to reset
@@ -118,18 +117,18 @@ class ScalaParserResult private (snapshot: Snapshot) extends ParserResult(snapsh
// An example is that when try completing on x. and then press esc, the error won't
// be reported if do not call reset here
reset
- _root = global.askForSemantic(srcFile, true)
+ _root = global.askForSemantic(srcFile)
_errors = collectErrors(global.reporter)
}
def cancelSemantic: Boolean = {
- val willCancel = if (isInSemantic) {
+ val willCancel = if (isAskingSemantic) {
global.cancelSemantic(srcFile)
} else false
if (willCancel) reset
- isInSemantic = false
+ isAskingSemantic = false
willCancel
}
@@ -163,9 +162,9 @@ class ScalaParserResult private (snapshot: Snapshot) extends ParserResult(snapsh
*/
lazy val rootScope: ScalaRootScope = _root synchronized {
if (isInvalid) {
- isInSemantic = true
+ isAskingSemantic = true
toSemanticed
- isInSemantic = false
+ isAskingSemantic = false
}
_root
}
@@ -195,4 +194,3 @@ object ScalaParserResult {
pr
}
}
-
View
52 scala.core/src/main/scala/org/netbeans/modules/scala/core/ScalaSourceUtil.scala
@@ -505,9 +505,6 @@ object ScalaSourceUtil {
private val TMPL_KINDS = Set(ElementKind.CLASS, ElementKind.MODULE)
def getBinaryClassName(pr: ScalaParserResult, lineNumber: Int): String = {
- val global = pr.global
- import global._
-
val root = pr.rootScope
val fo = pr.getSnapshot.getSource.getFileObject
val doc = pr.getSnapshot.getSource.getDocument(false).asInstanceOf[StyledDocument]
@@ -515,26 +512,35 @@ object ScalaSourceUtil {
val offset = NbDocument.findLineOffset(doc, lineNumber - 1)
var clazzName = ""
- root.enclosingDfn(TMPL_KINDS, th, offset) foreach {case enclDfn: ScalaDfn =>
- val sym = enclDfn.symbol
- // "scalarun.Dog.$talk$1"
- val fqn = new StringBuilder(sym.fullName('.'))
-
- // * getTopLevelClassName "scalarun.Dog"
- val topSym = sym.enclosingTopLevelClass
- val topClzName = topSym.fullName('.')
-
- // "scalarun.Dog$$talk$1"
- for (i <- topClzName.length until fqn.length if fqn.charAt(i) == '.') {
- fqn.setCharAt(i, '$')
- }
+
+ val global = pr.global
+ import global._
+ askForResponse {() =>
+ root.enclosingDfn(TMPL_KINDS, th, offset) foreach {case enclDfn: ScalaDfn =>
+ val sym = enclDfn.symbol
+ // "scalarun.Dog.$talk$1"
+ val fqn = new StringBuilder(sym.fullName('.'))
+
+ // * getTopLevelClassName "scalarun.Dog"
+ val topSym = sym.enclosingTopLevelClass
+ val topClzName = topSym.fullName('.')
+
+ // "scalarun.Dog$$talk$1"
+ for (i <- topClzName.length until fqn.length if fqn.charAt(i) == '.') {
+ fqn.setCharAt(i, '$')
+ }
- // * According to Symbol#kindString, an object template isModuleClass()
- // * trait's symbol name has been added "$class" by compiler
- if (topSym.isModuleClass) {
- fqn.append("$")
- }
- clazzName = fqn.toString
+ // * According to Symbol#kindString, an object template isModuleClass()
+ // * trait's symbol name has been added "$class" by compiler
+ if (topSym.isModuleClass) {
+ fqn.append("$")
+ }
+ clazzName = fqn.toString
+ }
+
+ } get match {
+ case Left(_) =>
+ case Right(_) =>
}
if (clazzName.length == 0) return null
@@ -584,7 +590,7 @@ object ScalaSourceUtil {
clazzName
}
- @deprecated
+ @deprecated("For reference only", "1.6.0")
def getBinaryClassName_old(pr: ScalaParserResult, offset: Int): String = {
val root = pr.rootScopeForDebug
val th = pr.getSnapshot.getTokenHierarchy
View
2  scala.core/src/main/scala/org/netbeans/modules/scala/core/ScalaSymbolResolver.scala
@@ -62,7 +62,7 @@ abstract class ScalaSymbolResolver {
// @todo
val srcFile = ScalaSourceFile.sourceFileOf(null)
val th = TokenHierarchy.create(sb.toString, ScalaTokenId.language)
- val rootScope = global.askForSemantic(srcFile, true)
+ val rootScope = global.askForSemantic(srcFile)
val lastDot = fqn.lastIndexOf('.')
val lastPart = if (lastDot == -1) fqn else fqn.substring(lastDot + 1, fqn.length)
View
621 scala.core/src/main/scala/org/netbeans/modules/scala/core/ast/ScalaAstVisitor.scala
@@ -39,14 +39,18 @@
package org.netbeans.modules.scala.core.ast
import java.io.File
-import org.netbeans.api.lexer.{Token, TokenId, TokenHierarchy, TokenSequence}
+import org.netbeans.api.lexer.Token
+import org.netbeans.api.lexer.TokenId
+import org.netbeans.api.lexer.TokenHierarchy
+import org.netbeans.api.lexer.TokenSequence
import org.netbeans.modules.csl.api.{ElementKind}
-import org.openide.filesystems.{FileObject, FileUtil}
-
-import org.netbeans.api.language.util.ast.{AstItem, AstScope}
+import org.openide.filesystems.FileObject
+import org.openide.filesystems.FileUtil
+import org.netbeans.api.language.util.ast.AstItem
+import org.netbeans.api.language.util.ast.AstScope
import org.netbeans.modules.scala.core.ScalaGlobal
-import org.netbeans.modules.scala.core.lexer.{ScalaLexUtil, ScalaTokenId}
-
+import org.netbeans.modules.scala.core.lexer.ScalaLexUtil
+import org.netbeans.modules.scala.core.lexer.ScalaTokenId
import scala.reflect.internal.Flags
import scala.reflect.internal.Flags._
import scala.reflect.internal.util.{SourceFile, OffsetPosition}
@@ -61,74 +65,57 @@ import scala.collection.mutable.{Stack, HashSet, HashMap}
*
* @author Caoyuan Deng
*/
-abstract class ScalaAstVisitor {
-
- val global: ScalaGlobal
- import global._
-
- private val EOL = System.getProperty("line.separator", "\n")
+trait ScalaAstVisitor {self: ScalaGlobal =>
- private val debug = false
- private val scopes = new Stack[AstScope]
- private val owners = new Stack[Symbol]
- private var rootScope: ScalaRootScope = _
+ /**
+ * call this method only via askForResponse to avoid race condition upon interactive presnetation compiler
+ */
+ protected def astVisit(srcFile: SourceFile, rootTree: Tree, th: TokenHierarchy[_]): ScalaRootScope = {
+ new treeTraverser(srcFile, rootTree, th).apply()
+ }
- private var fo: Option[FileObject] = _
- private var th: TokenHierarchy[_] = _
- private var srcFile: SourceFile = _
- private var docLength: Int = _
+ private class treeTraverser(srcFile: SourceFile, rootTree: Tree, th: TokenHierarchy[_]) {
+ private val debug = false
- def visit(unit: CompilationUnit, th: TokenHierarchy[_]): ScalaRootScope = {
- this.th = th
- this.srcFile = unit.source
- this.docLength = srcFile.content.length
- this.fo = if (srcFile ne null) {
+ private val docLength = srcFile.content.length
+ private val fo = {
val file = new File(srcFile.path)
- if ((file ne null) && file.exists) { // it's a real file instead of archive file
- FileUtil.toFileObject(file) match {
- case null => None
- case x => Some(x)
- }
+ if (file != null && file.exists) { // it's a real file instead of archive file
+ Option(FileUtil.toFileObject(file))
} else None
- } else None
-
- //println(global.qualToRecoveredType)
-
- scopes.clear
- rootScope = ScalaRootScope(Some(unit), getBoundsTokens(0, docLength))
- scopes push rootScope
-
- owners.clear
- owners push rootMirror.RootClass
+ }
- treeTraverser(unit.body)
+ private val rootScope: ScalaRootScope = ScalaRootScope(getBoundsTokens(0, docLength))
+ private val scopes = new Stack[AstScope]
+ private val owners = new Stack[Symbol]
- rootScope
- }
-
- private final object treeTraverser {
private val visited = new HashSet[Tree]
private val treeToKnownType = new HashMap[Tree, Type]
- def apply[T <: Tree](tree: T): T = {
- traverse(tree)
+ def apply(): ScalaRootScope = {
+ //println(qualToRecoveredType)
+
+ scopes push rootScope
+ owners push rootMirror.RootClass
+
+ traverse(rootTree)
- // * clear after visit to free memory
+ // clear after visit to free memory
visited.clear
treeToKnownType.clear
if (debug) rootScope.debugPrintTokens(th)
- tree
+ rootScope
}
- private def traverse(tree: Tree): Unit = {
- if (global.isCancelingSemantic) return
- if (!visited.add(tree)) return // has visited
+ private def traverse(tree: Tree) {
+ if (isCancelingSemantic) return
+ if (!visited.add(tree)) return // has visited
tree match {
case EmptyTree =>
- ;
+
case PackageDef(pid, stats) =>
val scope = ScalaScope(getBoundsTokens(tree))
scopes.top.addScope(scope)
@@ -136,7 +123,7 @@ abstract class ScalaAstVisitor {
val sym = tree.symbol
withIdToken(getIdToken(tree)) {token =>
val dfn = ScalaDfn(sym, token, ElementKind.PACKAGE, scope, fo)
- if (scopes.top.addDfn(dfn)) info("\tAdded: ", dfn)
+ if (scopes.top.addDfn(dfn)) logInfo("\tAdded: ", dfn)
}
atOwner(sym.moduleClass, scope) {
@@ -153,7 +140,7 @@ abstract class ScalaAstVisitor {
val sym = tree.symbol
withIdToken(getIdToken(tree)) {token =>
val dfn = ScalaDfn(sym, token, ElementKind.CLASS, scope, fo)
- if (scopes.top.addDfn(dfn)) info("\tAdded: ", dfn)
+ if (scopes.top.addDfn(dfn)) logInfo("\tAdded: ", dfn)
}
atOwner(sym, scope) {
@@ -170,7 +157,7 @@ abstract class ScalaAstVisitor {
val sym = tree.symbol
withIdToken(getIdToken(tree)) {token =>
val dfn = ScalaDfn(sym, token, ElementKind.MODULE, scope, fo)
- if (scopes.top.addDfn(dfn)) info("\tAdded: ", dfn)
+ if (scopes.top.addDfn(dfn)) logInfo("\tAdded: ", dfn)
}
atOwner(sym.moduleClass, scope) {
@@ -188,7 +175,7 @@ abstract class ScalaAstVisitor {
if (!isTupleClass(tpt.symbol)) {
withIdToken(getIdToken(tree, name.decode)) {token =>
val dfn = ScalaDfn(sym, token, ElementKind.OTHER, scope, fo)
- if (scopes.top.addDfn(dfn)) info("\tAdded: ", dfn)
+ if (scopes.top.addDfn(dfn)) logInfo("\tAdded: ", dfn)
}
}
@@ -208,7 +195,7 @@ abstract class ScalaAstVisitor {
val sym = tree.symbol
withIdToken(getIdToken(tree)) {token =>
val dfn = ScalaDfn(sym, token, kind, scope, fo)
- if (scopes.top.addDfn(dfn)) info("\tAdded: ", dfn)
+ if (scopes.top.addDfn(dfn)) logInfo("\tAdded: ", dfn)
}
atOwner(sym, scope) {
@@ -229,7 +216,7 @@ abstract class ScalaAstVisitor {
if (!sym.hasFlag(Flags.SYNTHETIC)) {
withIdToken(getIdToken(tree, name.decode)) {token =>
val dfn = ScalaDfn(sym, token, ElementKind.CLASS, scope, fo)
- if (scopes.top.addDfn(dfn)) info("\tAdded: ", dfn)
+ if (scopes.top.addDfn(dfn)) logInfo("\tAdded: ", dfn)
}
}
}
@@ -246,13 +233,13 @@ abstract class ScalaAstVisitor {
val loSym = loTpe.typeSymbol
withIdToken(getIdToken(lo, loSym.nameString)) {token =>
val loRef = ScalaRef(loSym, token, ElementKind.CLASS, fo)
- if (scopes.top.addRef(loRef)) info("\tAdded: ", loRef)
+ if (scopes.top.addRef(loRef)) logInfo("\tAdded: ", loRef)
}
val hiSym = hiTpe.typeSymbol
withIdToken(getIdToken(hi, hiSym.nameString)) {token =>
val hiRef = ScalaRef(hiSym, token, ElementKind.CLASS, fo)
- if (scopes.top.addRef(hiRef)) info("\tAdded: ", hiRef)
+ if (scopes.top.addRef(hiRef)) logInfo("\tAdded: ", hiRef)
}
case _ => traverse(rhs)
}
@@ -279,7 +266,7 @@ abstract class ScalaAstVisitor {
if (qualSym ne null) {
withIdToken(getIdToken(qual)) {token =>
val ref = ScalaRef(qualSym, token, if (qualSym.hasFlag(Flags.PACKAGE)) ElementKind.PACKAGE else ElementKind.OTHER, fo)
- if (scopes.top.addRef(ref)) info("\tAdded: ", ref)
+ if (scopes.top.addRef(ref)) logInfo("\tAdded: ", ref)
}
}
@@ -290,7 +277,7 @@ abstract class ScalaAstVisitor {
withIdToken(getIdToken(tree, nme.WILDCARD.decode)) {token =>
val ref = ScalaRef(qualSym, token, ElementKind.OTHER, fo)
if (scopes.top.addRef(ref)) {
- info("\tAdded: ", ref)
+ logInfo("\tAdded: ", ref)
rootScope putImportingItem ref
}
}
@@ -301,7 +288,7 @@ abstract class ScalaAstVisitor {
withIdToken(getIdToken(tree, from.decode)) {idToken =>
val ref = ScalaRef(xsym, idToken, ElementKind.OTHER, fo)
if (scopes.top.addRef(ref)) {
- info("\tAdded: ", ref)
+ logInfo("\tAdded: ", ref)
rootScope putImportingItem ref
}
}
@@ -311,7 +298,7 @@ abstract class ScalaAstVisitor {
withIdToken(getIdToken(tree, to.decode)) {token =>
val ref = ScalaRef(ysym, token, ElementKind.OTHER, fo)
if (scopes.top.addRef(ref)) {
- info("\tAdded: ", ref)
+ logInfo("\tAdded: ", ref)
rootScope putImportingItem ref
}
}
@@ -343,7 +330,7 @@ abstract class ScalaAstVisitor {
// * "case c => println(c)", will define a bind val "c"
withIdToken(getIdToken(tree)) {token =>
val dfn = ScalaDfn(tree.symbol, token, ElementKind.VARIABLE, scope, fo)
- if (scopes.top.addDfn(dfn)) info("\tAdded: ", dfn)
+ if (scopes.top.addDfn(dfn)) logInfo("\tAdded: ", dfn)
}
traverse(body)
@@ -382,7 +369,7 @@ abstract class ScalaAstVisitor {
if (sym ne null) {
withIdToken(getIdToken(tree, "super")) {token =>
val ref = ScalaRef(sym, token, ElementKind.OTHER, fo)
- if (scopes.top.addRef(ref)) info("\tAdded: ", ref)
+ if (scopes.top.addRef(ref)) logInfo("\tAdded: ", ref)
}
}
@@ -391,7 +378,7 @@ abstract class ScalaAstVisitor {
if (sym ne null) {
withIdToken(getIdToken(tree, "this")) {token =>
val ref = ScalaRef(sym, token, ElementKind.OTHER, fo)
- if (scopes.top.addRef(ref)) info("\tAdded: ", ref)
+ if (scopes.top.addRef(ref)) logInfo("\tAdded: ", ref)
}
}
@@ -428,9 +415,9 @@ abstract class ScalaAstVisitor {
* to get the proper resultType, we'll check if the qualierMaybeType isDefined
*/
if ((sym ne null) && !sym.exists) {
- global.recoveredType(tree) foreach {tpex => ref.resultType = tpex}
+ recoveredType(tree) foreach {tpex => ref.resultType = tpex}
}
- if (scopes.top.addRef(ref)) info("\tAdded: ", ref)
+ if (scopes.top.addRef(ref)) logInfo("\tAdded: ", ref)
}
}
}
@@ -454,10 +441,10 @@ abstract class ScalaAstVisitor {
* to get the proper resultType, we'll check if the qualierMaybeType isDefined
*/
if (!sym1.exists) {
- global.recoveredType(tree) foreach {tpex => ref.resultType = tpex}
+ recoveredType(tree) foreach {tpex => ref.resultType = tpex}
}
// * set ref.resultType before addRef to scope, otherwise, it may not be added if there is same symbol had been added
- if (scopes.top.addRef(ref)) info("\tAdded: ", ref)
+ if (scopes.top.addRef(ref)) logInfo("\tAdded: ", ref)
}
}
@@ -491,7 +478,7 @@ abstract class ScalaAstVisitor {
case _ =>
withIdToken(getIdToken(tree)) {token =>
val ref = ScalaRef(sym, token, ElementKind.CLASS, fo)
- if (scopes.top.addRef(ref)) info("\tAdded: ", ref)
+ if (scopes.top.addRef(ref)) logInfo("\tAdded: ", ref)
}
}
}
@@ -547,6 +534,7 @@ abstract class ScalaAstVisitor {
case Parens(ts) =>
traverseTrees(ts)
case _ =>
+ logInfo("Unknow tree: " + tree)
}
}
@@ -603,7 +591,7 @@ abstract class ScalaAstVisitor {
withIdToken(idToken) {token =>
val ref = ScalaRef(sym, token, ElementKind.CLASS, fo)
- if (scopes.top.addRef(ref)) info("\tAdded: ", ref)
+ if (scopes.top.addRef(ref)) logInfo("\tAdded: ", ref)
}
// if tpe is TypeRef, we need to add args type
@@ -625,7 +613,7 @@ abstract class ScalaAstVisitor {
withIdToken(idToken) {token =>
val ref = ScalaRef(sym, token, ElementKind.CLASS, fo)
- if (scopes.top.addRef(ref)) info("\tAdded: ", ref)
+ if (scopes.top.addRef(ref)) logInfo("\tAdded: ", ref)
}
// if tpe is TypeRef, we need to add args type
@@ -635,309 +623,310 @@ abstract class ScalaAstVisitor {
}
}
- }
+
+ // ---- Helper methods
+
+ /**
+ * The symbol with name <code>name</code> imported from import clause <code>tree</code>.
+ * We'll find class/trait instead of object first.
+ * @bug in scala compiler? why name is always TermName? which means it's object instead of class/trait
+ */
+ private def importedSymbol(qual: Tree, xname: Name, yname: Name): Symbol = {
+ val targetName = xname.toTermName
+ val members = try {
+ qual.tpe.members
+ } catch {
+ case ex: Throwable => EmptyScope
+ }
- // ---- Helper methods
+ val result = members filter {_.name.toTermName == targetName}
- /**
- * The symbol with name <code>name</code> imported from import clause <code>tree</code>.
- * We'll find class/trait instead of object first.
- * @bug in scala compiler? why name is always TermName? which means it's object instead of class/trait
- */
- private def importedSymbol(qual: Tree, xname: Name, yname: Name): Symbol = {
- val targetName = xname.toTermName
- val members = try {
- qual.tpe.members
- } catch {
- case ex: Throwable => EmptyScope
+ // * prefer type over object
+ result find ScalaUtil.isProperType getOrElse result.headOption.getOrElse(null)
}
- val result = members filter {_.name.toTermName == targetName}
-
- // * prefer type over object
- result find ScalaUtil.isProperType getOrElse result.headOption.getOrElse(null)
- }
-
- private def withIdToken(idToken: Option[Token[TokenId]])(op: Token[TokenId] => Unit) {
- if (idToken.isDefined) op(idToken.get)
- }
+ private def withIdToken(idToken: Option[Token[TokenId]])(op: Token[TokenId] => Unit) {
+ if (idToken.isDefined) op(idToken.get)
+ }
- /**
- * @Note: nameNode may contains preceding void productions, and may also contains
- * following void productions, but nameString has stripped the void productions,
- * so we should adjust nameRange according to name and its length.
- */
- private def getIdTokenViaPos(pos: Position, knownName: String = "", forward: Int = -1, sym: Symbol): Option[Token[TokenId]] = {
- if (sym eq null) return None
+ /**
+ * @Note: nameNode may contains preceding void productions, and may also contains
+ * followed void productions, but nameString has stripped the void productions,
+ * so we should adjust nameRange according to name and its length.
+ */
+ private def getIdTokenViaPos(pos: Position, knownName: String = "", forward: Int = -1, sym: Symbol): Option[Token[TokenId]] = {
+ if (sym eq null) return None
- if (sym.hasFlag(Flags.SYNTHETIC)) {
- // @todo
- }
+ if (sym.hasFlag(Flags.SYNTHETIC)) {
+ // @todo
+ }
- /** Do not use symbol.nameString or idString) here, for example, a constructor Dog()'s nameString maybe "this" */
- val name = if (knownName.length > 0) knownName else (if (sym != NoSymbol) sym.rawname.decode else "")
- if (name.length == 0) return None
+ /** Do not use symbol.nameString or idString) here, for example, a constructor Dog()'s nameString maybe "this" */
+ val name = if (knownName.length > 0) knownName else (if (sym != NoSymbol) sym.rawname.decode else "")
+ if (name.length == 0) return None
- val offset = if (pos.isDefined) pos.startOrPoint else return None
+ val offset = if (pos.isDefined) pos.startOrPoint else return None
- var endOffset = if (pos.isDefined) pos.endOrPoint else -1
- if (forward != -1) {
- endOffset = math.max(endOffset, offset + forward)
- }
+ var endOffset = if (pos.isDefined) pos.endOrPoint else -1
+ if (forward != -1) {
+ endOffset = math.max(endOffset, offset + forward)
+ }
- val ts = ScalaLexUtil.getTokenSequence(th, offset) getOrElse {return None}
- ts.move(offset)
- if (!ts.moveNext && !ts.movePrevious) {
- assert(false, "Should not happen!")
- }
+ val ts = ScalaLexUtil.getTokenSequence(th, offset) getOrElse {return None}
+ ts.move(offset)
+ if (!ts.moveNext && !ts.movePrevious) {
+ assert(false, "Should not happen!")
+ }
- val token = findIdTokenForward(ts, name, offset, endOffset)
+ val token = findIdTokenForward(ts, name, offset, endOffset)
- token match {
- case Some(x) if x.isFlyweight => Some(ts.offsetToken)
- case x => x
+ token match {
+ case Some(x) if x.isFlyweight => Some(ts.offsetToken)
+ case x => x
+ }
}
- }
- /**
- * @Note: nameNode may contains preceding void productions, and may also contains
- * following void productions, but nameString has stripped the void productions,
- * so we should adjust nameRange according to name and its length.
- */
- private def getIdToken(tree: Tree, knownName: String = "", forward: Int = -1, asym: Symbol = null): Option[Token[TokenId]] = {
- val sym = if (asym ne null) asym else tree.symbol
- if (sym eq null) return None
+ /**
+ * @Note: nameNode may contains preceding void productions, and may also contains
+ * following void productions, but nameString has stripped the void productions,
+ * so we should adjust nameRange according to name and its length.
+ */
+ private def getIdToken(tree: Tree, knownName: String = "", forward: Int = -1, asym: Symbol = null): Option[Token[TokenId]] = {
+ val sym = if (asym ne null) asym else tree.symbol
+ if (sym eq null) return None
- if (sym.hasFlag(Flags.SYNTHETIC)) {
- // @todo
- }
+ if (sym.hasFlag(Flags.SYNTHETIC)) {
+ // @todo
+ }
- /** Do not use symbol.nameString or idString) here, for example, a constructor Dog()'s nameString maybe "this" */
- val name = if (knownName.length > 0) knownName else (if (sym != NoSymbol) sym.rawname.decode else "")
- if (name.length == 0) return None
+ /** Do not use symbol.nameString or idString) here, for example, a constructor Dog()'s nameString maybe "this" */
+ val name = if (knownName.length > 0) knownName else (if (sym != NoSymbol) sym.rawname.decode else "")
+ if (name.length == 0) return None
- val pos = tree.pos
- val offset = if (pos.isDefined) pos.startOrPoint else return None
+ val pos = tree.pos
+ val offset = if (pos.isDefined) pos.startOrPoint else return None
- var endOffset = if (pos.isDefined) pos.endOrPoint else -1
- if (forward != -1) {
- endOffset = math.max(endOffset, offset + forward)
- }
+ var endOffset = if (pos.isDefined) pos.endOrPoint else -1
+ if (forward != -1) {
+ endOffset = math.max(endOffset, offset + forward)
+ }
- val ts = ScalaLexUtil.getTokenSequence(th, offset) getOrElse {return None}
- ts.move(offset)
- if (!ts.moveNext && !ts.movePrevious) {
- assert(false, "Should not happen!")
- }
+ val ts = ScalaLexUtil.getTokenSequence(th, offset) getOrElse {return None}
+ ts.move(offset)
+ if (!ts.moveNext && !ts.movePrevious) {
+ assert(false, "Should not happen!")
+ }
- val token = tree match {
- case _: This => ScalaLexUtil.findNext(ts, ScalaTokenId.This)
- case _: Super => ScalaLexUtil.findNext(ts, ScalaTokenId.Super)
- case _ if name == "this" => ScalaLexUtil.findNext(ts, ScalaTokenId.This)
- case _ if name == "super" => ScalaLexUtil.findNext(ts, ScalaTokenId.Super)
- case _ if name == "expected" => Some(ts.token)
- case _: ValDef if sym hasFlag SYNTHETIC =>
- // * is it a placeholder '_' token ?
- ScalaLexUtil.findNext(ts, ScalaTokenId.Wild) find {_.offset(th) <= endOffset}
+ val token = tree match {
+ case _: This => ScalaLexUtil.findNext(ts, ScalaTokenId.This)
+ case _: Super => ScalaLexUtil.findNext(ts, ScalaTokenId.Super)
+ case _ if name == "this" => ScalaLexUtil.findNext(ts, ScalaTokenId.This)
+ case _ if name == "super" => ScalaLexUtil.findNext(ts, ScalaTokenId.Super)
+ case _ if name == "expected" => Some(ts.token)
+ case _: ValDef if sym hasFlag SYNTHETIC =>
+ // * is it a placeholder '_' token ?
+ ScalaLexUtil.findNext(ts, ScalaTokenId.Wild) find {_.offset(th) <= endOffset}
- case _: Select if name == "apply" =>
- // * for Select tree that is `apple` call, will look forward for the nearest id token
- //val content = getContent(offset, endOffset)
- ScalaLexUtil.findNextIn(ts, ScalaLexUtil.PotentialIdTokens)
-
- case _: Select if endOffset > 0 =>
- // * for Select tree, will look backward from endOffset
- ts.move(endOffset)
- findIdTokenBackward(ts, name, offset, endOffset) match {
- case None =>
- // * bug in scalac, wrong RangePosition for "list filter {...}", the range only contains "list"
- ts.move(endOffset)
- if (ts.moveNext && ts.movePrevious) {
- val end = math.min(endOffset + 100, docLength - 1)
- findIdTokenForward(ts, name, endOffset, end)
- } else None
- case x => x
- }
+ case _: Select if name == "apply" =>
+ // * for Select tree that is `apple` call, will look forward for the nearest id token
+ //val content = getContent(offset, endOffset)
+ ScalaLexUtil.findNextIn(ts, ScalaLexUtil.PotentialIdTokens)
+
+ case _: Select if endOffset > 0 =>
+ // * for Select tree, will look backward from endOffset
+ ts.move(endOffset)
+ findIdTokenBackward(ts, name, offset, endOffset) match {
+ case None =>
+ // * bug in scalac, wrong RangePosition for "list filter {...}", the range only contains "list"
+ ts.move(endOffset)
+ if (ts.moveNext && ts.movePrevious) {
+ val end = math.min(endOffset + 100, docLength - 1)
+ findIdTokenForward(ts, name, endOffset, end)
+ } else None
+ case x => x
+ }
- case _: Import =>
- //println("import tree content=" + getContent(offset, endOffset) + ", name=" + name)
- ts.move(endOffset)
- findIdTokenBackward(ts, name, offset, endOffset)
+ case _: Import =>
+ //println("import tree content=" + getContent(offset, endOffset) + ", name=" + name)
+ ts.move(endOffset)
+ findIdTokenBackward(ts, name, offset, endOffset)
- case _ => findIdTokenForward(ts, name, offset, endOffset)
- }
+ case _ => findIdTokenForward(ts, name, offset, endOffset)
+ }
- token match {
- case Some(x) if x.isFlyweight => Some(ts.offsetToken)
- case x => x
+ token match {
+ case Some(x) if x.isFlyweight => Some(ts.offsetToken)
+ case x => x
+ }
}
- }
- private def findIdTokenForward(ts: TokenSequence[TokenId], name: String, offset: Int, endOffset: Int): Option[Token[TokenId]] = {
- var token = ScalaLexUtil.findNextIn(ts, ScalaLexUtil.PotentialIdTokens)
- var curr = offset + token.get.length
- while (token.isDefined && !tokenNameEquals(token.get, name) && curr <= endOffset) {
- token = if (ts.moveNext) {
- ScalaLexUtil.findNextIn(ts, ScalaLexUtil.PotentialIdTokens)
- } else None
- if (token.isDefined) curr = ts.offset + token.get.length
- }
+ private def findIdTokenForward(ts: TokenSequence[TokenId], name: String, offset: Int, endOffset: Int): Option[Token[TokenId]] = {
+ var token = ScalaLexUtil.findNextIn(ts, ScalaLexUtil.PotentialIdTokens)
+ var curr = offset + token.get.length
+ while (token.isDefined && !tokenNameEquals(token.get, name) && curr <= endOffset) {
+ token = if (ts.moveNext) {
+ ScalaLexUtil.findNextIn(ts, ScalaLexUtil.PotentialIdTokens)
+ } else None
+ if (token.isDefined) curr = ts.offset + token.get.length
+ }
- token match {
- case Some(x) if tokenNameEquals(x, name) => token
- case _ => None
+ token match {
+ case Some(x) if tokenNameEquals(x, name) => token
+ case _ => None
+ }
}
- }
- private def findIdTokenBackward(ts: TokenSequence[TokenId], name: String, offset: Int, endOffset: Int): Option[Token[TokenId]] = {
- var token = if (ts.movePrevious) {
- ScalaLexUtil.findPreviousIn(ts, ScalaLexUtil.PotentialIdTokens)
- } else None
- var curr = endOffset
- while (token.isDefined && !tokenNameEquals(token.get, name) && curr >= offset) {
- token = if (ts.movePrevious) {
+ private def findIdTokenBackward(ts: TokenSequence[TokenId], name: String, offset: Int, endOffset: Int): Option[Token[TokenId]] = {
+ var token = if (ts.movePrevious) {
ScalaLexUtil.findPreviousIn(ts, ScalaLexUtil.PotentialIdTokens)
} else None
- if (token.isDefined) curr = ts.offset
- }
+ var curr = endOffset
+ while (token.isDefined && !tokenNameEquals(token.get, name) && curr >= offset) {
+ token = if (ts.movePrevious) {
+ ScalaLexUtil.findPreviousIn(ts, ScalaLexUtil.PotentialIdTokens)
+ } else None
+ if (token.isDefined) curr = ts.offset
+ }
- token match {
- case Some(x) if tokenNameEquals(x, name) => token
- case _ => None
+ token match {
+ case Some(x) if tokenNameEquals(x, name) => token
+ case _ => None
+ }
}
- }
- private def tokenNameEquals(token: Token[_], name: String): Boolean = {
- val text = token.text.toString
- token.id match {
- case ScalaTokenId.SymbolLiteral => text.substring(1, text.length - 1) == name // strip '`'
- case ScalaTokenId.LArrow if name == "foreach" || name == "map" => true
- case ScalaTokenId.Identifier if name == "apply" || name.startsWith("<error") => true // return the first matched identifier token
- case _ if name.endsWith("_=") => text == name || text + "_=" == name
- case _ if name == "Sequence" => text == name || text == "Seq" // Seq may have symbol name "Sequence"
- case _ => text == name
+ private def tokenNameEquals(token: Token[_], name: String): Boolean = {
+ val text = token.text.toString
+ token.id match {
+ case ScalaTokenId.SymbolLiteral => text.substring(1, text.length - 1) == name // strip '`'
+ case ScalaTokenId.LArrow if name == "foreach" || name == "map" => true
+ case ScalaTokenId.Identifier if name == "apply" || name.startsWith("<error") => true // return the first matched identifier token
+ case _ if name.endsWith("_=") => text == name || text + "_=" == name
+ case _ if name == "Sequence" => text == name || text == "Seq" // Seq may have symbol name "Sequence"
+ case _ => text == name
+ }
}
- }
- private def getContent(offset: Int, endOffset: Int): CharSequence = {
- if (endOffset > offset && offset > -1) {
- srcFile.content.subSequence(offset, endOffset)
- } else ""
- }
+ private def getContent(offset: Int, endOffset: Int): CharSequence = {
+ if (endOffset > offset && offset > -1) {
+ srcFile.content.subSequence(offset, endOffset)
+ } else ""
+ }
- private def getBoundsTokens(offset: Int, endOffset: Int): Array[Token[TokenId]] = {
- Array(getBoundsToken(offset).getOrElse(null), getBoundsEndToken(endOffset).getOrElse(null))
- }
+ private def getBoundsTokens(offset: Int, endOffset: Int): Array[Token[TokenId]] = {
+ Array(getBoundsToken(offset).getOrElse(null), getBoundsEndToken(endOffset).getOrElse(null))
+ }
- private def getBoundsTokens(tree: Tree): Array[Token[TokenId]] = {
- val pos = tree.pos
- val (offset, endOffset) = if (tree.pos.isDefined) {
- (pos.startOrPoint, pos.endOrPoint)
- } else (-1, -1)
+ private def getBoundsTokens(tree: Tree): Array[Token[TokenId]] = {
+ val pos = tree.pos
+ val (offset, endOffset) = if (tree.pos.isDefined) {
+ (pos.startOrPoint, pos.endOrPoint)
+ } else (-1, -1)
- getBoundsTokens(offset, endOffset)
- }
+ getBoundsTokens(offset, endOffset)
+ }
- private def getBoundsToken(offset: Int): Option[Token[TokenId]] = {
- if (offset < 0) return None
+ private def getBoundsToken(offset: Int): Option[Token[TokenId]] = {
+ if (offset < 0) return None
- val ts = ScalaLexUtil.getTokenSequence(th, offset).getOrElse(return None)
- ts.move(offset)
- if (!ts.moveNext && !ts.movePrevious) {
- assert(false, "Should not happen!")
- }
+ val ts = ScalaLexUtil.getTokenSequence(th, offset).getOrElse(return None)
+ ts.move(offset)
+ if (!ts.moveNext && !ts.movePrevious) {
+ assert(false, "Should not happen!")
+ }
- val startToken = ScalaLexUtil.findPreviousNoWsNoComment(ts) match {
- case Some(x) if x.isFlyweight => Some(ts.offsetToken)
- case x => x
- }
+ val startToken = ScalaLexUtil.findPreviousNoWsNoComment(ts) match {
+ case Some(x) if x.isFlyweight => Some(ts.offsetToken)
+ case x => x
+ }
- if (startToken == None) {
- println("null start token(" + offset + ")")
- }
+ if (startToken == None) {
+ println("null start token(" + offset + ")")
+ }
- startToken
- }
+ startToken
+ }
- private def getBoundsEndToken(endOffset: Int): Option[Token[TokenId]] = {
- if (endOffset == -1) return None
+ private def getBoundsEndToken(endOffset: Int): Option[Token[TokenId]] = {
+ if (endOffset == -1) return None
- val ts = ScalaLexUtil.getTokenSequence(th, endOffset).getOrElse{return None}
- ts.move(endOffset)
- if (!ts.movePrevious && !ts.moveNext) {
- assert(false, "Should not happen!")
- }
+ val ts = ScalaLexUtil.getTokenSequence(th, endOffset).getOrElse{return None}
+ ts.move(endOffset)
+ if (!ts.movePrevious && !ts.moveNext) {
+ assert(false, "Should not happen!")
+ }
- val endToken = ScalaLexUtil.findPreviousNoWsNoComment(ts) match {
- case Some(x) if x.isFlyweight => Some(ts.offsetToken)
- case x => x
+ val endToken = ScalaLexUtil.findPreviousNoWsNoComment(ts) match {
+ case Some(x) if x.isFlyweight => Some(ts.offsetToken)
+ case x => x
+ }
+
+ endToken
}
- endToken
- }
+ private def logInfo(message: String): Unit = {
+ if (!debug) return
- private def info(message: String): Unit = {
- if (!debug) return
+ println(message)
+ }
- println(message)
- }
+ private def logInfo(message: String, item: AstItem): Unit = {
+ if (!debug) return
- private def info(message: String, item: AstItem): Unit = {
- if (!debug) return
+ print(message)
+ println(item)
+ }
- print(message)
- println(item)
- }
+ private def debugPrintAstPath(tree: Tree): Unit = {
+ if (!debug) {
+ return
+ }
- private def debugPrintAstPath(tree: Tree): Unit = {
- if (!debug) {
- return
- }
+ val idTokenStr = getIdToken(tree) match {
+ case None => "<null>"
+ case Some(x) => x.text.toString
+ }
- val idTokenStr = getIdToken(tree) match {
- case None => "<null>"
- case Some(x) => x.text.toString
- }
+ val symbol = tree.symbol
+ val symbolStr = if (symbol eq null) "<null>" else symbol.toString
- val symbol = tree.symbol
- val symbolStr = if (symbol eq null) "<null>" else symbol.toString
+ val pos = tree.pos
- val pos = tree.pos
+ println("(" + pos.line + ":" + pos.column + ")" + ", idToken: " + idTokenStr + ", symbol: " + symbolStr)
+ }
- println("(" + pos.line + ":" + pos.column + ")" + ", idToken: " + idTokenStr + ", symbol: " + symbolStr)
- }
+ /**
+ * Used when endOffset of tree is not available.
+ * @Note from scala-2.8.x, the endOffset has been added, just keep this method
+ * here for reference.
+ */
+ private def setBoundsEndToken(fromScope: AstScope) {
+ assert(fromScope.isScopesSorted == false)
- /**
- * Used when endOffset of tree is not available.
- * @Note from scala-2.8.x, the endOffset has been added, just keep this method
- * here for reference.
- */
- private def setBoundsEndToken(fromScope: AstScope) {
- assert(fromScope.isScopesSorted == false)
-
- val children = fromScope.subScopes
- val itr = children.iterator
- var curr = if (itr.hasNext) itr.next else null
- while (curr ne null) {
- if (itr.hasNext) {
- val next = itr.next
- val offset = next.boundsOffset(th)
- if (offset != -1) {
- val endToken = getBoundsEndToken(offset - 1)
- curr.boundsEndToken = endToken
+ val children = fromScope.subScopes
+ val itr = children.iterator
+ var curr = if (itr.hasNext) itr.next else null
+ while (curr ne null) {
+ if (itr.hasNext) {
+ val next = itr.next
+ val offset = next.boundsOffset(th)
+ if (offset != -1) {
+ val endToken = getBoundsEndToken(offset - 1)
+ curr.boundsEndToken = endToken
+ } else {
+ println("Scope without start token: " + next)
+ }
+ curr = next
} else {
- println("Scope without start token: " + next)
- }
- curr = next
- } else {
- curr.parent match {
- case Some(x) => curr.boundsEndToken = x.boundsEndToken
- case None =>
+ curr.parent match {
+ case Some(x) => curr.boundsEndToken = x.boundsEndToken
+ case None =>
+ }
+ curr = null
}
- curr = null
}
- }
- children foreach setBoundsEndToken
+ children foreach setBoundsEndToken
+ }
}
+
}
View
11 scala.core/src/main/scala/org/netbeans/modules/scala/core/ast/ScalaDfns.scala
@@ -108,18 +108,11 @@ trait ScalaDfns {self: ScalaGlobal =>
}
def htmlFormat(fm: HtmlFormatter) {
- ScalaUtil.htmlFormat(symbol, fm)
+ ScalaUtil.askForHtmlFormat(symbol, fm)
}
def sigFormat(fm: HtmlFormatter) {
- try {
- fm.appendHtml("<i>")
- fm.appendText(symbol.enclClass.fullName)
- fm.appendHtml("</i><p>")
- ScalaUtil.htmlDef(symbol, fm)
- } catch {
- case ex: Throwable => ScalaGlobal.resetLate(self, ex)
- }
+ ScalaUtil.askForHtmlDef(symbol, fm)
}
}
View
15 scala.core/src/main/scala/org/netbeans/modules/scala/core/ast/ScalaRootScope.scala
@@ -38,12 +38,11 @@
*/
package org.netbeans.modules.scala.core.ast
-import org.netbeans.api.lexer.{Token, TokenId}
+import org.netbeans.api.lexer.Token
+import org.netbeans.api.lexer.TokenId
+import org.netbeans.api.language.util.ast.AstRootScope
-import org.netbeans.api.language.util.ast.{AstRootScope}
-import scala.tools.nsc.CompilationUnits
-
-class ScalaRootScope(val unit: Option[CompilationUnits#CompilationUnit], boundsTokens: Array[Token[TokenId]]
+class ScalaRootScope(boundsTokens: Array[Token[TokenId]]
) extends AstRootScope(boundsTokens) {
// def findDfnOfSym(symbol:AstSymbol[_]): Option[AstDfn] = {
// _idTokenToItem.values.find{item =>
@@ -54,10 +53,10 @@ class ScalaRootScope(val unit: Option[CompilationUnits#CompilationUnit], boundsT
}
object ScalaRootScope {
- def apply(unit: Option[CompilationUnits#CompilationUnit], boundsTokens: Array[Token[TokenId]]) = {
- new ScalaRootScope(unit, boundsTokens)
+ def apply(boundsTokens: Array[Token[TokenId]]) = {
+ new ScalaRootScope(boundsTokens)
}
- val EMPTY = new ScalaRootScope(None, Array())
+ val EMPTY = new ScalaRootScope(Array())
}
View
393 scala.core/src/main/scala/org/netbeans/modules/scala/core/ast/ScalaUtils.scala
@@ -50,25 +50,31 @@ import scala.reflect.internal.Flags
trait ScalaUtils {self: ScalaGlobal =>
object ScalaUtil {
+
def getModifiers(symbol: Symbol): java.util.Set[Modifier] = {
val modifiers = new java.util.HashSet[Modifier]
+ askForResponse {() =>
- if (symbol hasFlag Flags.PROTECTED) {
- modifiers.add(Modifier.PROTECTED)
- } else if (symbol hasFlag Flags.PRIVATE) {
- modifiers.add(Modifier.PRIVATE)
- } else {
- modifiers.add(Modifier.PUBLIC)
- }
+ if (symbol hasFlag Flags.PROTECTED) {
+ modifiers.add(Modifier.PROTECTED)
+ } else if (symbol hasFlag Flags.PRIVATE) {
+ modifiers.add(Modifier.PRIVATE)
+ } else {
+ modifiers.add(Modifier.PUBLIC)
+ }
- if (symbol hasFlag Flags.MUTABLE) modifiers.add(Modifier.STATIC) // to use STATIC icon only
- if (symbol.isDeprecated) modifiers.add(Modifier.DEPRECATED)
+ if (symbol hasFlag Flags.MUTABLE) modifiers.add(Modifier.STATIC) // to use STATIC icon only
+ if (symbol.isDeprecated) modifiers.add(Modifier.DEPRECATED)
- modifiers
+ modifiers
+ } get match {
+ case Left(x) => x
+ case Right(_) => modifiers
+ }
}
def getKind(sym: Symbol): ElementKind = {
- try {
+ askForResponse {() =>
if (sym.isPackage) {
ElementKind.PACKAGE
} else if (sym.isClass) {
@@ -87,6 +93,8 @@ trait ScalaUtils {self: ScalaGlobal =>
ElementKind.FIELD
} else if (sym.isVariable) {
ElementKind.VARIABLE
+ } else if (sym.isGetter) {
+ ElementKind.FIELD
} else if (sym.isMethod) {
ElementKind.METHOD
} else if (sym.isValueParameter) {
@@ -96,11 +104,14 @@ trait ScalaUtils {self: ScalaGlobal =>
} else {
ElementKind.OTHER
}
- } catch {
- case t: Throwable => ElementKind.OTHER
+
+ } get match {
+ case Left(x) => x
+ case Right(_) =>
// java.lang.Error: no-symbol does not have owner
// at scala.tools.nsc.symtab.Symbols$NoSymbol$.owner(Symbols.scala:1609)
// at scala.tools.nsc.symtab.Symbols$Symbol.isLocal(Symbols.scala:346)
+ ElementKind.OTHER
}
}
@@ -148,7 +159,7 @@ trait ScalaUtils {self: ScalaGlobal =>
}
def typeQualifiedName(tpe: Type, forScala: Boolean): String = {
- symbolQualifiedName(tpe.typeSymbol, forScala);
+ symbolQualifiedName(tpe.typeSymbol, forScala)
}
def isInherited(template: Symbol, member: Symbol): Boolean = {
@@ -167,23 +178,28 @@ trait ScalaUtils {self: ScalaGlobal =>
if (str ne null) str else tpe.termSymbol.nameString
}
- def htmlFormat(symbol: Symbol, fm: HtmlFormatter): Unit = {
- symbol match {
- case sym if sym.isPackage | sym.isClass | sym.isModule => fm.appendText(sym.nameString)
- case sym if sym.isConstructor =>
- fm.appendText(sym.owner.nameString)
- htmlTypeName(sym, fm)
- case sym if sym.isMethod =>
- fm.appendText(sym.nameString)
- htmlTypeName(sym, fm)
- case sym =>
- fm.appendText(sym.nameString)
- fm.appendText(": ")
- htmlTypeName(sym, fm)
+ def askForHtmlFormat(symbol: Symbol, fm: HtmlFormatter) {
+ askForResponse {() =>
+ symbol match {
+ case sym if sym.isPackage | sym.isClass | sym.isModule => fm.appendText(sym.nameString)
+ case sym if sym.isConstructor =>
+ fm.appendText(sym.owner.nameString)
+ htmlTypeName(sym, fm)
+ case sym if sym.isMethod =>
+ fm.appendText(sym.nameString)
+ htmlTypeName(sym, fm)
+ case sym =>
+ fm.appendText(sym.nameString)
+ fm.appendText(": ")
+ htmlTypeName(sym, fm)
+ }
+ } get match {
+ case Left(_) =>
+ case Right(_) =>
}
}
- def tryTpe(sym: Symbol): Type = {
+ private def tryTpe(sym: Symbol): Type = {
try {
sym.tpe
} catch {
@@ -191,11 +207,11 @@ trait ScalaUtils {self: ScalaGlobal =>
}
}
- def htmlTypeName(sym: Symbol, fm: HtmlFormatter): Unit = {
+ private def htmlTypeName(sym: Symbol, fm: HtmlFormatter) {
htmlTypeName(tryTpe(sym), fm)
}
- def htmlTypeName(tpe: Type, fm: HtmlFormatter): Unit = {
+ private def htmlTypeName(tpe: Type, fm: HtmlFormatter): Unit = {
if (tpe eq null) return
tpe match {
case ErrorType => fm.appendText("<error>")
@@ -307,39 +323,51 @@ trait ScalaUtils {self: ScalaGlobal =>
* String representation of symbol's definition
* from scala.tools.nsc.symtab.Symbols
*/
- def htmlDef(sym: Symbol, fm: HtmlFormatter): Unit = {
- // * no-symbol does not have owner
- if (sym == NoSymbol) {
- fm.appendText("<no-symbol>")
- return
- }
+ def askForHtmlDef(sym: Symbol, fm: HtmlFormatter) {
+
+ askForResponse {() =>
+ fm.appendHtml("<i>")
+ fm.appendText(sym.enclClass.fullName)
+ fm.appendHtml("</i><p>")
+
+ // * no-symbol does not have owner
+ if (sym == NoSymbol) {
+ fm.appendText("<no-symbol>")
+ return
+ }
- completeIfWithLazyType(sym)
+ completeIfWithLazyType(sym)
- val flags = if (sym.owner.isRefinementClass) {
- sym.flags & Flags.ExplicitFlags & ~Flags.OVERRIDE
- } else sym.flags & Flags.ExplicitFlags
+ val flags = if (sym.owner.isRefinementClass) {
+ sym.flags & Flags.ExplicitFlags & ~Flags.OVERRIDE
+ } else sym.flags & Flags.ExplicitFlags
- compose(List(Flags.flagsToString(flags),
- sym.keyString,
- sym.varianceString + sym.nameString), fm)
+ compose(List(Flags.flagsToString(flags),
+ sym.keyString,
+ sym.varianceString + sym.nameString), fm)
- sym match {
- case _ if sym.isPackage | sym.isClass | sym.isTrait =>
- if (sym.hasRawInfo) htmlTypeInfo(sym.rawInfo, fm)
- case _ if sym.isModule => // object, the `rawInfo` is `TypeRef`, we should dive into `sym.moduleClass`
- if (sym.hasRawInfo) htmlTypeInfo(sym.moduleClass.rawInfo, fm)
- case _ if sym.isConstructor =>
- if (sym.hasRawInfo) fm.appendText(sym.infoString(sym.rawInfo))
- case _ if sym.isMethod =>
- if (sym.hasRawInfo) fm.appendText(sym.infoString(sym.rawInfo))
- case _ =>
- if (sym.hasRawInfo) fm.appendText(sym.infoString(sym.rawInfo))
- }
+ sym match {
+ case _ if sym.isPackage | sym.isClass | sym.isTrait =>
+ if (sym.hasRawInfo) htmlTypeInfo(sym.rawInfo, fm)
+ case _ if sym.isModule => // object, the `rawInfo` is `TypeRef`, we should dive into `sym.moduleClass`
+ if (sym.hasRawInfo) htmlTypeInfo(sym.moduleClass.rawInfo, fm)
+ case _ if sym.isConstructor =>
+ if (sym.hasRawInfo) fm.appendText(sym.infoString(sym.rawInfo))
+ case _ if sym.isMethod =>
+ if (sym.hasRawInfo) fm.appendText(sym.infoString(sym.rawInfo))
+ case _ =>
+ if (sym.hasRawInfo) fm.appendText(sym.infoString(sym.rawInfo))
+ }
+
+ } get match {
+ case Left(x) =>
+ case Right(ex) =>
+ ScalaGlobal.resetLate(self, ex)
+ }
}
/** Concatenate strings separated by spaces */
- private def compose(ss: List[String], fm: HtmlFormatter): Unit = {
+ private def compose(ss: List[String], fm: HtmlFormatter) {
val itr = ss.filter("" !=).iterator
while (itr.hasNext) {
fm.appendText(itr.next)
@@ -347,7 +375,7 @@ trait ScalaUtils {self: ScalaGlobal =>
}
}
- def htmlTypeInfo(tpe: Type, fm: HtmlFormatter): Unit = {
+ private def htmlTypeInfo(tpe: Type, fm: HtmlFormatter) {
if (tpe eq null) return
tpe match {
case ErrorType => fm.appendText("<error>")
@@ -476,133 +504,138 @@ trait ScalaUtils {self: ScalaGlobal =>
}
def completeIfWithLazyType(sym: Symbol) {
- val topClazz = sym.enclosingTopLevelClass
+ askForResponse {() =>
+ val topClazz = sym.enclosingTopLevelClass
- if (topClazz.nameString.indexOf('$') != -1) return // avoid assertion error @see
+ if (topClazz.nameString.indexOf('$') != -1) return // avoid assertion error @see
- val (clazz, staticModule) = if (topClazz.isModule) {
- (topClazz.companionClass, topClazz)
- } else {
- (topClazz, topClazz.companionModule)
- }
+ val (clazz, staticModule) = if (topClazz.isModule) {
+ (topClazz.companionClass, topClazz)
+ } else {
+ (topClazz, topClazz.companionModule)
+ }
- if (clazz != NoSymbol && staticModule != NoSymbol) { // avoid Error: NoSymbol does not have owner
- topClazz.rawInfo match {
- case x if !x.isComplete =>
- /*
- java.lang.AssertionError: assertion failed: object NotificationDisplayer$NotificationImpl
- at scala.Predef$.assert(Predef.scala:179)
- at scala.tools.nsc.Global.assert(Global.scala:239)
- at scala.tools.nsc.symtab.SymbolLoaders.enterClassAndModule(SymbolLoaders.scala:100)
- at scala.tools.nsc.symtab.SymbolLoaders.initializeFromClassPath(SymbolLoaders.scala:138)
- at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader$$anonfun$doComplete$3.apply(SymbolLoaders.scala:232)
- at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader$$anonfun$doComplete$3.apply(SymbolLoaders.scala:231)
- at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:772)
- at scala.collection.Iterator$class.foreach(Iterator.scala:727)
- at scala.collection.AbstractIterator.foreach(Iterator.scala:1156)
- at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
- at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
- at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:771)
- at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader.doComplete(SymbolLoaders.scala:231)
- at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:187)
- at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1217)
- at scala.reflect.internal.Types$TypeRef.thisInfo(Types.scala:2364)
- at scala.reflect.internal.Types$TypeRef.baseClasses(Types.scala:2369)
- at scala.reflect.internal.Types$Type.findMember(Types.scala:1138)
- at scala.reflect.internal.Types$Type.memberBasedOnName(Types.scala:687)
- at scala.reflect.internal.Types$Type.member(Types.scala:645)
- at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:43)
- at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:61)
- at scala.reflect.internal.Mirrors$RootsBase.getClassByName(Mirrors.scala:99)
- at scala.reflect.internal.Mirrors$RootsBase.getClass(Mirrors.scala:96)
- at scala.tools.nsc.symtab.classfile.ClassfileParser.lookupClass$1(ClassfileParser.scala:481)
- at scala.tools.nsc.symtab.classfile.ClassfileParser.classNameToSymbol(ClassfileParser.scala:494)
- at scala.tools.nsc.symtab.classfile.ClassfileParser.sig2type$1(ClassfileParser.scala:755)
- at scala.tools.nsc.symtab.classfile.ClassfileParser.sig2type$1(ClassfileParser.scala:792)
- at scala.tools.nsc.symtab.classfile.ClassfileParser.scala$tools$nsc$symtab$classfile$ClassfileParser$$sigToType(ClassfileParser.scala:838)
- at scala.tools.nsc.symtab.classfile.ClassfileParser$ConstantPool.getType(ClassfileParser.scala:334)
- at scala.tools.nsc.symtab.classfile.ClassfileParser.parseMethod(ClassfileParser.scala:644)
- at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$scala$tools$nsc$symtab$classfile$ClassfileParser$$queueLoad$1$2.apply$mcVI$sp(ClassfileParser.scala:565)
- at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:142)
- at scala.tools.nsc.symtab.classfile.ClassfileParser.scala$tools$nsc$symtab$classfile$ClassfileParser$$queueLoad$1(ClassfileParser.scala:565)
- at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$parseClass$1.apply$mcV$sp(ClassfileParser.scala:575)
- at scala.tools.nsc.symtab.classfile.ClassfileParser.parseClass(ClassfileParser.scala:580)
- at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$parse$1.apply$mcV$sp(ClassfileParser.scala:105)
- at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$parse$1.apply(ClassfileParser.scala:94)
- at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$parse$1.apply(ClassfileParser.scala:94)
- at scala.tools.nsc.symtab.classfile.ClassfileParser.pushBusy(ClassfileParser.scala:81)
- at scala.tools.nsc.symtab.classfile.ClassfileParser.parse(ClassfileParser.scala:94)
- at scala.tools.nsc.symtab.SymbolLoaders$ClassfileLoader.doComplete(SymbolLoaders.scala:254)
- at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:187)
- at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.load(SymbolLoaders.scala:203)
- at scala.reflect.internal.Symbols$Symbol.exists(Symbols.scala:884)
- at scala.tools.nsc.typechecker.Typers$Typer.typedIdent$1(Typers.scala:4894)
- at scala.tools.nsc.typechecker.Typers$Typer.typedIdentOrWildcard$1(Typers.scala:5048)
- at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5379)
- at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5458)
- at scala.tools.nsc.typechecker.Typers$Typer.typedTypeConstructor(Typers.scala:5588)
- at scala.tools.nsc.typechecker.Typers$Typer.typedTypeConstructor(Typers.scala:5616)
- at scala.tools.nsc.typechecker.Typers$Typer.parentTypes(Typers.scala:1495)
- at scala.tools.nsc.typechecker.Namers$Namer.templateSig(Namers.scala:861)
- at scala.tools.nsc.typechecker.Namers$Namer.classSig(Namers.scala:907)
- at scala.tools.nsc.typechecker.Namers$Namer.getSig$1(Namers.scala:1291)
- at scala.tools.nsc.typechecker.Namers$Namer.typeSig(Namers.scala:1349)
- at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply$mcV$sp(Namers.scala:709)
- at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply(Namers.scala:708)
- at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply(Namers.scala:708)
- at scala.tools.nsc.typechecker.Namers$Namer$LogTransitions.apply(Namers.scala:1378)
- at scala.tools.nsc.typechecker.Namers$Namer.scala$tools$nsc$typechecker$Namers$Namer$$logAndValidate(Namers.scala:1387)
- at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1.apply(Namers.scala:708)
- at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1.apply(Namers.scala:707)
- at scala.tools.nsc.typechecker.Namers$$anon$1.completeImpl(Namers.scala:1498)
- at scala.tools.nsc.typechecker.Namers$LockingTypeCompleter$class.complete(Namers.scala:1506)
- at scala.tools.nsc.typechecker.Namers$$anon$1.complete(Namers.scala:1496)
- at org.netbeans.modules.scala.core.ast.ScalaUtils$ScalaUtil$.completeIfWithLazyType(ScalaUtils.scala:491)
- at org.netbeans.modules.scala.core.ast.ScalaUtils$ScalaUtil$.isProperType(ScalaUtils.scala:499)
- at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$$anonfun$org$netbeans$modules$scala$core$ast$ScalaAstVisitor$$importedSymbol$1.apply(ScalaAstVisitor.scala:658)
- at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$$anonfun$org$netbeans$modules$scala$core$ast$ScalaAstVisitor$$importedSymbol$1.apply(ScalaAstVisitor.scala:658)
- at scala.collection.Iterator$class.find(Iterator.scala:780)
- at scala.collection.AbstractIterator.find(Iterator.scala:1156)
- at scala.collection.IterableLike$class.find(IterableLike.scala:79)
- at scala.reflect.internal.Scopes$Scope.find(Scopes.scala:44)
- at org.netbeans.modules.scala.core.ast.ScalaAstVisitor.org$netbeans$modules$scala$core$ast$ScalaAstVisitor$$importedSymbol(ScalaAstVisitor.scala:658)
- at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$$anonfun$org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverse$15.apply(ScalaAstVisitor.scala:299)
- at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$$anonfun$org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverse$15.apply(ScalaAstVisitor.scala:287)
- at scala.collection.immutable.List.foreach(List.scala:309)
- at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$.org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverse(ScalaAstVisitor.scala:287)
- at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$$anonfun$org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverseTrees$1.apply(ScalaAstVisitor.scala:554)
- at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$$anonfun$org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverseTrees$1.apply(ScalaAstVisitor.scala:554)
- at scala.collection.immutable.List.foreach(List.scala:309)
- at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$.org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverseTrees(ScalaAstVisitor.scala:554)
- at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$$anonfun$org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverse$1.apply$mcV$sp(ScalaAstVisitor.scala:144)
- at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$.org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$atOwner(ScalaAstVisitor.scala:580)
- at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$.org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverse(ScalaAstVisitor.scala:142)
- at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$.apply(ScalaAstVisitor.scala:114)
- at org.netbeans.modules.scala.core.ast.ScalaAstVisitor.visit(ScalaAstVisitor.scala:104)
- at org.netbeans.modules.scala.core.ScalaGlobal.getSemanticRoot(ScalaGlobal.scala:280)
- [catch] at org.netbeans.modules.scala.core.ScalaGlobal.askForSemantic(ScalaGlobal.scala:193)
- at org.netbeans.modules.scala.core.ScalaParserResult.toSemanticed(ScalaParserResult.scala:121)
- at org.netbeans.modules.scala.core.ScalaParserResult.rootScope$lzycompute(ScalaParserResult.scala:167)
- at org.netbeans.modules.scala.core.ScalaParserResult.rootScope(ScalaParserResult.scala:164)
- at org.netbeans.modules.scala.editor.overridden.IsOverriddenAnnotationHandler.process(IsOverriddenAnnotationHandler.scala:241)
- at org.netbeans.modules.scala.editor.overridden.IsOverriddenAnnotationHandler.run(IsOverriddenAnnotationHandler.scala:218)
- at org.netbeans.modules.scala.editor.overridden.IsOverriddenAnnotationHandler.run(IsOverriddenAnnotationHandler.scala:180)
- at org.netbeans.modules.parsing.impl.TaskProcessor.callParserResultTask(TaskProcessor.java:559)
- at org.netbeans.modules.parsing.impl.TaskProcessor$CompilationJob.run(TaskProcessor.java:735)
- at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
- at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
- at java.util.concurrent.FutureTask.run(FutureTask.java:166)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
- at java.lang.Thread.run(Thread.java:722)
- */
- try {
- x.complete(topClazz)
- } catch {
- case ex: Throwable =>
- }
- case _ =>
+ if (clazz != NoSymbol && staticModule != NoSymbol) { // avoid Error: NoSymbol does not have owner
+ topClazz.rawInfo match {
+ case x if !x.isComplete =>
+ /*
+ java.lang.AssertionError: assertion failed: object NotificationDisplayer$NotificationImpl
+ at scala.Predef$.assert(Predef.scala:179)
+ at scala.tools.nsc.Global.assert(Global.scala:239)
+ at scala.tools.nsc.symtab.SymbolLoaders.enterClassAndModule(SymbolLoaders.scala:100)
+ at scala.tools.nsc.symtab.SymbolLoaders.initializeFromClassPath(SymbolLoaders.scala:138)
+ at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader$$anonfun$doComplete$3.apply(SymbolLoaders.scala:232)
+ at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader$$anonfun$doComplete$3.apply(SymbolLoaders.scala:231)
+ at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:772)
+ at scala.collection.Iterator$class.foreach(Iterator.scala:727)
+ at scala.collection.AbstractIterator.foreach(Iterator.scala:1156)
+ at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
+ at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
+ at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:771)
+ at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader.doComplete(SymbolLoaders.scala:231)
+ at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:187)
+ at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1217)
+ at scala.reflect.internal.Types$TypeRef.thisInfo(Types.scala:2364)
+ at scala.reflect.internal.Types$TypeRef.baseClasses(Types.scala:2369)
+ at scala.reflect.internal.Types$Type.findMember(Types.scala:1138)
+ at scala.reflect.internal.Types$Type.memberBasedOnName(Types.scala:687)
+ at scala.reflect.internal.Types$Type.member(Types.scala:645)
+ at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:43)
+ at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:61)
+ at scala.reflect.internal.Mirrors$RootsBase.getClassByName(Mirrors.scala:99)
+ at scala.reflect.internal.Mirrors$RootsBase.getClass(Mirrors.scala:96)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser.lookupClass$1(ClassfileParser.scala:481)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser.classNameToSymbol(ClassfileParser.scala:494)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser.sig2type$1(ClassfileParser.scala:755)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser.sig2type$1(ClassfileParser.scala:792)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser.scala$tools$nsc$symtab$classfile$ClassfileParser$$sigToType(ClassfileParser.scala:838)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser$ConstantPool.getType(ClassfileParser.scala:334)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser.parseMethod(ClassfileParser.scala:644)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$scala$tools$nsc$symtab$classfile$ClassfileParser$$queueLoad$1$2.apply$mcVI$sp(ClassfileParser.scala:565)
+ at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:142)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser.scala$tools$nsc$symtab$classfile$ClassfileParser$$queueLoad$1(ClassfileParser.scala:565)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$parseClass$1.apply$mcV$sp(ClassfileParser.scala:575)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser.parseClass(ClassfileParser.scala:580)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$parse$1.apply$mcV$sp(ClassfileParser.scala:105)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$parse$1.apply(ClassfileParser.scala:94)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser$$anonfun$parse$1.apply(ClassfileParser.scala:94)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser.pushBusy(ClassfileParser.scala:81)
+ at scala.tools.nsc.symtab.classfile.ClassfileParser.parse(ClassfileParser.scala:94)
+ at scala.tools.nsc.symtab.SymbolLoaders$ClassfileLoader.doComplete(SymbolLoaders.scala:254)
+ at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:187)
+ at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.load(SymbolLoaders.scala:203)
+ at scala.reflect.internal.Symbols$Symbol.exists(Symbols.scala:884)
+ at scala.tools.nsc.typechecker.Typers$Typer.typedIdent$1(Typers.scala:4894)
+ at scala.tools.nsc.typechecker.Typers$Typer.typedIdentOrWildcard$1(Typers.scala:5048)
+ at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5379)
+ at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5458)
+ at scala.tools.nsc.typechecker.Typers$Typer.typedTypeConstructor(Typers.scala:5588)
+ at scala.tools.nsc.typechecker.Typers$Typer.typedTypeConstructor(Typers.scala:5616)
+ at scala.tools.nsc.typechecker.Typers$Typer.parentTypes(Typers.scala:1495)
+ at scala.tools.nsc.typechecker.Namers$Namer.templateSig(Namers.scala:861)
+ at scala.tools.nsc.typechecker.Namers$Namer.classSig(Namers.scala:907)
+ at scala.tools.nsc.typechecker.Namers$Namer.getSig$1(Namers.scala:1291)
+ at scala.tools.nsc.typechecker.Namers$Namer.typeSig(Namers.scala:1349)
+ at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply$mcV$sp(Namers.scala:709)
+ at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply(Namers.scala:708)
+ at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply(Namers.scala:708)
+ at scala.tools.nsc.typechecker.Namers$Namer$LogTransitions.apply(Namers.scala:1378)
+ at scala.tools.nsc.typechecker.Namers$Namer.scala$tools$nsc$typechecker$Namers$Namer$$logAndValidate(Namers.scala:1387)
+ at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1.apply(Namers.scala:708)
+ at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1.apply(Namers.scala:707)
+ at scala.tools.nsc.typechecker.Namers$$anon$1.completeImpl(Namers.scala:1498)
+ at scala.tools.nsc.typechecker.Namers$LockingTypeCompleter$class.complete(Namers.scala:1506)
+ at scala.tools.nsc.typechecker.Namers$$anon$1.complete(Namers.scala:1496)
+ at org.netbeans.modules.scala.core.ast.ScalaUtils$ScalaUtil$.completeIfWithLazyType(ScalaUtils.scala:491)
+ at org.netbeans.modules.scala.core.ast.ScalaUtils$ScalaUtil$.isProperType(ScalaUtils.scala:499)
+ at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$$anonfun$org$netbeans$modules$scala$core$ast$ScalaAstVisitor$$importedSymbol$1.apply(ScalaAstVisitor.scala:658)
+ at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$$anonfun$org$netbeans$modules$scala$core$ast$ScalaAstVisitor$$importedSymbol$1.apply(ScalaAstVisitor.scala:658)
+ at scala.collection.Iterator$class.find(Iterator.scala:780)
+ at scala.collection.AbstractIterator.find(Iterator.scala:1156)
+ at scala.collection.IterableLike$class.find(IterableLike.scala:79)
+ at scala.reflect.internal.Scopes$Scope.find(Scopes.scala:44)
+ at org.netbeans.modules.scala.core.ast.ScalaAstVisitor.org$netbeans$modules$scala$core$ast$ScalaAstVisitor$$importedSymbol(ScalaAstVisitor.scala:658)
+ at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$$anonfun$org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverse$15.apply(ScalaAstVisitor.scala:299)
+ at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$$anonfun$org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverse$15.apply(ScalaAstVisitor.scala:287)
+ at scala.collection.immutable.List.foreach(List.scala:309)
+ at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$.org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverse(ScalaAstVisitor.scala:287)
+ at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$$anonfun$org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverseTrees$1.apply(ScalaAstVisitor.scala:554)
+ at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$$anonfun$org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverseTrees$1.apply(ScalaAstVisitor.scala:554)
+ at scala.collection.immutable.List.foreach(List.scala:309)
+ at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$.org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverseTrees(ScalaAstVisitor.scala:554)
+ at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$$anonfun$org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverse$1.apply$mcV$sp(ScalaAstVisitor.scala:144)
+ at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$.org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$atOwner(ScalaAstVisitor.scala:580)
+ at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$.org$netbeans$modules$scala$core$ast$ScalaAstVisitor$treeTraverser$$traverse(ScalaAstVisitor.scala:142)
+ at org.netbeans.modules.scala.core.ast.ScalaAstVisitor$treeTraverser$.apply(ScalaAstVisitor.scala:114)
+ at org.netbeans.modules.scala.core.ast.ScalaAstVisitor.visit(ScalaAstVisitor.scala:104)
+ at org.netbeans.modules.scala.core.ScalaGlobal.getSemanticRoot(ScalaGlobal.scala:280)
+ [catch] at org.netbeans.modules.scala.core.ScalaGlobal.askForSemantic(ScalaGlobal.scala:193)
+ at org.netbeans.modules.scala.core.ScalaParserResult.toSemanticed(ScalaParserResult.scala:121)
+ at org.netbeans.modules.scala.core.ScalaParserResult.rootScope$lzycompute(ScalaParserResult.scala:167)
+ at org.netbeans.modules.scala.core.ScalaParserResult.rootScope(ScalaParserResult.scala:164)
+ at org.netbeans.modules.scala.editor.overridden.IsOverriddenAnnotationHandler.process(IsOverriddenAnnotationHandler.scala:241)
+ at org.netbeans.modules.scala.editor.overridden.IsOverriddenAnnotationHandler.run(IsOverriddenAnnotationHandler.scala:218)
+ at org.netbeans.modules.scala.editor.overridden.IsOverriddenAnnotationHandler.run(IsOverriddenAnnotationHandler.scala:180)
+ at org.netbeans.modules.parsing.impl.TaskProcessor.callParserResultTask(TaskProcessor.java:559)
+ at org.netbeans.modules.parsing.impl.TaskProcessor$CompilationJob.run(TaskProcessor.java:735)
+ at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
+ at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
+ at java.util.concurrent.FutureTask.run(FutureTask.java:166)
+ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
+ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
+ at java.lang.Thread.run(Thread.java:722)
+ */
+ try {
+ x.complete(topClazz)
+ } catch {
+ case ex: Throwable =>
+ }
+ case _ =>
+ }
}
+ } get match {
+ case Left(_) =>
+ case Right(ex) =>
}
}
View
23 scala.core/src/main/scala/org/netbeans/modules/scala/core/element/ScalaElements.scala
@@ -53,7 +53,7 @@ import org.openide.util.Exceptions
import scala.reflect.internal.Flags
-import org.netbeans.api.language.util.ast.{AstElementHandle}
+import org.netbeans.api.language.util.ast.AstElementHandle
import org.netbeans.modules.scala.core.{JavaSourceUtil, ScalaGlobal, ScalaSourceUtil, ScalaMimeResolver}
@@ -242,7 +242,7 @@ trait ScalaElements {self: ScalaGlobal =>
* position via the AST Tree, or use a tree visitor to update
* all symbols Position
*/
- val root = askForSemantic(srcFile, true)
+ val root = askForSemantic(srcFile)
root.findDfnMatched(symbol) match {
case Some(x) => offset = x.idOffset(srcFile.tokenHierarchy)
case None =>
@@ -265,7 +265,9 @@ trait ScalaElements {self: ScalaGlobal =>
case _: Throwable => false
}
}
- def isDeprecated_=(b: Boolean) {}
+ def isDeprecated_=(b: Boolean) {
+
+ }
def isInherited = _isInherited
def isInherited_=(b: Boolean) {
@@ -273,7 +275,9 @@ trait ScalaElements {self: ScalaGlobal =>
}
def isEmphasize = !isInherited
- def isEmphasize_=(b: Boolean) {}
+ def isEmphasize_=(b: Boolean) {
+
+ }
def isSmart = _isSmart
def isSmart_=(b: Boolean) {
@@ -294,18 +298,11 @@ trait ScalaElements {self: ScalaGlobal =>
}
def htmlFormat(fm: HtmlFormatter) {
- ScalaUtil.htmlFormat(symbol, fm)
+ ScalaUtil.askForHtmlFormat(symbol, fm)
}
def sigFormat(fm: HtmlFormatter) {
- try {
- fm.appendHtml("<i>")
- fm.appendText(symbol.enclClass.fullName)
- fm.appendHtml("</i><p>")
- ScalaUtil.htmlDef(symbol, fm)
- } catch {
- case ex: Throwable => ScalaGlobal.resetLate(self, ex)
- }
+ ScalaUtil.askForHtmlDef(symbol, fm)
}
}
View
227 scala.editor/src/main/scala/org/netbeans/modules/scala/editor/JavaStubGenerator.scala
@@ -69,147 +69,152 @@ abstract class JavaStubGenerator extends scala.reflect.internal.transform.Erasur
@throws(classOf[FileNotFoundException])
def genClass(pkgName: String, clzName: String, syms: Array[Symbol]): CharSequence = {
- val javaCode = new StringBuilder(1024)
+ global.askForResponse {() =>
+ val javaCode = new StringBuilder(1024)
- if (!pkgName.isEmpty) {
- javaCode ++= "package " ++= pkgName ++= ";\n"
- }
+ if (!pkgName.isEmpty) {
+ javaCode ++= "package " ++= pkgName ++= ";\n"
+ }
- val sym = syms match {
- //syms takes the form of (class, object, trait)
- case Array(null, null, traitSym) => // trait
- isTrait = true
- javaCode ++= modifiers(traitSym) ++= "interface "
- traitSym
- case Array(null, objSym, null) => // single object
- isObject = true
- javaCode ++= modifiers(objSym) ++= "final class "
- objSym
- case Array(classSym, null, null) => // single class
- javaCode ++= modifiers(classSym) ++= "class "
- classSym
- case Array(classSym, objSym, null) => // companion object + class
- isCompanion = true
- javaCode ++= modifiers(classSym) ++= "class "
- classSym
- case Array(_, obj, traitSym) => // companion object + trait ?
- isTrait = true
- javaCode ++= modifiers(traitSym) ++= "interface "
- traitSym
- }
+ val sym = syms match {
+ //syms takes the form of (class, object, trait)
+ case Array(null, null, traitSym) => // trait
+ isTrait = true
+ javaCode ++= modifiers(traitSym) ++= "interface "
+ traitSym
+ case Array(null, objSym, null) => // single object
+ isObject = true
+ javaCode ++= modifiers(objSym) ++= "final class "
+ objSym
+ case Array(classSym, null, null) => // single class
+ javaCode ++= modifiers(classSym) ++= "class "
+ classSym
+ case Array(classSym, objSym, null) => // companion object + class
+ isCompanion = true
+ javaCode ++= modifiers(classSym) ++= "class "
+ classSym
+ case Array(_, obj, traitSym) => // companion object + trait ?
+ isTrait = true
+ javaCode ++= modifiers(traitSym) ++= "interface "
+ traitSym
+ }
- // * we get clzName, do not try javaSig, which contains package string
- // * and may be binary name, for example, an object's name will be "object$"
- javaCode ++= clzName
+ // * we get clzName, do not try javaSig, which contains package string
+ // * and may be binary name, for example, an object's name will be "object$"
+ javaCode ++= clzName
- val tpe = tryTpe(sym)
- javaSig(sym, tpe) match {
- case Some(sig) => javaCode ++= getGenericPart(sig)
- case None =>
- }
+ val tpe = tryTpe(sym)
+ javaSig(sym, tpe) match {
+ case Some(sig) => javaCode ++= getGenericPart(sig)
+ case None =>
+ }
- val qName = sym.fullName
+ val qName = sym.fullName
- val superClass = sym.superClass
- val superQName = superClass match {
- case null => ""
- case x => x.fullName
- }
+ val superClass = sym.superClass
+ val superQName = superClass match {
+ case null => ""
+ case x => x.fullName
+ }
- var extended = false
- if (!isTrait && superQName.length > 0) {
- javaCode ++= " extends "
- extended = true
+ var extended = false
+ if (!isTrait && superQName.length > 0) {
+ javaCode ++= " extends "
+ extended = true
- javaSig(superClass, superClass.tpe) match {
- case Some(sig) => javaCode ++= sig
- case None => javaCode ++= encodeQName(superQName)
+ javaSig(superClass, superClass.tpe) match {
+ case Some(sig) => javaCode ++= sig
+ case None => javaCode ++= encodeQName(superQName)
+ }
}
- }
- if (tpe ne null) {
- val itr = tpe.baseClasses.tail.iterator // head is always `java.lang.Object`?
- var implemented = false
- while (itr.hasNext) {
- val base = itr.next
- base.fullName match {
- case `superQName` =>
- case `qName` =>
- case "java.lang.Object" =>
- case "scala.Any" => // javaSig of "scala.Any" will be "java.lang.Object"
- case baseQName =>
- if (base.isTrait) {
- if (isTrait) {
- if (!extended) {
- javaCode ++= " extends "
- extended = true
- } else {
- javaCode ++= ", "
- }
- } else {
- if (!