Skip to content

Commit 7b57b6d

Browse files
zbartyzelchangvvb
authored and
changvvb
committed
Improve docs styles
wip wip
1 parent 515cb9f commit 7b57b6d

File tree

14 files changed

+375
-211
lines changed

14 files changed

+375
-211
lines changed

compiler/src/dotty/tools/dotc/core/ContextOps.scala

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Contexts._, Symbols._, Types._, Flags._, Scopes._, Decorators._, NameOps.
55
import Denotations._
66
import SymDenotations.LazyType, Names.Name, StdNames.nme
77
import ast.untpd
8+
import dotty.tools.dotc.core.SymDenotations.NoDenotation
89

910
/** Extension methods for contexts where we want to keep the ctx.<methodName> syntax */
1011
object ContextOps:
@@ -34,14 +35,59 @@ object ContextOps:
3435
if (elem.name == name) return elem.sym.denot // return self
3536
}
3637
val pre = ctx.owner.thisType
37-
pre.findMember(name, pre, required, excluded)
38+
if (ctx.isJava) {
39+
javaFindMember(name, pre, required, excluded)
40+
} else {
41+
pre.findMember(name, pre, required, excluded)
42+
}
3843
}
3944
else // we are in the outermost context belonging to a class; self is invisible here. See inClassContext.
4045
ctx.owner.findMember(name, ctx.owner.thisType, required, excluded)
4146
else
4247
ctx.scope.denotsNamed(name).filterWithFlags(required, excluded).toDenot(NoPrefix)
4348
}
4449

50+
final def javaFindMember(name: Name, pre: Type, required: FlagSet = EmptyFlags, excluded: FlagSet = EmptyFlags): Denotation = {
51+
inContext(ctx) {
52+
val result = {
53+
val preSym = pre.typeSymbol
54+
val denot = pre.findMember(name, pre, required, excluded)
55+
if (denot.exists || preSym.isPackageObject || !preSym.isClass) denot
56+
else {
57+
// In Java code, static innner classes, which we model as members of the companion object,
58+
// can be referenced from an ident in a subclass or by a selection prefixed by the subclass.
59+
val toSearch = if (preSym.is(Flags.Module)) then
60+
if pre.typeSymbol.sourceModule.companionClass.exists then
61+
pre.typeSymbol.sourceModule.companionClass.asClass.baseClasses.tail
62+
else Nil
63+
else
64+
preSym.asClass.baseClasses.tail
65+
66+
val result = toSearch.iterator.map { bc =>
67+
val pre1 = bc.thisType
68+
val found = pre1.findMember(name,pre,required,excluded | Flags.TypeParam)
69+
val result = found match {
70+
case NoDenotation =>
71+
val companionModule = pre1.typeSymbol.companionClass
72+
val pre2 = companionModule.thisType
73+
val result = pre2.findMember(name, pre2, required, excluded)
74+
// println(result.symbol.fullName)
75+
result
76+
case denot => denot
77+
}
78+
// println((bc.show,pre1.show , pre.typeSymbol.show ,result.show))
79+
result
80+
}.find(_.exists).getOrElse(NoDenotation)
81+
result
82+
}
83+
}
84+
// if(name.toSimpleName.toString == "InnerInterface") {
85+
// println((pre.show, result))
86+
// }
87+
result
88+
}
89+
}
90+
4591
/** A fresh local context with given tree and owner.
4692
* Owner might not exist (can happen for self valdefs), in which case
4793
* no owner is set in result context

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2049,7 +2049,12 @@ object SymDenotations {
20492049

20502050
override final def findMember(name: Name, pre: Type, required: FlagSet, excluded: FlagSet)(using Context): Denotation =
20512051
val raw = if excluded.is(Private) then nonPrivateMembersNamed(name) else membersNamed(name)
2052-
raw.filterWithFlags(required, excluded).asSeenFrom(pre).toDenot(pre)
2052+
val result = raw.filterWithFlags(required, excluded).asSeenFrom(pre).toDenot(pre)
2053+
// if(name.toSimpleName.toString == "StaticInner" && this.name.toSimpleName.toString.contains("OuterBase")) {
2054+
// println((this.show, raw, result, required, excluded))
2055+
// }
2056+
result
2057+
20532058

20542059
final def findMemberNoShadowingBasedOnFlags(name: Name, pre: Type,
20552060
required: FlagSet = EmptyFlags, excluded: FlagSet = EmptyFlags)(using Context): Denotation =

compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -901,16 +901,7 @@ object JavaParsers {
901901
members) ++= decls
902902
}
903903
}
904-
def forwarders(sdef: Tree): List[Tree] = sdef match {
905-
case TypeDef(name, _) if (parentToken == INTERFACE) =>
906-
var rhs: Tree = Select(Ident(parentName.toTermName), name)
907-
List(TypeDef(name, rhs).withMods(Modifiers(Flags.Protected)))
908-
case _ =>
909-
List()
910-
}
911-
val sdefs = statics.toList
912-
val idefs = members.toList ::: (sdefs flatMap forwarders)
913-
(sdefs, idefs)
904+
(statics.toList, members.toList)
914905
}
915906
def annotationParents: List[Select] = List(
916907
scalaAnnotationDot(tpnme.Annotation),

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package typer
44

55
import core._
66
import ast._
7-
import Contexts._, Constants._, Types._, Symbols._, Names._, Flags._, Decorators._
7+
import Contexts._, ContextOps._, Constants._, Types._, Symbols._, Names._, Flags._, Decorators._
88
import ErrorReporting._, Annotations._, Denotations._, SymDenotations._, StdNames._
99
import util.Spans._
1010
import util.SrcPos
@@ -145,7 +145,10 @@ trait TypeAssigner {
145145
// this is exactly what Erasure will do.
146146
case _ =>
147147
val pre = maybeSkolemizePrefix(qualType, name)
148-
val mbr = qualType.findMember(name, pre)
148+
var mbr = qualType.findMember(name, pre)
149+
if(!mbr.exists && ctx.isJava && pre.typeSymbol.isClass)
150+
mbr = ctx.javaFindMember(name,pre)
151+
149152
if reallyExists(mbr) then qualType.select(name, mbr)
150153
else if qualType.isErroneous || name.toTermName == nme.ERROR then UnspecifiedErrorType
151154
else NoType

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ class Typer extends Namer
367367
if (qualifies(defDenot)) {
368368
val found =
369369
if (isSelfDenot(defDenot)) curOwner.enclosingClass.thisType
370-
else {
370+
else if(ctx.isJava && defDenot.symbol.isStatic) {
371+
defDenot.symbol.namedType
372+
} else {
371373
val effectiveOwner =
372374
if (curOwner.isTerm && defDenot.symbol.maybeOwner.isType)
373375
// Don't mix NoPrefix and thisType prefixes, since type comparer
@@ -379,6 +381,7 @@ class Typer extends Namer
379381
}
380382
if !curOwner.is(Package) || isDefinedInCurrentUnit(defDenot) then
381383
result = checkNewOrShadowed(found, Definition) // no need to go further out, we found highest prec entry
384+
// println((found.show, defDenot.show, ctx.owner.show))
382385
found match
383386
case found: NamedType if curOwner.isClass && isInherited(found.denot) =>
384387
checkNoOuterDefs(found.denot, ctx, ctx)
@@ -2133,6 +2136,10 @@ class Typer extends Namer
21332136
if (sym.isOneOf(GivenOrImplicit)) checkImplicitConversionDefOK(sym)
21342137
val tpt1 = checkSimpleKinded(typedType(tpt))
21352138

2139+
if(name.toSimpleName.toString == "create") {
2140+
// println((tpt,tpt1.show))
2141+
}
2142+
21362143
val rhsCtx = ctx.fresh
21372144
val tparamss = paramss1.collect {
21382145
case untpd.TypeDefs(tparams) => tparams

0 commit comments

Comments
 (0)