public static List<DeclarationWithProximity> getSortedProposedValues(
     Scope scope, Unit unit, final String exactName) {
   Map<String, DeclarationWithProximity> map = scope.getMatchingDeclarations(unit, "", 0, null);
   if (exactName != null) {
     for (DeclarationWithProximity dwp : new ArrayList<DeclarationWithProximity>(map.values())) {
       if (!dwp.isUnimported() && !dwp.isAlias() && isNameMatching(dwp.getName(), exactName)) {
         map.put(dwp.getName(), new DeclarationWithProximity(dwp.getDeclaration(), -5));
       }
     }
   }
   List<DeclarationWithProximity> results = new ArrayList<DeclarationWithProximity>(map.values());
   Collections.sort(results, new ArgumentProposalComparator(exactName));
   return results;
 }
示例#2
0
 /**
  * Generates the code for single or multiple parameter lists, with a callback function to generate
  * the function blocks.
  */
 static void generateParameterLists(
     final Node context,
     final List<Tree.ParameterList> plist,
     final Scope scope,
     final ParameterListCallback callback,
     final boolean emitFunctionKeyword,
     final GenerateJsVisitor gen) {
   if (plist.size() == 1) {
     if (emitFunctionKeyword) {
       gen.out("function");
     }
     Tree.ParameterList paramList = plist.get(0);
     paramList.visit(gen);
     callback.completeFunction();
   } else {
     List<MplData> metas = new ArrayList<>(plist.size());
     Function m = scope instanceof Function ? (Function) scope : null;
     for (Tree.ParameterList paramList : plist) {
       final MplData mpl = new MplData();
       metas.add(mpl);
       mpl.n = context;
       if (metas.size() == 1) {
         if (emitFunctionKeyword) {
           gen.out("function");
         }
       } else {
         mpl.name = gen.getNames().createTempVariable();
         mpl.params = paramList;
         gen.out("var ", mpl.name, "=function");
       }
       paramList.visit(gen);
       if (metas.size() == 1) {
         gen.beginBlock();
         gen.initSelf(context);
         Scope parent = scope == null ? null : scope.getContainer();
         gen.initParameters(
             paramList, parent instanceof TypeDeclaration ? (TypeDeclaration) parent : null, m);
       } else {
         gen.out("{");
       }
     }
     callback.completeFunction();
     closeMPL(metas, m.getType(), gen);
     gen.endBlock();
   }
 }
  @Override
  public void visit(Tree.Block that) {
    Scope scope = that.getScope();
    if (scope instanceof Constructor) {
      if (definitelyInitedBy.contains(delegatedConstructor)) {
        specified.definitely = true;
      }
      if (possiblyInitedBy.contains(delegatedConstructor)) {
        specified.possibly = true;
      }
      delegatedConstructor = null;
    }

    boolean oe = endsInBreakReturnThrow;
    Tree.Continue olc = lastContinue;
    Tree.Statement olcs = lastContinueStatement;
    // rather nasty way of detecting that the continue
    // occurs in another conditional branch of the
    // statement containing this block, even though we
    // did not find it in _this_ branch
    boolean continueInSomeBranchOfCurrentConditional =
        lastContinue != null && lastContinueStatement == null;
    boolean blockEndsInBreakReturnThrow = blockEndsInBreakReturnThrow(that);
    endsInBreakReturnThrow = endsInBreakReturnThrow || blockEndsInBreakReturnThrow;
    Tree.Continue last = null;
    Tree.Statement lastStatement = null;
    for (Tree.Statement st : that.getStatements()) {
      ContinueVisitor cv = new ContinueVisitor(olc);
      st.visit(cv);
      if (cv.node != null) {
        last = cv.node;
        lastStatement = st;
      }
      if (cv.found) {
        olc = null;
        olcs = null;
      }
    }
    if (blockEndsInBreakReturnThrow || continueInSomeBranchOfCurrentConditional) {
      lastContinue = last;
      lastContinueStatement = lastStatement;
    }
    super.visit(that);
    endsInBreakReturnThrow = oe;
    lastContinue = olc;
    lastContinueStatement = olcs;

    if (scope instanceof Constructor) {
      Constructor c = (Constructor) scope;
      if (specified.definitely) {
        definitelyInitedBy.add(c);
      }
      if (specified.possibly) {
        possiblyInitedBy.add(c);
      }
    }
    if (isNonPartialConstructor(scope) && declaration.getContainer() == scope.getContainer()) {
      if (!specified.definitely) {
        initedByEveryConstructor = false;
      }
    }
  }