summaryrefslogtreecommitdiff
path: root/sources/scala/tools/scalac/transformer/matching/VariableTraverser.scala
blob: 74d613c66f53fd323e3e11fc11a6f01ea1427efc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import scalac.ast.Tree;
import scalac.util.Name;
import scalac.symtab.Symbol ;
import scalac.ast.Traverser ;

import Tree.Ident;
import Tree.Bind;
import Tree.Select;

package scala.tools.scalac.transformer.matching {

abstract class VariableTraverser extends Traverser {

  def isVariableName(name: Name): Boolean = {
    ( name.isVariable() ) && ( name != Name.fromString("_") ) ;
  }

  def isVariableSymbol(sym: Symbol): Boolean = {
    ( sym != null )&&( !sym.isPrimaryConstructor() );
  }

  def handleVariableSymbol(sym: Symbol): Unit;

  override def traverse(tree: Tree): Unit = {
    tree.match {
      case Ident(name)=>
        var sym: Symbol  = _;

        if( isVariableName( name )
           && isVariableSymbol( {sym = tree.symbol(); tree.symbol()} ) )
          handleVariableSymbol( sym );

        return;

      case Bind(name, subtree) =>
        var sym: Symbol = _;

        if( isVariableName( name )
           && isVariableSymbol( {sym = tree.symbol(); tree.symbol()} ))
          handleVariableSymbol( sym );

        traverse( subtree );

        return;

      case Select(_,_) =>
        return;

      case _ =>
        super.traverse( tree );
    }
  }


}
}