public void addFunctionDeclaration(
      Expression identifier, FunctionStatement function, IMethod method) {
    nodes.add(new MethodDeclarationNode(identifier != null ? identifier : function, method));

    Map<String, Argument> arguments = new HashMap<String, Argument>();
    for (Argument argument : function.getArguments()) {
      arguments.put(argument.getIdentifier().getName(), argument);
    }
    for (IParameter parameter : method.getParameters()) {
      final Argument argument = arguments.get(parameter.getName());
      if (argument != null) {
        nodes.add(
            new ArgumentDeclarationNode(
                argument, method.getLocation().getSourceModule(), parameter.getType()));
      }
    }
    final Comment comment = JSDocSupport.getComment(function);
    if (comment != null) {
      final JSDocTags tags = JSDocSupport.parse(comment);
      for (JSDocTag tag : tags.list(JSDocTag.PARAM)) {
        final ParameterNode node = JSDocSupport.parseParameter(tag);
        if (node != null) {
          final IParameter parameter = method.getParameter(node.name);
          if (parameter != null) {
            final Identifier ref = new Identifier(null);
            ref.setName(node.name);
            final int start = tag.fromValueOffset(node.offset);
            ref.setStart(start);
            ref.setEnd(start + node.name.length());
            nodes.add(new LocalVariableReferenceNode(ref, parameter.getLocation(), true));
          }
        }
      }
    }
  }
コード例 #2
0
 private void printRest(StringBuffer buffer) {
   if (!fRest.isEmpty()) {
     final Set<String> definedTags = new HashSet<String>();
     Collections.addAll(definedTags, JSDocTag.getTags());
     ISourceModule module = null; /* TODO identify module? */
     Collections.addAll(
         definedTags,
         JSKeywordManager.getInstance().getKeywords(JSKeywordCategory.JS_DOC_TAG, module));
     final List<Pair> unknowTags = new ArrayList<Pair>();
     for (Pair p : fRest) {
       buffer.append("<dt>"); // $NON-NLS-1$
       if (definedTags.contains(p.fTag)) {
         buffer.append(Character.toUpperCase(p.fTag.charAt(1))).append(p.fTag.substring(2));
         if (p.fContent.length() != 0) {
           buffer.append(":");
         }
         buffer.append("</dt>"); // $NON-NLS-1$
         printDefinition(buffer, p.fContent, TypedDefinition.AUTO);
       } else {
         unknowTags.add(p);
       }
     }
     for (Pair p : unknowTags) {
       buffer.append("<dt>"); // $NON-NLS-1$
       buffer.append(p.fTag);
       if (p.fContent.length() != 0) {
         buffer.append(":");
       }
       buffer.append("</dt>"); // $NON-NLS-1$
       printDefinition(buffer, p.fContent, TypedDefinition.AUTO);
     }
   }
 }