diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/models/SemanticTokens.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/models/SemanticTokens.scala | 122 |
1 files changed, 62 insertions, 60 deletions
diff --git a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala index e191fc171d..6404a4fa28 100644 --- a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala +++ b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala @@ -6,6 +6,8 @@ package scala.tools.nsc.models +import java.lang.Thread +import java.lang.Character.isJavaIdentifierPart import scala.collection.mutable.{HashMap,HashSet} import scala.tools.nsc.Global import scala.tools.nsc.symtab.{Flags,Names} @@ -173,7 +175,7 @@ class SemanticTokens(val compiler: Global) { else if (term0.isTypeParameter) TPARAM else if (term0.isType ) TPARAM else { - // System.err.println("UNRECOGNIZED SYMBOL: " + term0 + " " + name); + // Console.err.println("UNRECOGNIZED SYMBOL: " + term0 + " " + name); null } } @@ -203,7 +205,7 @@ class SemanticTokens(val compiler: Global) { val pos = eatKeywords(unit.source, tree.pos) if (pos == NoPos) { // inner types. - // System.err.println("NOPOS: " + tree.getClass() + " " + (new Position(unit.source, tree.pos)).dbgString); + // Console.err.println("NOPOS: " + tree.getClass() + " " + (new Position(unit.source, tree.pos)).dbgString); //Thread.dumpStack(); } else buildDef(tree.symbol, eatKeywords(unit.source, tree.pos)); tree match { @@ -221,7 +223,7 @@ class SemanticTokens(val compiler: Global) { { val pos : Int = if (tree.name.toString().equals("<init>")) NoPos else eatKeywords(unit.source, tree.pos); - if (false) System.err.println("VALDEF: tree=" + tree + " sym=" + tree.symbol + " pos0=" + + if (false) Console.err.println("VALDEF: tree=" + tree + " sym=" + tree.symbol + " pos0=" + tree.symbol.pos + " alias=" + tree.symbol.alias + " pos1=" + pos + " pos2=" + tree.pos + " " + unit.source.dbg(tree.pos) + " " + tree.symbol.hasFlag(Flags.SYNTHETIC)); @@ -243,21 +245,21 @@ class SemanticTokens(val compiler: Global) { try { //TPT=scala.Iterator[DocGenerator.this.compiler0.CompilationUnit] 260 class scala.tools.nsc.ast.Trees$TypeTree scala.Iterator[DocGenerator.this.compiler0.CompilationUnit] class scala.tools.nsc.symtab.Types$$anon$5 if (tree.tpt == null || tree.tpt.tpe == null) { - //System.err.println("BAD: " + tree.tpt + " in " + tree); + //Console.err.println("BAD: " + tree.tpt + " in " + tree); } else { - //System.err.println("TPT=" + tree.tpt + " " + tree.tpt.pos + " " + tree.tpt.getClass() + " " + tree.tpt.tpe + " " + tree.tpt.tpe.getClass() + " " + tree.tpt.tpe.getClass().getSuperclass()); + //Console.err.println("TPT=" + tree.tpt + " " + tree.tpt.pos + " " + tree.tpt.getClass() + " " + tree.tpt.tpe + " " + tree.tpt.tpe.getClass() + " " + tree.tpt.tpe.getClass().getSuperclass()); build(tree.tpt); } } catch { case e: Error => - System.err.println("VALDEF: " + tree + " " + tree.tpt + " " + tree.pos + " " + tree.tpt.pos); + Console.err.println("VALDEF: " + tree + " " + tree.tpt + " " + tree.pos + " " + tree.tpt.pos); throw e; } - //System.err.println("RHS: " + tree.rhs + " " + tree.rhs.getClass() + " " + tree.rhs.getClass().getSuperclass()); + //Console.err.println("RHS: " + tree.rhs + " " + tree.rhs.getClass() + " " + tree.rhs.getClass().getSuperclass()); build(tree.rhs); } case tree: PackageDef => - //System.err.println("PACKAGE: " + tree.name); + //Console.err.println("PACKAGE: " + tree.name); if (false) { val pos = eatKeywords(unit.source, tree.pos) if (pos != NoPos) @@ -272,7 +274,7 @@ class SemanticTokens(val compiler: Global) { unit.source.skipWhitespace(arg.pos + ("val ").length()) else if (unit.source.content(arg.pos) == ':') { var posx : Int = arg.pos - while (Character.isWhitespace(unit.source.content(posx - 1))) posx = posx - 1 + while (unit.source.content(posx - 1).isWhitespace) posx = posx - 1 posx - name.length() } else arg.pos buildDef(arg.symbol, pos) @@ -286,99 +288,99 @@ class SemanticTokens(val compiler: Global) { if (clazz == null) Nil else clazz :: classes(clazz.getSuperclass()) if (tree.original == null) { - if (false) System.err.println("NO_ORIGINAL: " + tree + " " + tree.tpe + " " + classes(tree.tpe.getClass())); + if (false) Console.err.println("NO_ORIGINAL: " + tree + " " + tree.tpe + " " + classes(tree.tpe.getClass())); } if (tree.tpe != null) buildT(tree1, tree.tpe); def buildT( tree : Tree, tpe : Type) : Unit = if (tree.pos != NoPos) tpe match { case tpe0 : TypeRef => tree match { case apt : AppliedTypeTree => buildUse(tpe.symbol, apt.tpt.pos, tpe0); - //System.err.println("APT: " + treex + " vs. " + treex.original); - //System.err.println("APT: " + treex.pos + " vs. " + treex.original.pos + " " + unit.source.dbg(treex.original.pos)); - //System.err.println("APT: " + apt.tpt + " sym0=" + apt.tpt.symbol + " sym1=" + tpe0.sym + " apt.args=" + apt.args + " tpe0.args=" + tpe0.args); + //Console.err.println("APT: " + treex + " vs. " + treex.original); + //Console.err.println("APT: " + treex.pos + " vs. " + treex.original.pos + " " + unit.source.dbg(treex.original.pos)); + //Console.err.println("APT: " + apt.tpt + " sym0=" + apt.tpt.symbol + " sym1=" + tpe0.sym + " apt.args=" + apt.args + " tpe0.args=" + tpe0.args); buildTs (apt.args, tpe0.args); case ident : Ident => buildUse(tpe0.sym, ident.pos, tpe0); case select : Select => if (select.symbol == NoSymbol) - if (false) System.err.println("BUILD_SELECT: " + select + " @ " + tpe0 + " SYM=" + select.symbol + " " + unit.source.dbg(select.pos)); + if (false) Console.err.println("BUILD_SELECT: " + select + " @ " + tpe0 + " SYM=" + select.symbol + " " + unit.source.dbg(select.pos)); try { // build(select); buildUse(tpe0.symbol, selectPos(select), tpe0); - //System.err.println("QUALIFIER: " + select.qualifier + " " + unit.source.dbg(select.qualifier.pos) + " " + tpe0.prefix + " " + tpe0.prefix.getClass() + " " + tpe0.prefix.getClass().getSuperclass() +" " + tpe0.prefix.widen + " " + tpe0.prefix.toLongString); + //Console.err.println("QUALIFIER: " + select.qualifier + " " + unit.source.dbg(select.qualifier.pos) + " " + tpe0.prefix + " " + tpe0.prefix.getClass() + " " + tpe0.prefix.getClass().getSuperclass() +" " + tpe0.prefix.widen + " " + tpe0.prefix.toLongString); buildT(select.qualifier, tpe0.prefix); } catch { case e : Error => - System.err.println("BUILD_SELECT: " + select + " @ " + tpe0 + " " + unit.source.dbg(select.pos)); + Console.err.println("BUILD_SELECT: " + select + " @ " + tpe0 + " " + unit.source.dbg(select.pos)); throw e; } case tpt : TypeTree => if (tpt.symbol != null) { - System.err.println("SYM0 " + tpt.symbol + " " + unit.source.dbg(tpt.pos)); + Console.err.println("SYM0 " + tpt.symbol + " " + unit.source.dbg(tpt.pos)); buildUse(tpt.symbol, tpt.pos, tpe0); } else if (tpe0.symbol != null) { - //System.err.println("TYPE_SYM1 " + tpe0.symbol + " " + unit.source.dbg(tpt.pos)); + //Console.err.println("TYPE_SYM1 " + tpe0.symbol + " " + unit.source.dbg(tpt.pos)); buildUse(tpe0.symbol, tpt.pos, tpe0); } else { - System.err.println("UNKNOWN TPT0: " + unit.source.dbg(tpt.pos) + " tpt=" + tpt + " " + tpt.symbol + " tpe0="+ tpe0 + " " + tpe0.symbol + " tpe0.args=" + tpe0.args); + Console.err.println("UNKNOWN TPT0: " + unit.source.dbg(tpt.pos) + " tpt=" + tpt + " " + tpt.symbol + " tpe0="+ tpe0 + " " + tpe0.symbol + " tpe0.args=" + tpe0.args); } case sft : SelectFromTypeTree => build(sft.qualifier); // XXX: broken - if (false) System.err.println("SFTT: " + sft + " sym=" + sft.symbol + " selector=" + sft.selector + " qual=" + sft.qualifier + " qual.sym=" + + if (false) Console.err.println("SFTT: " + sft + " sym=" + sft.symbol + " selector=" + sft.selector + " qual=" + sft.qualifier + " qual.sym=" + sft.qualifier.symbol + " qual.pos=" + unit.source.dbg(sft.qualifier.pos) + " symbol=" + sft.symbol + " type=" + tpe0 + " type.sym=" + tpe0.symbol); - case _ => System.err.println("UNKNOWN TPT2: " + tree + " vs. " + tpe0 + " " + tree.getClass() + " " + unit.source.content(tree.pos)); + case _ => Console.err.println("UNKNOWN TPT2: " + tree + " vs. " + tpe0 + " " + tree.getClass() + " " + unit.source.content(tree.pos)); } case tpe0 : MethodType => tree match { case tpt: TypeTree => if (tpt.original != null) buildT(tpt.original, tpe); else { - System.err.println("UNKNOWN TPT3: " + tree + " vs. " + tpe0 + " " + unit.source.content(tree.pos)); + Console.err.println("UNKNOWN TPT3: " + tree + " vs. " + tpe0 + " " + unit.source.content(tree.pos)); } case ident : Ident => buildT(ident, tpe0.resultType); case select : Select => buildT(select, tpe0.resultType); - case _ => System.err.println("UNKNOWN TPE: " + tree + " vs. " + tpe0 + " " + tree.getClass()); + case _ => Console.err.println("UNKNOWN TPE: " + tree + " vs. " + tpe0 + " " + tree.getClass()); } case tpe0 : RefinedType => tree match { case cpt : CompoundTypeTree => buildTs(cpt.templ.parents, tpe0.parents); case _ : TypeTree => - // System.err.println("UNKNOWN TPE13: " + dbg(tree) + " tpe0=" + tpe0 + " " + tpe0.parents); + // Console.err.println("UNKNOWN TPE13: " + dbg(tree) + " tpe0=" + tpe0 + " " + tpe0.parents); case _ => - if (false) System.err.println("UNKNOWN TPE5: " + dbg(tree) + " tpe0=" + tpe0 + " " + tpe0.parents); + if (false) Console.err.println("UNKNOWN TPE5: " + dbg(tree) + " tpe0=" + tpe0 + " " + tpe0.parents); } case tpe0 : ThisType => tree match { case stt : SingletonTypeTree => stt.ref match { case ths : This => build(ths); - case _ => System.err.println("UNKNOWN TPE11: " + tpe0 + " " + stt + " " + stt.ref + " " + stt.ref.getClass() + " " + unit.source.dbg(tree.pos)); + case _ => Console.err.println("UNKNOWN TPE11: " + tpe0 + " " + stt + " " + stt.ref + " " + stt.ref.getClass() + " " + unit.source.dbg(tree.pos)); } case tt : This => case _ : Ident => case _ : Select => case tt : TypeTree => - if (false) System.err.println("UNKNOWN TPE12: " + tpe0 + " " + tree + " " + tree.getClass() + " " + unit.source.dbg(tree.pos)); + if (false) Console.err.println("UNKNOWN TPE12: " + tpe0 + " " + tree + " " + tree.getClass() + " " + unit.source.dbg(tree.pos)); case _ => - if (false) System.err.println("UNKNOWN TPE10: " + tpe0 + " " + tree + " " + tree.getClass() + " " + unit.source.dbg(tree.pos)); + if (false) Console.err.println("UNKNOWN TPE10: " + tpe0 + " " + tree + " " + tree.getClass() + " " + unit.source.dbg(tree.pos)); } case tpe0 : SingleType => tree match { case ident : Ident => buildUse(tpe0.sym, ident.pos, tpe0); case select : Select => buildUse(tpe0.symbol, selectPos(select), tpe0); - //System.err.println("QUALIFIER-0: " + select.qualifier + " " + unit.source.dbg(select.qualifier.pos) + " " + tpe0.prefix + " " + tpe0.prefix.getClass() + " " + tpe0.prefix.getClass().getSuperclass() +" " + tpe0.prefix.widen + " " + tpe0.prefix.toLongString); + //Console.err.println("QUALIFIER-0: " + select.qualifier + " " + unit.source.dbg(select.qualifier.pos) + " " + tpe0.prefix + " " + tpe0.prefix.getClass() + " " + tpe0.prefix.getClass().getSuperclass() +" " + tpe0.prefix.widen + " " + tpe0.prefix.toLongString); buildT(select.qualifier, tpe0.prefix); case _ => - if (false) System.err.println("UNKNOWN TPE8: " + tree + " " + unit.source.dbg(tree.pos) + " TPE=" + tpe0 + " PRE=" + tpe0.pre + " SYM=" + tpe0.sym); + if (false) Console.err.println("UNKNOWN TPE8: " + tree + " " + unit.source.dbg(tree.pos) + " TPE=" + tpe0 + " PRE=" + tpe0.pre + " SYM=" + tpe0.sym); } case ctype : ConstantType => - if (false) System.err.println("UNKNOWN CONSTANT_TYPE: " + tree + " " + ctype + " " + unit.source.dbg(tree.pos)); + if (false) Console.err.println("UNKNOWN CONSTANT_TYPE: " + tree + " " + ctype + " " + unit.source.dbg(tree.pos)); case ErrorType => case _ => { - if (false) System.err.println("UNKNOWN TPE4: " + tree + " " + tpe + " " + tpe.getClass() + " " + unit.source.dbg(tree.pos)); + if (false) Console.err.println("UNKNOWN TPE4: " + tree + " " + tpe + " " + tpe.getClass() + " " + unit.source.dbg(tree.pos)); } }; def buildTs(trees : List[Tree], types : List[Type]): Unit = if (!trees.isEmpty && !types.isEmpty) { @@ -395,7 +397,7 @@ class SemanticTokens(val compiler: Global) { }; case tree: AbsTypeDef => - //System.err.println("ABS: " + tree.symbol + " " + unit.source.dbg(tree.namePos) + " " + unit.source.dbg(tree.pos)); + //Console.err.println("ABS: " + tree.symbol + " " + unit.source.dbg(tree.namePos) + " " + unit.source.dbg(tree.pos)); buildDef(tree.symbol, tree.namePos) buildDef(tree.symbol, tree.pos) build(tree.lo) @@ -409,32 +411,32 @@ class SemanticTokens(val compiler: Global) { try { build(tree.qualifier) } catch { - case e : Error => System.err.println("SELECTQ: " + tree + " " + tree.qualifier + " " + unit.source.dbg(tree.qualifier.pos)); throw e; + case e : Error => Console.err.println("SELECTQ: " + tree + " " + tree.qualifier + " " + unit.source.dbg(tree.qualifier.pos)); throw e; } try { if (tree.pos >= unit.source.content.length) { - if (false) System.err.println("BAD_SELECT_QUALIFIER " + tree + " @ " + unit.source.dbg(tree.pos)); + if (false) Console.err.println("BAD_SELECT_QUALIFIER " + tree + " @ " + unit.source.dbg(tree.pos)); } else { - //System.err.println("SELECT-0: " + tree.symbol + " " + unit.source.dbg(tree.pos) + " " + (tree.pos - selectPos(tree))); + //Console.err.println("SELECT-0: " + tree.symbol + " " + unit.source.dbg(tree.pos) + " " + (tree.pos - selectPos(tree))); buildUse(tree.symbol, selectPos(tree), tree.tpe); } } catch { - case e : Error => System.err.println("SELECTU: " + tree + " " + tree.symbol + " " + unit.source.dbg(tree.pos)); throw e; + case e : Error => Console.err.println("SELECTU: " + tree + " " + tree.symbol + " " + unit.source.dbg(tree.pos)); throw e; } case tree: TypeApply => - //System.err.println("TYPE_APPLY: " + tree + " " + unit.source.dbg(tree.pos)); + //Console.err.println("TYPE_APPLY: " + tree + " " + unit.source.dbg(tree.pos)); if (!tree.args.isEmpty) { - //System.err.println("ARGS: " + unit.source.dbg(tree.args0.head.pos)); + //Console.err.println("ARGS: " + unit.source.dbg(tree.args0.head.pos)); } build(tree.fun) build(tree.args) case tree: Apply => - //System.err.println("NORM_APPLY: " + tree + " " + unit.source.dbg(tree.pos)); + //Console.err.println("NORM_APPLY: " + tree + " " + unit.source.dbg(tree.pos)); build(tree.fun) build(tree.args) case tree: GenericApply => - //System.err.println("GEN_APPLY: " + tree + " " + unit.source.dbg(tree.pos)); + //Console.err.println("GEN_APPLY: " + tree + " " + unit.source.dbg(tree.pos)); build(tree.fun) build(tree.args) case tree: Typed => @@ -443,8 +445,8 @@ class SemanticTokens(val compiler: Global) { case tree: Block => if (false) { if (!tree.stats.isEmpty) - System.err.println("BLOCKS: " + tree.stats.head + " " + tree.stats.head.getClass()); - System.err.println("BLOCKE: " + tree.expr + " " + tree.expr.getClass()) + Console.err.println("BLOCKS: " + tree.stats.head + " " + tree.stats.head.getClass()); + Console.err.println("BLOCKE: " + tree.expr + " " + tree.expr.getClass()) } build(tree.stats) build(tree.expr) @@ -456,7 +458,7 @@ class SemanticTokens(val compiler: Global) { case tree : Assign => build(tree.lhs); build(tree.rhs); case tree : If => build(tree.cond); build(tree.thenp); build(tree.elsep); case tree : New => - //System.err.println("NEW: " + tree.tpt + " " + tree.tpt.getClass()); + //Console.err.println("NEW: " + tree.tpt + " " + tree.tpt.getClass()); build(tree.tpt); case tree : Match => build(tree.selector); build(tree.cases); case tree : Return => build(tree.expr); @@ -465,11 +467,11 @@ class SemanticTokens(val compiler: Global) { case tree : Try => build(tree.block); build(tree.catches); build(tree.finalizer); case tree : Alternative => build(tree.trees); case tree : This => - //System.err.println("THIS: " + tree.symbol + " " + tree.qual + " " + unit.source.dbg(tree.pos) + " " + tree.tpe); + //Console.err.println("THIS: " + tree.symbol + " " + tree.qual + " " + unit.source.dbg(tree.pos) + " " + tree.tpe); if (tree.symbol != null) buildUse(tree.symbol, tree.pos, tree.tpe); //Thread.dumpStack(); case tree : AliasTypeDef => - //System.err.println("ALIAS: " + tree); + //Console.err.println("ALIAS: " + tree); build(tree.rhs); build(tree.tparams); buildDef(tree.symbol, tree.pos); case tree : DocDef => build(tree.definition); case tree: Import => build(tree.expr) @@ -479,7 +481,7 @@ class SemanticTokens(val compiler: Global) { case tree: Literal => ; case EmptyTree => ; case _ => ; - System.err.println("BAIL: " + unit.source.dbg(tree0.pos) + " " + tree0 + " " + tree0.getClass()); + Console.err.println("BAIL: " + unit.source.dbg(tree0.pos) + " " + tree0 + " " + tree0.getClass()); } } catch { case t: Throwable => @@ -493,7 +495,7 @@ class SemanticTokens(val compiler: Global) { if (term.hasFlag(Flags.ACCESSOR)) buildSym(analyzer.underlying(term), pos, isDef, tpe) else if (pos == NoPos) { - //System.err.println("NOPOS: " + term) + //Console.err.println("NOPOS: " + term) //Thread.dumpStack() } else if (term != NoSymbol) { @@ -504,15 +506,15 @@ class SemanticTokens(val compiler: Global) { if (cs.length + pos > buf.length) return else while (idx < cs.length) { if (buf(pos + idx) != cs(idx)) { - //System.err.println("MISMATCH: " + name + "[" + idx + "] " + unit.source.dbg(pos)); + //Console.err.println("MISMATCH: " + name + "[" + idx + "] " + unit.source.dbg(pos)); //Thread.dumpStack(); return; } else idx = idx + 1; } if (cs.length + pos + 1 < buf.length) { - if (Character.isJavaIdentifierPart(buf(pos + cs.length))) { - //System.err.println("MISMATCH: " + name + "[last] " + unit.source.dbg(pos)); + if (isJavaIdentifierPart(buf(pos + cs.length))) { + //Console.err.println("MISMATCH: " + name + "[last] " + unit.source.dbg(pos)); return; } } @@ -527,7 +529,7 @@ class SemanticTokens(val compiler: Global) { val buf = unit.source.content if (tree.pos >= buf.length) { if (false) { - System.err.println("" + tree + "@" + tree.pos + " not in " + + Console.err.println("" + tree + "@" + tree.pos + " not in " + unit.source.file.name + "[" + buf.length + "]"); Thread.dumpStack() throw new Error() @@ -539,7 +541,7 @@ class SemanticTokens(val compiler: Global) { if (buf(tree.pos) != '.') tree.pos else { def f(x : Int) : Int = { - if (Character.isWhitespace(buf(x))) f(x + 1) + if (buf(x).isWhitespace) f(x + 1) else x } f(tree.pos + 1) @@ -592,10 +594,10 @@ class SemanticTokens(val compiler: Global) { sem.symbol.pos == tok.symbol.pos) return; if (false) { - System.err.println("NOT_GAP: " + sem.symbol + " " + sem.symbol.getClass() + " " + unit.source.dbg(sem.symbol.pos) + " " + sem.symbol.flags); - System.err.println("NOT_GAP: " + tok.symbol + " " + tok.symbol.getClass() + " " + unit.source.dbg(tok.symbol.pos) + " " + tok.symbol.flags); - System.err.println("LIST: " + this); - System.err.println("POS: " + unit.source.dbg(offset)); + Console.err.println("NOT_GAP: " + sem.symbol + " " + sem.symbol.getClass() + " " + unit.source.dbg(sem.symbol.pos) + " " + sem.symbol.flags); + Console.err.println("NOT_GAP: " + tok.symbol + " " + tok.symbol.getClass() + " " + unit.source.dbg(tok.symbol.pos) + " " + tok.symbol.flags); + Console.err.println("LIST: " + this); + Console.err.println("POS: " + unit.source.dbg(offset)); Thread.dumpStack(); throw new Error(); @@ -603,9 +605,9 @@ class SemanticTokens(val compiler: Global) { } else { val gap = cursor.token.asInstanceOf[Gap]; if (!(offset - cursor.offset + tok.length <= gap.length)) { - System.err.println("LIST =" + this); - System.err.println("OFFSET=" + offset + " " + tok + " " + tok.length); - System.err.println(" " + cursor.offset + " " + gap.length); + Console.err.println("LIST =" + this); + Console.err.println("OFFSET=" + offset + " " + tok + " " + tok.length); + Console.err.println(" " + cursor.offset + " " + gap.length); throw new Error(); } if (offset == cursor.offset) { |