Changeset ca52f554a13ca631512f929d8a0e10ab0cb65831

User picture

Commiter: Mirko Stocker

Author: Mirko Stocker

Parent: 28048e468f

(2012/01/19 08:36) About 1 month ago

Fix compilation errors on 2.10 related to Names.

Affected files

Updated org.scala-refactoring.library/src/main/scala/scala/tools/refactoring/common/PimpedTrees.scala Download diff

28048e468f2f0a7b1479d2975df94b27e284e73eca52f554a13ca631512f929d8a0e10ab0cb65831
92
  }
92
  }
93
  
93
  
94
  def escapeScalaKeywordsForImport(n: String) = {
94
  def escapeScalaKeywordsForImport(n: String) = {
95
    if(global.nme.keywords.contains(n.toTermName) && n.toTermName != nme.USCOREkw) "`"+ n +"`" else n
95
    val name = newTermName(n)
96
    if(global.nme.keywords.contains(name) && name != nme.USCOREkw) "`"+ n +"`" else n
96
  }
97
  }
97
  /**
98
  /**
98
   * Searches for a Symbol of a name in the type members of a tree.
99
   * Searches for a Symbol of a name in the type members of a tree.
...
...
752
    }
753
    }
753
    def errorSubtrees = Nil
754
    def errorSubtrees = Nil
754
  }
755
  }
755
  
756
  object NameTree {
757
    def apply(name: String) = new NameTree(newTermName(name))
758
  }
756
  /**
759
  /**
757
   * Represent a modifier as a tree, including its position.
760
   * Represent a modifier as a tree, including its position.
758
   */
761
   */

Updated org.scala-refactoring.library/src/main/scala/scala/tools/refactoring/implementations/ExplicitGettersSetters.scala Download diff

28048e468f2f0a7b1479d2975df94b27e284e73eca52f554a13ca631512f929d8a0e10ab0cb65831
43
    else
43
    else
44
      Modifiers(Flags.PARAMACCESSOR)
44
      Modifiers(Flags.PARAMACCESSOR)
45
      
45
      
46
    val privateField = selectedValue copy (mods = privateFieldMods, name = privateName)
46
    val privateField = selectedValue copy (mods = privateFieldMods, name = newTermName(privateName))
47
    
47
    
48
    val getter = DefDef(
48
    val getter = DefDef(
49
        mods = Modifiers(Flags.METHOD) withPosition (Flags.METHOD, NoPosition), 
49
        mods = Modifiers(Flags.METHOD) withPosition (Flags.METHOD, NoPosition), 
50
        name = publicName, 
50
        name = newTermName(publicName), 
51
        tparams = Nil, 
51
        tparams = Nil, 
52
        vparamss = Nil, 
52
        vparamss = Nil, 
53
        tpt = EmptyTree, 
53
        tpt = EmptyTree, 
...
...
56
    
56
    
57
    val setter = DefDef(
57
    val setter = DefDef(
58
        mods = Modifiers(Flags.METHOD) withPosition (Flags.METHOD, NoPosition), 
58
        mods = Modifiers(Flags.METHOD) withPosition (Flags.METHOD, NoPosition), 
59
        name = publicName +"_=",
59
        name = newTermName(publicName +"_="),
60
        tparams = Nil,
60
        tparams = Nil,
61
        vparamss = List(List(ValDef(Modifiers(Flags.PARAM), publicName, TypeTree(selectedValue.tpt.tpe), EmptyTree))), 
61
        vparamss = List(List(ValDef(Modifiers(Flags.PARAM), newTermName(publicName), TypeTree(selectedValue.tpt.tpe), EmptyTree))), 
62
        tpt = EmptyTree,
62
        tpt = EmptyTree,
63
        rhs = Block(
63
        rhs = Block(
64
            Assign(
64
            Assign(

Updated org.scala-refactoring.library/src/main/scala/scala/tools/refactoring/transformation/TreeFactory.scala Download diff

28048e468f2f0a7b1479d2975df94b27e284e73eca52f554a13ca631512f929d8a0e10ab0cb65831
16
16
17
  object Invisible extends Position
17
  object Invisible extends Position
18
18
19
  def mkRenamedSymTree(t: SymTree, name: String): SymTree = (t match {
19
  def mkRenamedSymTree(t: SymTree, nameString: String): SymTree = {
20
    case i: Ident => i.copy(name = name)
20
    val name = newTermName(nameString)
21
    case v: ValDef => v.copy(name = name)
21
    t match {
22
    case d: DefDef => d.copy(name = name)
22
      case i: Ident => i.copy(name = name)
23
    case b: Bind => b.copy(name = name)
23
      case v: ValDef => v.copy(name = name)
24
    case s: Select => s.copy(name = name)
24
      case d: DefDef => d.copy(name = name)
25
    case c: ClassDef => c.copy(name = name.toTypeName)
25
      case b: Bind => b.copy(name = name)
26
    case t: This => t.copy(qual = name.toTypeName)
26
      case s: Select => s.copy(name = name)
27
    case m: ModuleDef => m.copy(name = name)
27
      case c: ClassDef => c.copy(name = name.toTypeName)
28
    case t: TypeDef => t.copy(name = name.toTypeName)
28
      case t: This => t.copy(qual = name.toTypeName)
29
    case t: PackageDef => t.copy(pid = Ident(name) setPos t.pid.pos)
29
      case m: ModuleDef => m.copy(name = name)
30
    case t => throw new Exception("Found " + t.getClass.getName)
30
      case t: TypeDef => t.copy(name = name.toTypeName)
31
  }) setPos t.pos
31
      case t: PackageDef => t.copy(pid = Ident(name) setPos t.pid.pos)
32
      case t => throw new Exception("Found " + t.getClass.getName)
33
    }
34
  } setPos t.pos
32
35
33
  def mkRenamedTypeTree(t: TypeTree, name: String, originalSymbol: Symbol) = {
36
  def mkRenamedTypeTree(t: TypeTree, name: String, originalSymbol: Symbol) = {
34
    val newType = t.tpe map {
37
    val newType = t.tpe map {
...
...
50
  
53
  
51
  def mkImportFromStrings(qualifier: String, name: String) = {
54
  def mkImportFromStrings(qualifier: String, name: String) = {
52
    def mapPackageNames(qualifier: String) = {
55
    def mapPackageNames(qualifier: String) = {
53
      qualifier.split("\\.").map(s => escapeScalaKeywordsForImport(s.toTermName)).mkString(".")
56
      newTermName(qualifier.split("\\.").map(s => escapeScalaKeywordsForImport(newTermName(s))).mkString("."))
54
    }
57
    }
55
    
58
    
56
    new Import(Ident(mapPackageNames(qualifier)), new ImportSelector(name, -1, name, -1) :: Nil)
59
    new Import(Ident(mapPackageNames(qualifier)), new ImportSelector(newTermName(name), -1, newTermName(name), -1) :: Nil)
57
  }
60
  }
58
61
59
  def mkRenamedImportTree(t: ImportSelectorTree, name: String) =
62
  def mkRenamedImportTree(t: ImportSelectorTree, name: String) =
...
...
71
74
72
  def mkValDef(name: String, rhs: Tree): ValDef = {
75
  def mkValDef(name: String, rhs: Tree): ValDef = {
73
    
76
    
74
    val valDef = ValDef(NoMods, name, new TypeTree, rhs)
77
    val valDef = ValDef(NoMods, newTermName(name), new TypeTree, rhs)
75
    def valDefForFunction = ValDef(NoMods, name, new TypeTree, Apply(rhs, Ident(nme.USCOREkw) :: Nil))
78
    def valDefForFunction = ValDef(NoMods, newTermName(name), new TypeTree, Apply(rhs, Ident(nme.USCOREkw) :: Nil))
76
    
79
    
77
    rhs match {
80
    rhs match {
78
      case rhs: Select if rhs.symbol.isMethod =>
81
      case rhs: Select if rhs.symbol.isMethod =>
...
...
104
          case xs => "(" + (xs map (_.name) mkString ", ") + ")"
107
          case xs => "(" + (xs map (_.name) mkString ", ") + ")"
105
        }
108
        }
106
109
107
        ValDef(NoMods, valName, new TypeTree(), call)
110
        ValDef(NoMods, newTermName(valName), new TypeTree(), call)
108
    }
111
    }
109
  }
112
  }
110
113
...
...
114
      if (parameters.isEmpty)
117
      if (parameters.isEmpty)
115
        Nil
118
        Nil
116
      else
119
      else
117
        parameters map (_ map (s => new ValDef(Modifiers(Flags.PARAM), s.nameString, TypeTree(s.tpe), EmptyTree)))
120
        parameters map (_ map (s => new ValDef(Modifiers(Flags.PARAM), newTermName(s.nameString), TypeTree(s.tpe), EmptyTree)))
118
    }
121
    }
119
122
120
    DefDef(mods withPosition (Flags.METHOD, NoPosition), name, Nil /*type parameters*/ , formalParameters, TypeTree(body.last.tpe), mkBlock(body))
123
    DefDef(mods withPosition (Flags.METHOD, NoPosition), newTermName(name), Nil /*type parameters*/ , formalParameters, TypeTree(body.last.tpe), mkBlock(body))
121
  }
124
  }
122
125
123
  def mkBlock(trees: List[Tree]): Block = trees match {
126
  def mkBlock(trees: List[Tree]): Block = trees match {
...
...
137
140
138
    val constructorArguments = argss map (_ map {
141
    val constructorArguments = argss map (_ map {
139
      case (mods, name, tpe) =>
142
      case (mods, name, tpe) =>
140
        ValDef(mods | Flags.PARAMACCESSOR, name, tpe, EmptyTree)
143
        ValDef(mods | Flags.PARAMACCESSOR, newTermName(name), tpe, EmptyTree)
141
    })
144
    })
142
145
143
    val constructor = {
146
    val constructor = {
...
...
148
          Apply(EmptyTree, args)
151
          Apply(EmptyTree, args)
149
      }
152
      }
150
153
151
      DefDef(mods withPosition (Flags.METHOD, NoPosition), nme.CONSTRUCTOR.toString, Nil, constructorArguments, TypeTree(NoType), mkBlock(body))
154
      DefDef(mods withPosition (Flags.METHOD, NoPosition), nme.CONSTRUCTOR, Nil, constructorArguments, TypeTree(NoType), mkBlock(body))
152
    }
155
    }
153
156
154
    ClassDef(
157
    ClassDef(
155
      mods,
158
      mods,
156
      name.toTypeName,
159
      newTypeName(name),
157
      tparams,
160
      tparams,
158
      Template(
161
      Template(
159
        parents,
162
        parents,
...
...
240
        // copy the tree and delete all positions so the full path will be written
243
        // copy the tree and delete all positions so the full path will be written
241
        val newExpr = topdown(setNoPosition &> removeThisTrees) apply duplicateTree(expr) getOrElse expr
244
        val newExpr = topdown(setNoPosition &> removeThisTrees) apply duplicateTree(expr) getOrElse expr
242
        val typeName = select.symbol.nameString
245
        val typeName = select.symbol.nameString
243
        Some(Import(newExpr, List(new ImportSelector(if(typeName == name.toString) name else typeName, -1, name, -1))))
246
        Some(Import(newExpr, List(new ImportSelector(if(typeName == name.toString) name else newTypeName(typeName), -1, name, -1))))
244
    }
247
    }
245
  }
248
  }
246
}
249
}

Updated org.scala-refactoring.library/src/test/scala/scala/tools/refactoring/tests/implementations/MarkOccurrencesTest.scala Download diff

28048e468f2f0a7b1479d2975df94b27e284e73eca52f554a13ca631512f929d8a0e10ab0cb65831
302
302
303
  @Test
303
  @Test
304
  def referenceFromInside = markOccurrences("""
304
  def referenceFromInside = markOccurrences("""
305
    package referenceFromInside
305
    class /*(*/Foo/*)*/ {
306
    class /*(*/Foo/*)*/ {
306
      class Bar {
307
      class Bar {
307
        def foo = Foo.this
308
        def foo = Foo.this
...
...
309
    }
310
    }
310
    """,
311
    """,
311
    """
312
    """
313
    package referenceFromInside
312
    class /*(*/###/*)*/ {
314
    class /*(*/###/*)*/ {
313
      class Bar {
315
      class Bar {
314
        def foo = ###.this
316
        def foo = ###.this

Updated org.scala-refactoring.library/src/test/scala/scala/tools/refactoring/tests/implementations/MoveClassTest.scala Download diff

28048e468f2f0a7b1479d2975df94b27e284e73eca52f554a13ca631512f929d8a0e10ab0cb65831
826
  def moveManyClassesAdaptReferences = new FileSet {
826
  def moveManyClassesAdaptReferences = new FileSet {
827
    """
827
    """
828
      package a.b.c
828
      package a.b.c
829
      trait A
829
      trait Aa
830
      trait B
830
      trait Bb
831
      trait C
831
      trait Cc
832
    """ becomes
832
    """ becomes
833
    """
833
    """
834
      package x.y
834
      package x.y
835
      trait A
835
      trait Aa
836
      trait B
836
      trait Bb
837
      trait C
837
      trait Cc
838
    """
838
    """
839
    ;
839
    ;
840
    """
840
    """
...
...
842
842
843
      import a.b.c._
843
      import a.b.c._
844
844
845
      class User(what: ToMove) extends A with B
845
      class User(what: ToMove) extends Aa with Bb
846
    """ becomes
846
    """ becomes
847
    """
847
    """
848
      package different
848
      package different
849
849
850
      import a.b.c._
850
      import a.b.c._
851
      import x.y.A
851
      import x.y.Aa
852
      import x.y.B
852
      import x.y.Bb
853
853
854
      class User(what: ToMove) extends A with B
854
      class User(what: ToMove) extends Aa with Bb
855
    """
855
    """
856
    ;
856
    ;
857
    """
857
    """
858
      package third
858
      package third
859
859
860
      import a.b.c.C
860
      import a.b.c.Cc
861
861
862
      class X extends C with a.b.c.B
862
      class X extends Cc with a.b.c.Bb
863
    """ becomes
863
    """ becomes
864
    """
864
    """
865
      package third
865
      package third
866
866
867
      import x.y.C
867
      import x.y.Cc
868
868
869
      class X extends C with x.y.B
869
      class X extends Cc with x.y.Bb
870
    """
870
    """
871
  } applyRefactoring(moveTo("x.y"))
871
  } applyRefactoring(moveTo("x.y"))
872
}
872
}

Updated org.scala-refactoring.library/src/test/scala/scala/tools/refactoring/tests/implementations/RenameTest.scala Download diff

28048e468f2f0a7b1479d2975df94b27e284e73eca52f554a13ca631512f929d8a0e10ab0cb65831
230
  @Test
230
  @Test
231
  def renameReferenceToOuterclass = new FileSet {
231
  def renameReferenceToOuterclass = new FileSet {
232
    """
232
    """
233
    package renameReferenceToOuterclass
233
    class /*(*/Foo/*)*/ {
234
    class /*(*/Foo/*)*/ {
234
      class Bar {
235
      class Bar {
235
        def foo = Foo.this
236
        def foo = Foo.this
236
      }
237
      }
237
    }""" becomes
238
    }""" becomes
238
    """
239
    """
240
    package renameReferenceToOuterclass
239
    class /*(*/Blubb/*)*/ {
241
    class /*(*/Blubb/*)*/ {
240
      class Bar {
242
      class Bar {
241
        def foo = Blubb.this
243
        def foo = Blubb.this
...
...
977
  @Test
979
  @Test
978
  def renameClassExplicitSelfTypeAnnotation= new FileSet {
980
  def renameClassExplicitSelfTypeAnnotation= new FileSet {
979
    """
981
    """
982
    package renameClassExplicitSelfTypeAnnotation
980
    trait A
983
    trait A
981
    class /*(*/Foo/*)*/ {
984
    class /*(*/Foo/*)*/ {
982
      self: Foo with A=>
985
      self: Foo with A=>
983
    }
986
    }
984
    """ becomes 
987
    """ becomes 
985
    """
988
    """
989
    package renameClassExplicitSelfTypeAnnotation
986
    trait A
990
    trait A
987
    class /*(*/Babar/*)*/ {
991
    class /*(*/Babar/*)*/ {
988
      self: Babar with A=>
992
      self: Babar with A=>

Updated org.scala-refactoring.library/src/test/scala/scala/tools/refactoring/tests/sourcegen/IndividualSourceGenTest.scala Download diff

28048e468f2f0a7b1479d2975df94b27e284e73eca52f554a13ca631512f929d8a0e10ab0cb65831
117
}
117
}
118
"""
118
"""
119
    val ast = treeFrom(src)    
119
    val ast = treeFrom(src)    
120
    val defdef = mkDefDef(name = "member", body = List(Ident("()")))
120
    val defdef = mkDefDef(name = "member", body = List(Ident(newTermName("()"))))
121
    
121
    
122
    val transformedAst = topdown {
122
    val transformedAst = topdown {
123
      matchingChildren {
123
      matchingChildren {
...
...
151
"""
151
"""
152
    val ast = treeFrom(src)
152
    val ast = treeFrom(src)
153
    
153
    
154
    val defdef = mkDefDef(name = "member", body = List(Ident("()")))
154
    val defdef = mkDefDef(name = "member", body = List(Ident(newTermName("()"))))
155
    
155
    
156
    val transformedAst = topdown {
156
    val transformedAst = topdown {
157
      matchingChildren {
157
      matchingChildren {
...
...
245
            val newRhs = Block(
245
            val newRhs = Block(
246
              mkClass(
246
              mkClass(
247
                name = "$anon", 
247
                name = "$anon", 
248
                parents = Ident("A") :: Ident("B") :: Nil,
248
                parents = Ident(newTermName("A")) :: Ident(newTermName("B")) :: Nil,
249
                superArgs = Literal(Constant(5)) :: Nil
249
                superArgs = Literal(Constant(5)) :: Nil
250
              ), 
250
              ), 
251
              Apply(Select(New(Ident("$anon")), nme.CONSTRUCTOR), Nil)
251
              Apply(Select(New(Ident(newTermName("$anon"))), nme.CONSTRUCTOR), Nil)
252
            )
252
            )
253
            
253
            
254
            t.copy(rhs = newRhs)
254
            t.copy(rhs = newRhs)
...
...
288
      case _ => Assert.fail(); Predef.error("") // too bad fail does not return Nothing
288
      case _ => Assert.fail(); Predef.error("") // too bad fail does not return Nothing
289
    }
289
    }
290
    
290
    
291
    val newRHS1 = Apply(Select(Ident("com"),"synchronized"), List(shallowDuplicate(originalDefDef.rhs) setPos NoPosition))
291
    val newRHS1 = Apply(Select(Ident(newTermName("com")),newTermName("synchronized")), List(shallowDuplicate(originalDefDef.rhs) setPos NoPosition))
292
    
292
    
293
    val newDefDef1 = originalDefDef copy (rhs = newRHS1) setPos originalDefDef.pos
293
    val newDefDef1 = originalDefDef copy (rhs = newRHS1) setPos originalDefDef.pos
294
        
294
        
...
...
297
    assertEquals("""
297
    assertEquals("""
298
       def amethod(v: Int, a: Account): Unit = com.synchronized(a.add(v))""", createFragment(removeAuxiliaryTrees apply newDefDef1 get).asText)
298
       def amethod(v: Int, a: Account): Unit = com.synchronized(a.add(v))""", createFragment(removeAuxiliaryTrees apply newDefDef1 get).asText)
299
   
299
   
300
    val newRHS2 = Apply(Select(Ident("com"),"synchronized"), List(originalDefDef.rhs))
300
    val newRHS2 = Apply(Select(Ident(newTermName("com")), newTermName("synchronized")), List(originalDefDef.rhs))
301
    
301
    
302
    val newDefDef2 = originalDefDef copy (rhs = newRHS2) setPos originalDefDef.pos
302
    val newDefDef2 = originalDefDef copy (rhs = newRHS2) setPos originalDefDef.pos
303
        
303
        
...
...
341
      case _ => Assert.fail(); Predef.error("") // too bad fail does not return Nothing
341
      case _ => Assert.fail(); Predef.error("") // too bad fail does not return Nothing
342
    }
342
    }
343
    
343
    
344
    val newRHS1 = new Block(List(Apply(Select(Ident("com"),"synchronized"), List(originalDefDef.rhs))), EmptyTree)
344
    val newRHS1 = new Block(List(Apply(Select(Ident(newTermName("com")),newTermName("synchronized")), List(originalDefDef.rhs))), EmptyTree)
345
    
345
    
346
    val newDefDef1 = originalDefDef copy (rhs = newRHS1) setPos originalDefDef.pos
346
    val newDefDef1 = originalDefDef copy (rhs = newRHS1) setPos originalDefDef.pos
347
    
347
    
...
...
896
        transform {
896
        transform {
897
          case a: Apply if (a.args.length > 1) =>
897
          case a: Apply if (a.args.length > 1) =>
898
            val fun1 = Select(
898
            val fun1 = Select(
899
              name = a.fun.symbol.nameString,
899
              name = newTermName(a.fun.symbol.nameString),
900
              qualifier = a.args.last)
900
              qualifier = a.args.last)
901
            a.copy(args = a.args.init, fun = fun1) replaces a
901
            a.copy(args = a.args.init, fun = fun1) replaces a
902
        }
902
        }
...
...
941
        transform {
941
        transform {
942
          case a: Apply if (a.args.length > 1) =>
942
          case a: Apply if (a.args.length > 1) =>
943
            val fun1 = Select(
943
            val fun1 = Select(
944
              name = a.fun.symbol.nameString,
944
              name = newTermName(a.fun.symbol.nameString),
945
              qualifier = a.args.last)
945
              qualifier = a.args.last)
946
            a.copy(args = a.args.init, fun = fun1) replaces a
946
            a.copy(args = a.args.init, fun = fun1) replaces a
947
        }
947
        }
...
...
1089
            val arg = buf(1)
1089
            val arg = buf(1)
1090
            buf.remove(1)
1090
            buf.remove(1)
1091
            val fun1 = Select(
1091
            val fun1 = Select(
1092
              name = a.fun.symbol.nameString,
1092
              name = newTermName(a.fun.symbol.nameString),
1093
              qualifier = arg)
1093
              qualifier = arg)
1094
            a.copy(args = buf.toList, fun = fun1) setPos a.pos
1094
            a.copy(args = buf.toList, fun = fun1) setPos a.pos
1095
        }
1095
        }
...
...
1413
            val arg = buf(1)
1413
            val arg = buf(1)
1414
            buf.remove(1)
1414
            buf.remove(1)
1415
            val fun1 = Select(
1415
            val fun1 = Select(
1416
              name = a.fun.symbol.nameString,
1416
              name = newTermName(a.fun.symbol.nameString),
1417
              qualifier = arg)
1417
              qualifier = arg)
1418
            a.copy(args = buf.toList, fun = fun1) setPos a.pos
1418
            a.copy(args = buf.toList, fun = fun1) setPos a.pos
1419
        }
1419
        }
...
...
1449
            val arg = buf(1)
1449
            val arg = buf(1)
1450
            buf.remove(1)
1450
            buf.remove(1)
1451
            val fun1 = Select(
1451
            val fun1 = Select(
1452
              name = a.fun.symbol.nameString,
1452
              name = newTermName(a.fun.symbol.nameString),
1453
              qualifier = arg)
1453
              qualifier = arg)
1454
            a.copy(args = buf.toList, fun = fun1) setPos a.pos
1454
            a.copy(args = buf.toList, fun = fun1) setPos a.pos
1455
        case a: Function =>
1455
        case a: Function =>
...
...
1496
      .impl.body(2).asInstanceOf[DefDef]
1496
      .impl.body(2).asInstanceOf[DefDef]
1497
    
1497
    
1498
    def mkPattern(varName: String, className: String, guard: Tree, rhs: Tree): CaseDef = {
1498
    def mkPattern(varName: String, className: String, guard: Tree, rhs: Tree): CaseDef = {
1499
      CaseDef(Bind("t",
1499
      CaseDef(Bind(newTermName("t"),
1500
        if (className != "") Typed(Ident(""), Ident(className))
1500
        if (className != "") Typed(Ident(newTermName("")), Ident(newTermName(className)))
1501
        else EmptyTree),
1501
        else EmptyTree),
1502
        guard, rhs)
1502
        guard, rhs)
1503
    }
1503
    }
...
...
1555
      .impl.body(4).asInstanceOf[DefDef]
1555
      .impl.body(4).asInstanceOf[DefDef]
1556
1556
1557
    def mkPattern(varName: String, className: String, guard: Tree, rhs: Tree): CaseDef = {
1557
    def mkPattern(varName: String, className: String, guard: Tree, rhs: Tree): CaseDef = {
1558
      CaseDef(Bind("t",
1558
      CaseDef(Bind(newTermName("t"),
1559
        if (className != "") Typed(Ident(""), Ident(className))
1559
        if (className != "") Typed(Ident(newTermName("")), Ident(newTermName(className)))
1560
        else EmptyTree),
1560
        else EmptyTree),
1561
        guard, rhs)
1561
        guard, rhs)
1562
    }
1562
    }
...
...
1567
          case t: DefDef if(t.name.toString() == "acmatch_expr")=>
1567
          case t: DefDef if(t.name.toString() == "acmatch_expr")=>
1568
            val rhs = toInline.rhs.asInstanceOf[If]
1568
            val rhs = toInline.rhs.asInstanceOf[If]
1569
            val caseDef = mkPattern("", "ASD", EmptyTree, rhs.copy())
1569
            val caseDef = mkPattern("", "ASD", EmptyTree, rhs.copy())
1570
            val matchx = Match(Ident("x"), List(caseDef))
1570
            val matchx = Match(Ident(newTermName("x")), List(caseDef))
1571
            t.copy(rhs = matchx) replaces t
1571
            t.copy(rhs = matchx) replaces t
1572
        }
1572
        }
1573
      }
1573
      }
...
...
1633
      .impl.body(3).asInstanceOf[DefDef]
1633
      .impl.body(3).asInstanceOf[DefDef]
1634
1634
1635
    def mkPattern(varName: String, className: String, guard: Tree, rhs: Tree): CaseDef = {
1635
    def mkPattern(varName: String, className: String, guard: Tree, rhs: Tree): CaseDef = {
1636
      CaseDef(Bind("t",
1636
      CaseDef(Bind(newTermName("t"),
1637
        if (className != "") Typed(Ident(""), Ident(className))
1637
        if (className != "") Typed(Ident(newTermName("")), Ident(newTermName(className)))
1638
        else EmptyTree),
1638
        else EmptyTree),
1639
        guard, rhs)
1639
        guard, rhs)
1640
    }
1640
    }
...
...
1645
          case t: DefDef if (t.name.toString() == "subst_expr") =>
1645
          case t: DefDef if (t.name.toString() == "subst_expr") =>
1646
            val rhs = toInline.rhs.asInstanceOf[Apply]
1646
            val rhs = toInline.rhs.asInstanceOf[Apply]
1647
            val caseDef = mkPattern("", "Until", EmptyTree, rhs.copy())
1647
            val caseDef = mkPattern("", "Until", EmptyTree, rhs.copy())
1648
            val matchx = Match(Ident("obj"), List(caseDef))
1648
            val matchx = Match(Ident(newTermName("obj")), List(caseDef))
1649
            t.copy(rhs = matchx) setPos t.pos
1649
            t.copy(rhs = matchx) setPos t.pos
1650
        }
1650
        }
1651
      }
1651
      }
...
...
1703
      .impl.body(3).asInstanceOf[DefDef]
1703
      .impl.body(3).asInstanceOf[DefDef]
1704
1704
1705
    def mkPattern(varName: String, className: String, guard: Tree, rhs: Tree): CaseDef = {
1705
    def mkPattern(varName: String, className: String, guard: Tree, rhs: Tree): CaseDef = {
1706
      CaseDef(Bind("t",
1706
      CaseDef(Bind(newTermName("t"),
1707
        if (className != "") Typed(Ident(""), Ident(className))
1707
        if (className != "") Typed(Ident(newTermName("")), Ident(newTermName(className)))
1708
        else EmptyTree),
1708
        else EmptyTree),
1709
        guard, rhs)
1709
        guard, rhs)
1710
    }
1710
    }
...
...
1715
          case t: DefDef if (t.name.toString() == "subst_expr") =>
1715
          case t: DefDef if (t.name.toString() == "subst_expr") =>
1716
            val rhs = toInline.rhs.asInstanceOf[Function]
1716
            val rhs = toInline.rhs.asInstanceOf[Function]
1717
            val caseDef = mkPattern("", "Abstractionmv", EmptyTree, rhs.copy())
1717
            val caseDef = mkPattern("", "Abstractionmv", EmptyTree, rhs.copy())
1718
            val matchx = Match(Ident("obj"), List(caseDef))
1718
            val matchx = Match(Ident(newTermName("obj")), List(caseDef))
1719
            t.copy(rhs = matchx) setPos t.pos
1719
            t.copy(rhs = matchx) setPos t.pos
1720
        }
1720
        }
1721
      }
1721
      }
...
...
1768
            val arg = buf(0)
1768
            val arg = buf(0)
1769
            buf.remove(0)
1769
            buf.remove(0)
1770
            val fun1 = Select(
1770
            val fun1 = Select(
1771
              name = a.fun.symbol.nameString,
1771
              name = newTermName(a.fun.symbol.nameString),
1772
              qualifier = arg)
1772
              qualifier = arg)
1773
            a.copy(args = buf.toList, fun = fun1) setPos a.pos
1773
            a.copy(args = buf.toList, fun = fun1) setPos a.pos
1774
        }
1774
        }
...
...
1810
            val arg = buf(1)
1810
            val arg = buf(1)
1811
            buf.remove(1)
1811
            buf.remove(1)
1812
            val fun1 = Select(
1812
            val fun1 = Select(
1813
              name = a.fun.symbol.nameString,
1813
              name = newTermName(a.fun.symbol.nameString),
1814
              qualifier = arg)
1814
              qualifier = arg)
1815
            a.copy(args = buf.toList, fun = fun1) setPos a.pos
1815
            a.copy(args = buf.toList, fun = fun1) setPos a.pos
1816
        }
1816
        }

Updated org.scala-refactoring.library/src/test/scala/scala/tools/refactoring/tests/sourcegen/PrettyPrinterTest.scala Download diff

28048e468f2f0a7b1479d2975df94b27e284e73eca52f554a13ca631512f929d8a0e10ab0cb65831
56
 * Bla bla
56
 * Bla bla
57
 * /
57
 * /
58
"""
58
"""
59
    val method = DocDef(DocComment(doc, NoPosition),mkDefDef(name = "meth", body = DocDef(DocComment("/** Kuuka */", NoPosition), EmptyTree) :: Ident("()") :: Nil))
59
    val method = DocDef(DocComment(doc, NoPosition),mkDefDef(name = "meth", body = DocDef(DocComment("/** Kuuka */", NoPosition), EmptyTree) :: Ident(newTermName("()")) :: Nil))
60
        
60
        
61
    val tree = mkCaseClass(
61
    val tree = mkCaseClass(
62
        name = "A",
62
        name = "A",
...
...
82
  
82
  
83
  @Test
83
  @Test
84
  def testCaseClassTwoArgLists() {
84
  def testCaseClassTwoArgLists() {
85
    val argsList1 = (NoMods, "r1", Ident("Rate")) :: Nil
85
    val argsList1 = (NoMods, "r1", Ident(newTermName("Rate"))) :: Nil
86
    val argsList2 = (NoMods, "r2", Ident("Rate")) :: (NoMods, "r3", Ident("Rate")) :: Nil
86
    val argsList2 = (NoMods, "r2", Ident(newTermName("Rate"))) :: (NoMods, "r3", Ident(newTermName("Rate"))) :: Nil
87
        
87
        
88
    mkCaseClass(name = "A", argss = List(argsList1, argsList2)) prettyPrintsTo "case class A(r1: Rate)(r2: Rate, r3: Rate)"
88
    mkCaseClass(name = "A", argss = List(argsList1, argsList2)) prettyPrintsTo "case class A(r1: Rate)(r2: Rate, r3: Rate)"
89
  }
89
  }
...
...
97
  def testCaseClassOneArg() = {
97
  def testCaseClassOneArg() = {
98
    mkCaseClass(
98
    mkCaseClass(
99
        name = "A", 
99
        name = "A", 
100
        argss = ((NoMods, "rate", Ident("Rate")) :: Nil) :: Nil) prettyPrintsTo "case class A(rate: Rate)"
100
        argss = ((NoMods, "rate", Ident(newTermName("Rate"))) :: Nil) :: Nil) prettyPrintsTo "case class A(rate: Rate)"
101
  }
101
  }
102
102
103
  @Test
103
  @Test
104
  def testCaseClassTwoArgs() = {
104
  def testCaseClassTwoArgs() = {
105
    mkCaseClass(
105
    mkCaseClass(
106
        name = "A", 
106
        name = "A", 
107
        argss = List(List((NoMods, "x", Ident("Int")), (NoMods, "y", Ident("String"))))) prettyPrintsTo "case class A(x: Int, y: String)"
107
        argss = List(List((NoMods, "x", Ident(newTermName("Int"))), (NoMods, "y", Ident(newTermName("String")))))) prettyPrintsTo "case class A(x: Int, y: String)"
108
  }
108
  }
109
109
110
  @Test
110
  @Test
111
  def testClassTwoArgs() = {
111
  def testClassTwoArgs() = {
112
    mkClass(
112
    mkClass(
113
        name = "A", 
113
        name = "A", 
114
        argss = List(List((NoMods, "x", Ident("Int")), (NoMods, "y", Ident("String"))))) prettyPrintsTo "class A(x: Int, y: String)"
114
        argss = List(List((NoMods, "x", Ident(newTermName("Int"))), (NoMods, "y", Ident(newTermName("String")))))) prettyPrintsTo "class A(x: Int, y: String)"
115
  }
115
  }
116
116
117
  @Test
117
  @Test
118
  def testClassTwoValVarArgs() = {
118
  def testClassTwoValVarArgs() = {
119
    mkClass(
119
    mkClass(
120
        name = "A", 
120
        name = "A", 
121
        argss = List(List((NoMods withPosition (Tokens.VAL, NoPosition), "x", Ident("Int")), (NoMods withPosition (Tokens.VAR, NoPosition), "y", Ident("String"))))) prettyPrintsTo "class A(val x: Int, var y: String)"
121
        argss = List(List((NoMods withPosition (Tokens.VAL, NoPosition), "x", Ident(newTermName("Int"))), (NoMods withPosition (Tokens.VAR, NoPosition), "y", Ident(newTermName("String")))))) prettyPrintsTo "class A(val x: Int, var y: String)"
122
  }
122
  }
123
  
123
  
124
  @Test
124
  @Test
...
...
126
    
126
    
127
    val tree = mkCaseClass(
127
    val tree = mkCaseClass(
128
        name = "A", 
128
        name = "A", 
129
        argss = ((NoMods, "x", Ident("Int")) :: Nil) :: Nil, 
129
        argss = ((NoMods, "x", Ident(newTermName("Int"))) :: Nil) :: Nil, 
130
        parents = Ident("X") :: Ident("Y") :: Nil)
130
        parents = Ident(newTermName("X")) :: Ident(newTermName("Y")) :: Nil)
131
    
131
    
132
    tree prettyPrintsTo "case class A(x: Int) extends X with Y"
132
    tree prettyPrintsTo "case class A(x: Int) extends X with Y"
133
  }
133
  }
...
...
137
    
137
    
138
    val tree = mkCaseClass(
138
    val tree = mkCaseClass(
139
        name = "A", 
139
        name = "A", 
140
        argss = ((NoMods, "x", Ident("Int")) :: Nil) :: Nil, 
140
        argss = ((NoMods, "x", Ident(newTermName("Int"))) :: Nil) :: Nil, 
141
        parents = Ident("X") :: Nil,
141
        parents = Ident(newTermName("X")) :: Nil,
142
        superArgs = Ident("x") :: Nil)
142
        superArgs = Ident(newTermName("x")) :: Nil)
143
    
143
    
144
    tree prettyPrintsTo "case class A(x: Int) extends X(x)"
144
    tree prettyPrintsTo "case class A(x: Int) extends X(x)"
145
  }
145
  }
...
...
178
          NoMods withPosition (Flags.IMPLICIT, NoPosition) withPosition (Flags.METHOD, NoPosition) ,
178
          NoMods withPosition (Flags.IMPLICIT, NoPosition) withPosition (Flags.METHOD, NoPosition) ,
179
          "eins",
179
          "eins",
180
          Nil,
180
          Nil,
181
          List(List(ValDef(NoMods withPosition (Flags.IMPLICIT, NoPosition), "a", EmptyTree, EmptyTree))),
181
          List(List(ValDef(NoMods withPosition (Flags.IMPLICIT, NoPosition), newTermName("a"), EmptyTree, EmptyTree))),
182
          EmptyTree,
182
          EmptyTree,
183
          Literal(Constant(()))
183
          Literal(Constant(()))
184
        )
184
        )
...
...
189
  @Test
189
  @Test
190
  def testDefDefWithTypeParams =  {
190
  def testDefDefWithTypeParams =  {
191
    
191
    
192
    val arg = ValDef(NoMods withPosition (Flags.IMPLICIT, NoPosition), "a", 
192
    val arg = ValDef(NoMods withPosition (Flags.IMPLICIT, NoPosition), newTermName("a"), 
193
                TypeDef(NoMods, "R".toTypeName, TypeDef(NoMods, "X".toTypeName, Nil, EmptyTree) :: Nil, EmptyTree), EmptyTree)
193
                TypeDef(NoMods, newTypeName("R"), TypeDef(NoMods, newTypeName("X"), Nil, EmptyTree) :: Nil, EmptyTree), EmptyTree)
194
    
194
    
195
    val tree = DefDef(
195
    val tree = DefDef(
196
          NoMods withPosition (Flags.METHOD, NoPosition) ,
196
          NoMods withPosition (Flags.METHOD, NoPosition) ,
197
          "m",
197
          "m",
198
          TypeDef(NoMods, "X".toTypeName, Nil, EmptyTree) :: Nil,
198
          TypeDef(NoMods, newTypeName("X"), Nil, EmptyTree) :: Nil,
199
          List(List(arg)),
199
          List(List(arg)),
200
          EmptyTree,
200
          EmptyTree,
201
          Literal(Constant(()))
201
          Literal(Constant(()))
...
...
209
209
210
    val doc = DocDef(DocComment("/** Kuuka */", NoPosition), EmptyTree)
210
    val doc = DocDef(DocComment("/** Kuuka */", NoPosition), EmptyTree)
211
    
211
    
212
    val tree = mkDefDef(name = "meth", body = doc :: Ident("()") :: Nil)
212
    val tree = mkDefDef(name = "meth", body = doc :: Ident(newTermName("()")) :: Nil)
213
    
213
    
214
    tree prettyPrintsTo """def meth() = {
214
    tree prettyPrintsTo """def meth() = {
215
  /** Kuuka */
215
  /** Kuuka */
...
...
219
  
219
  
220
  @Test
220
  @Test
221
  def testApplyHasParens() = {
221
  def testApplyHasParens() = {
222
    Apply(Ident( "aa" ), Nil) prettyPrintsTo """aa()"""
222
    Apply(Ident(newTermName("aa")), Nil) prettyPrintsTo """aa()"""
223
  }
223
  }
224
  
224
  
225
  @Test
225
  @Test
226
  def testApplyTypesToClass() = {
226
  def testApplyTypesToClass() = {
227
    TypeApply(Ident("MyClass"), Ident("A") :: Ident("B") :: Nil) prettyPrintsTo """MyClass[A, B]"""
227
    TypeApply(Ident(newTermName("MyClass")), Ident(newTermName("A")) :: Ident(newTermName("B")) :: Nil) prettyPrintsTo """MyClass[A, B]"""
228
  }
228
  }
229
  
229
  
230
  @Test
230
  @Test
231
  def testClassWithTypeParams() = {
231
  def testClassWithTypeParams() = {
232
    val c = mkClass(name = "A", tparams = List(TypeDef(NoMods, "T".toTypeName, Nil, EmptyTree), TypeDef(NoMods, "U".toTypeName, Nil, EmptyTree)))
232
    val c = mkClass(name = "A", tparams = List(TypeDef(NoMods, newTypeName("T"), Nil, EmptyTree), TypeDef(NoMods, newTypeName("U"), Nil, EmptyTree)))
233
    c prettyPrintsTo """class A[T, U]"""
233
    c prettyPrintsTo """class A[T, U]"""
234
  }
234
  }
235
  
235
  
236
  @Test
236
  @Test
237
  def testFloatLiteralFromIdent() = {
237
  def testFloatLiteralFromIdent() = {
238
   Ident( "33.3f") prettyPrintsTo """33.3f"""
238
   Ident(newTermName("33.3f")) prettyPrintsTo """33.3f"""
239
  }
239
  }
240
  
240
  
241
  @Test
241
  @Test
...
...
252
    val tree = DefDef(
252
    val tree = DefDef(
253
          NoMods withPosition (Flags.METHOD, NoPosition),
253
          NoMods withPosition (Flags.METHOD, NoPosition),
254
          "eins",
254
          "eins",
255
          TypeDef( NoMods, "R".toTypeName, Nil, TypeBoundsTree( EmptyTree, TypeDef( NoMods, "Rate".toTypeName, Nil, EmptyTree ))) :: Nil,
255
          TypeDef( NoMods, newTypeName("R"), Nil, TypeBoundsTree( EmptyTree, TypeDef( NoMods, newTypeName("Rate"), Nil, EmptyTree ))) :: Nil,
256
          Nil,
256
          Nil,
257
          EmptyTree,
257
          EmptyTree,
258
          Literal(Constant(()))
258
          Literal(Constant(()))

Updated org.scala-refactoring.library/src/test/scala/scala/tools/refactoring/tests/util/TestHelper.scala Download diff

28048e468f2f0a7b1479d2975df94b27e284e73eca52f554a13ca631512f929d8a0e10ab0cb65831
23
  type SilentTracing = common.SilentTracing
23
  type SilentTracing = common.SilentTracing
24
  type GlobalIndexes = analysis.GlobalIndexes
24
  type GlobalIndexes = analysis.GlobalIndexes
25
  type ScalaVersion = tests.util.ScalaVersion
25
  type ScalaVersion = tests.util.ScalaVersion
26
27
  implicit def stringToName(name: String): global.Name = global.newTermName(name)
26
    
28
    
27
  /**
29
  /**
28
   * A project to test multiple compilation units. Add all 
30
   * A project to test multiple compilation units. Add all