@@ -117,11 +117,8 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
117
117
atPos(pkg.pos) { PackageDef (pkg, stats) }
118
118
119
119
def makeTemplate (parents : List [Tree ], stats : List [Tree ]) =
120
- Template (
121
- parents,
122
- noSelfType,
123
- if (treeInfo.firstConstructor(stats) == EmptyTree ) makeConstructor(List ()) :: stats
124
- else stats)
120
+ Template (parents, noSelfType, if (treeInfo.firstConstructor(stats) == EmptyTree )
121
+ makeConstructor(Nil ) :: stats else stats)
125
122
126
123
def makeSyntheticParam (count : Int , tpt : Tree ): ValDef =
127
124
makeParam(nme.syntheticParamName(count), tpt)
@@ -586,7 +583,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
586
583
case CLASS | ENUM | INTERFACE | AT =>
587
584
typeDecl(if (definesInterface(parentToken)) mods | Flags .STATIC else mods)
588
585
case _ =>
589
- joinComment( termDecl(mods, parentToken) )
586
+ termDecl(mods, parentToken)
590
587
}
591
588
592
589
def makeCompanionObject (cdef : ClassDef , statics : List [Tree ]): Tree =
@@ -600,26 +597,8 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
600
597
Import (Ident (cdef.name.toTermName), ImportSelector .wildList)
601
598
}
602
599
603
- // Importing the companion object members cannot be done uncritically: see
604
- // ticket #2377 wherein a class contains two static inner classes, each of which
605
- // has a static inner class called "Builder" - this results in an ambiguity error
606
- // when each performs the import in the enclosing class's scope.
607
- //
608
- // To address this I moved the import Companion._ inside the class, as the first
609
- // statement. This should work without compromising the enclosing scope, but may (?)
610
- // end up suffering from the same issues it does in scala - specifically that this
611
- // leaves auxiliary constructors unable to access members of the companion object
612
- // as unqualified identifiers.
613
- def addCompanionObject (statics : List [Tree ], cdef : ClassDef ): List [Tree ] = {
614
- def implWithImport (importStmt : Tree ) = deriveTemplate(cdef.impl)(importStmt :: _)
615
- // if there are no statics we can use the original cdef, but we always
616
- // create the companion so import A._ is not an error (see ticket #1700)
617
- val cdefNew =
618
- if (statics.isEmpty) cdef
619
- else deriveClassDef(cdef)(_ => implWithImport(importCompanionObject(cdef)))
620
-
621
- List (makeCompanionObject(cdefNew, statics), cdefNew)
622
- }
600
+ def addCompanionObject (statics : List [Tree ], cdef : ClassDef ): List [Tree ] =
601
+ List (makeCompanionObject(cdef, statics), cdef)
623
602
624
603
def importDecl (): List [Tree ] = {
625
604
accept(IMPORT )
@@ -726,8 +705,15 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
726
705
in.nextToken()
727
706
} else {
728
707
if (in.token == ENUM || definesInterface(in.token)) mods |= Flags .STATIC
729
- val decls = memberDecl(mods, parentToken)
730
- (if (mods.hasStaticFlag || inInterface && ! (decls exists (_.isInstanceOf [DefDef ])))
708
+ val decls = joinComment(memberDecl(mods, parentToken))
709
+
710
+ def isDefDef (tree : Tree ): Boolean = tree match {
711
+ case _ : DefDef => true
712
+ case DocDef (_, defn) => isDefDef(defn)
713
+ case _ => false
714
+ }
715
+
716
+ (if (mods.hasStaticFlag || inInterface && ! (decls exists isDefDef))
731
717
statics
732
718
else
733
719
members) ++= decls
0 commit comments