langtools/src/jdk.jshell/share/classes/jdk/jshell/TreeDissector.java
changeset 37644 33cf53901cac
parent 36160 f42d362d0d17
child 43134 006808ae5f6e
equal deleted inserted replaced
37643:626e07816dce 37644:33cf53901cac
   160             return null;
   160             return null;
   161         }
   161         }
   162         return new Range(start, end);
   162         return new Range(start, end);
   163     }
   163     }
   164 
   164 
   165     Tree firstClassMember() {
   165     MethodTree method(MethodSnippet msn) {
   166         if (targetClass != null) {
   166         if (targetClass == null) {
   167             //TODO: missing classes
   167             return null;
   168             for (Tree mem : targetClass.getMembers()) {
   168         }
   169                 if (mem.getKind() == Tree.Kind.VARIABLE) {
   169         OuterWrap ow = msn.outerWrap();
   170                     return mem;
   170         if (!(ow instanceof OuterSnippetsClassWrap)) {
   171                 }
   171             return null;
   172                 if (mem.getKind() == Tree.Kind.METHOD) {
   172         }
   173                     MethodTree mt = (MethodTree) mem;
   173         int ordinal = ((OuterSnippetsClassWrap) ow).ordinal(msn);
   174                     if (!isDoIt(mt.getName()) && !mt.getName().toString().equals("<init>")) {
   174         if (ordinal < 0) {
       
   175             return null;
       
   176         }
       
   177         int count = 0;
       
   178         String name = msn.name();
       
   179         for (Tree mem : targetClass.getMembers()) {
       
   180             if (mem.getKind() == Tree.Kind.METHOD) {
       
   181                 MethodTree mt = (MethodTree) mem;
       
   182                 if (mt.getName().toString().equals(name)) {
       
   183                     if (count == ordinal) {
   175                         return mt;
   184                         return mt;
   176                     }
   185                     }
       
   186                     ++count;
   177                 }
   187                 }
   178             }
   188             }
   179         }
   189         }
   180         return null;
   190         return null;
   181     }
   191     }
   242             }
   252             }
   243         }
   253         }
   244         return ei;
   254         return ei;
   245     }
   255     }
   246 
   256 
   247     String typeOfMethod() {
   257     String typeOfMethod(MethodSnippet msn) {
   248         Tree unitTree = firstClassMember();
   258         Tree unitTree = method(msn);
   249         if (unitTree instanceof JCMethodDecl) {
   259         if (unitTree instanceof JCMethodDecl) {
   250             JCMethodDecl mtree = (JCMethodDecl) unitTree;
   260             JCMethodDecl mtree = (JCMethodDecl) unitTree;
   251             Type mt = types().erasure(mtree.type);
   261             Type mt = types().erasure(mtree.type);
   252             if (mt instanceof MethodType) {
   262             if (mt instanceof MethodType) {
   253                 return signature(types(), (MethodType) mt);
   263                 return signature(types(), (MethodType) mt);