private void propogateLVTs()

in src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarDefinitionHelper.java [813:914]


  private void propogateLVTs(Statement stat) {
    MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor());
    Map<VarVersion, VarInfo> types = new LinkedHashMap<>();

    if (varproc.hasLVT()) {
      int index = 0;
      if (!mt.hasModifier(CodeConstants.ACC_STATIC)) {
        List<LocalVariable> lvt = varproc.getCandidates(index); // Some enums give incomplete lvts?
        if (lvt != null && !lvt.isEmpty()) {
          types.put(new VarVersion(index, 0), new VarInfo(lvt.get(0), null));
        }
        index++;
      }

      for (VarType var : md.params) {
        List<LocalVariable> lvt = varproc.getCandidates(index); // Some enums give incomplete lvts?
        if (lvt != null && !lvt.isEmpty()) {
          types.put(new VarVersion(index, 0), new VarInfo(lvt.get(0), null));
        }
        index += var.getStackSize();
      }
    }

    findTypes(stat, types);

    Map<VarVersion,String> typeNames = new LinkedHashMap<>();
    for (Entry<VarVersion, VarInfo> e : types.entrySet()) {
      typeNames.put(e.getKey(), e.getValue().getCast());
    }


    Map<VarVersion, String> renames = this.mt.getVariableNamer().rename(typeNames);

    // Stuff the parent context into enclosed child methods
    StatementIterator.iterate(root, (exprent) -> {
      List<StructMethod> methods = new ArrayList<>();
      if (exprent.type == Exprent.EXPRENT_VAR) {
        VarExprent var = (VarExprent)exprent;
        if (var.isClassDef()) {
          ClassesProcessor.ClassNode child = DecompilerContext.getClassProcessor().getMapRootClasses().get(var.getVarType().getValue());
          if (child != null)
            methods.addAll(child.classStruct.getMethods());
        }
      }
      else if (exprent.type == Exprent.EXPRENT_NEW) {
        NewExprent _new = (NewExprent)exprent;
        if (_new.isAnonymous()) { //TODO: Check for Lambda here?
          ClassesProcessor.ClassNode child = DecompilerContext.getClassProcessor().getMapRootClasses().get(_new.getNewType().getValue());
          if (child != null) {
            if (_new.isLambda()) {
              if (!child.lambdaInformation.is_method_reference) {
                methods.add(child.classStruct.getMethod(child.lambdaInformation.content_method_name, child.lambdaInformation.content_method_descriptor));
              }
            } else {
              methods.addAll(child.classStruct.getMethods());
            }
          }
        }
      }

      for (StructMethod meth : methods) {
        meth.getVariableNamer().addParentContext(this.mt.getVariableNamer());
      }
      return 0;
    });

    if (mt.enclosedClasses != null) {
      for (String cls : mt.enclosedClasses) {
        StructClass cl = DecompilerContext.getStructContext().getClass(cls);
        for (StructMethod meth : cl.getMethods()) {
          meth.getVariableNamer().addParentContext(this.mt.getVariableNamer());
        }
      }
    }

    Map<VarVersion, LocalVariable> lvts = new HashMap<>();

    for (Entry<VarVersion, VarInfo> e : types.entrySet()) {
      VarVersion idx = e.getKey();
      // skip this. we can't rename it
      if (idx.var == 0 && !mt.hasModifier(CodeConstants.ACC_STATIC)) {
        continue;
      }
      LocalVariable lvt = e.getValue().getLVT();
      String rename = renames == null ? null : renames.get(idx);

      if (rename != null) {
        varproc.setVarName(idx, rename);
      }

      if (lvt != null) {
        if (rename != null) {
          lvt = lvt.rename(rename);
        }
        varproc.setVarLVTEntry(idx, lvt);
        lvts.put(idx, lvt);
      }
    }


    applyTypes(stat, lvts);
  }