< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java

Print this page

 165             default:
 166                 return false;
 167         }
 168     }
 169 
 170     /** Is this tree an identifier, possibly qualified by 'this'?
 171      */
 172     public static boolean isIdentOrThisDotIdent(JCTree tree) {
 173         switch (tree.getTag()) {
 174             case PARENS:
 175                 return isIdentOrThisDotIdent(skipParens(tree));
 176             case IDENT:
 177                 return true;
 178             case SELECT:
 179                 return isThisQualifier(((JCFieldAccess)tree).selected);
 180             default:
 181                 return false;
 182         }
 183     }
 184 



































 185     /** Is this a call to super?
 186      */
 187     public static boolean isSuperCall(JCTree tree) {
 188         Name name = calledMethodName(tree);
 189         if (name != null) {
 190             Names names = name.table.names;
 191             return name==names._super;
 192         } else {
 193             return false;
 194         }
 195     }
 196 
 197     public static List<JCVariableDecl> recordFields(JCClassDecl tree) {
 198         return tree.defs.stream()
 199                 .filter(t -> t.hasTag(VARDEF))
 200                 .map(t -> (JCVariableDecl)t)
 201                 .filter(vd -> (vd.getModifiers().flags & (Flags.RECORD)) == RECORD)
 202                 .collect(List.collector());
 203     }
 204 

 165             default:
 166                 return false;
 167         }
 168     }
 169 
 170     /** Is this tree an identifier, possibly qualified by 'this'?
 171      */
 172     public static boolean isIdentOrThisDotIdent(JCTree tree) {
 173         switch (tree.getTag()) {
 174             case PARENS:
 175                 return isIdentOrThisDotIdent(skipParens(tree));
 176             case IDENT:
 177                 return true;
 178             case SELECT:
 179                 return isThisQualifier(((JCFieldAccess)tree).selected);
 180             default:
 181                 return false;
 182         }
 183     }
 184 
 185     /** Check if the given tree is an explicit reference to the 'this' instance of the
 186      *  class currently being compiled. This is true if tree is:
 187      *  - An unqualified 'this' identifier
 188      *  - A 'super' identifier qualified by a class name whose type is 'currentClass' or a supertype
 189      *  - A 'this' identifier qualified by a class name whose type is 'currentClass' or a supertype
 190      *    but also NOT an enclosing outer class of 'currentClass'.
 191      */
 192     public static boolean isExplicitThisReference(Types types, Type.ClassType currentClass, JCTree tree) {
 193         switch (tree.getTag()) {
 194             case PARENS:
 195                 return isExplicitThisReference(types, currentClass, skipParens(tree));
 196             case IDENT: {
 197                 JCIdent ident = (JCIdent)tree;
 198                 Names names = ident.name.table.names;
 199                 return ident.name == names._this || ident.name == names._super;
 200             }
 201             case SELECT: {
 202                 JCFieldAccess select = (JCFieldAccess)tree;
 203                 Type selectedType = types.erasure(select.selected.type);
 204                 if (!selectedType.hasTag(TypeTag.CLASS))
 205                     return false;
 206                 Symbol.ClassSymbol currentClassSym = (Symbol.ClassSymbol)((Type.ClassType)types.erasure(currentClass)).tsym;
 207                 Symbol.ClassSymbol selectedClassSym = (Symbol.ClassSymbol)((Type.ClassType)selectedType).tsym;
 208                 Names names = select.name.table.names;
 209                 return currentClassSym.isSubClass(selectedClassSym, types) &&
 210                         (select.name == names._super ||
 211                                 (select.name == names._this &&
 212                                         (currentClassSym == selectedClassSym ||
 213                                                 !currentClassSym.isEnclosedBy(selectedClassSym))));
 214             }
 215             default:
 216                 return false;
 217         }
 218     }
 219 
 220     /** Is this a call to super?
 221      */
 222     public static boolean isSuperCall(JCTree tree) {
 223         Name name = calledMethodName(tree);
 224         if (name != null) {
 225             Names names = name.table.names;
 226             return name==names._super;
 227         } else {
 228             return false;
 229         }
 230     }
 231 
 232     public static List<JCVariableDecl> recordFields(JCClassDecl tree) {
 233         return tree.defs.stream()
 234                 .filter(t -> t.hasTag(VARDEF))
 235                 .map(t -> (JCVariableDecl)t)
 236                 .filter(vd -> (vd.getModifiers().flags & (Flags.RECORD)) == RECORD)
 237                 .collect(List.collector());
 238     }
 239 
< prev index next >