implemented PCLOC annotation.
[IRC.git] / Robust / src / IR / NameDescriptor.java
1 package IR;
2
3 public class NameDescriptor extends Descriptor {
4   String identifier;
5   NameDescriptor nd;
6   public NameDescriptor(NameDescriptor nd, String id) {
7     super(nd.toString()+"."+id);
8     identifier=getPathFromRootToHere(id);
9     this.nd=nd;
10   }
11
12   public NameDescriptor(String id) {
13     super(id);
14     identifier=getPathFromRootToHere(id);
15     nd=null;
16   }
17
18   public String getIdentifier() {
19     return identifier;
20   }
21
22   public NameDescriptor getBase() {
23     return nd;
24   }
25
26   public String getRoot() {
27     if (nd==null)
28       return identifier;
29     else
30       return nd.getRoot();
31   }
32
33   public String getPathFromRootToHere() {
34     return getPathFromRootToHere(identifier);
35   }
36
37   public String getPathFromRootToHere(String id) {
38     String path = id;
39     NameDescriptor temp = this.nd;
40     while(temp!=null) {
41       path =  temp.identifier + "." + path;
42       temp = temp.nd;
43     }
44
45     return path;
46   }
47
48   public String toString() {
49     if (nd==null)
50       return identifier;
51     else
52       return nd+"."+identifier;
53   }
54 }