1 19 24 25 package org.netbeans.lib.java.parser; 26 27 31 class ASTreeNode extends ASTClass implements ASTreeTypes { 32 33 private int firstToken,lastToken; 34 ASTree subTrees[]; 35 36 ASTreeNode(ASTContext context,int type, ASTree first, ASTree last, ASTree[] sub) { 37 super(context,type); 38 firstToken=first.getFirstToken(); 39 lastToken=last.getLastToken(); 40 subTrees=sub; 41 } 42 43 ASTreeNode(ASTContext context,int type, ASTree first, ASTree last, ASTree sub) { 44 this(context,type,first,last,new ASTree[]{sub}); 45 } 46 47 ASTreeNode(ASTContext context,int type, ASTree token) { 48 super(context,type); 49 subTrees=new ASTree[]{token}; 50 firstToken=token.getFirstToken(); 51 lastToken=token.getLastToken(); 52 } 53 54 ASTreeNode(ASTContext context,int type, ASTree[] sub) { 55 super(context,type); 56 subTrees=sub; 57 computeBounds(); 58 } 59 60 ASTreeNode(ASTContext context,int type, ASTree leftAST, ASTree rightAST) { 61 super(context,type); 62 subTrees=new ASTree[]{leftAST,rightAST}; 63 computeBounds(); 64 } 65 66 private void computeBounds() { 67 int i,j; 68 69 for (i=0;i<subTrees.length;i++) { 70 if (subTrees[i]!=null) { 71 firstToken=subTrees[i].getFirstToken(); 72 break; 73 } 74 } 75 for (j=subTrees.length-1;j>=i;j--) { 76 if (subTrees[j]!=null) { 77 lastToken=subTrees[j].getLastToken(); 78 break; 79 } 80 } 81 } 82 83 final ASTClass setLastToken(ASTree token) { 84 lastToken = token.getLastToken(); 85 return this; 86 } 87 88 final ASTClass setLastToken(int tokenIndex) { 89 lastToken = tokenIndex; 90 return this; 91 } 92 93 96 public final int getLastToken() { 97 return lastToken; 98 } 99 100 final ASTClass setFirstToken(ASTree token) { 101 firstToken = token.getFirstToken(); 102 return this; 103 } 104 105 final ASTClass setFirstToken(int tokenIndex) { 106 firstToken = tokenIndex; 107 return this; 108 } 109 110 public final int getFirstToken() { 111 return firstToken; 112 } 113 114 final ASTClass addSubTree(ASTree sub) { 115 if (subTrees!=null) { 116 int size=subTrees.length; 117 ASTree trees[]=new ASTree[size+1]; 118 119 System.arraycopy(subTrees,0,trees,0,size); 120 trees[size]=sub; 121 subTrees=trees; 122 } else 123 subTrees=new ASTree[]{sub}; 124 if (sub!=null) 125 lastToken=sub.getLastToken(); 126 return this; 127 } 128 129 final ASTClass setFirstAndLastToken(ASTree first, ASTree last) { 130 firstToken = first.getFirstToken(); 131 lastToken=last.getLastToken(); 132 return this; 133 } 134 135 public final String toString() { 136 String text="ASTreeNode Type:"+getType()+"\n{\n"; 137 int i; 138 139 if (subTrees!=null) { 140 for (i=0;i<subTrees.length;i++) { 141 String subText; 142 ASTree t=subTrees[i]; 143 144 if (t!=null) 145 subText=t.toString(); 146 else 147 subText="NULL"; 148 text+=subText+"\n"; 149 } 150 } 151 return text+"}\n"; 152 } 153 154 public final ASTree[] getSubTrees() { 155 return subTrees; 156 } 157 158 } 159 | Popular Tags |