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)); } } } } }
/** * @param node * @return */ private IMatchLocatorValue createFunctionDeclaration(FunctionStatement node, Identifier name) { final JSMethod method = new JSMethod(node, referenceSource); jsdocSupport.processMethod(node, method, fReporter, fTypeChecker); final FunctionNode functionNode; if (node.isDeclaration()) { functionNode = new FunctionDeclaration(peek(), node, method); } else { functionNode = new FunctionExpression(peek(), node, method); } method.setLocation( ReferenceLocation.create( referenceSource, node.start(), node.end(), functionNode.getNameNode())); functionNode.buildArgumentNodes(); push(functionNode); addFunctionDeclaration(name, node, method); visitFunctionBody(node); pop(); return null; }
private void createVariable(VariableDeclaration declaration) { final JSVariable variable = new JSVariable(declaration.getVariableName()); variable.setLocation( declaration.getInitializer() != null ? ReferenceLocation.create( referenceSource, declaration.start(), declaration.end(), declaration.getIdentifier()) : ReferenceLocation.create(referenceSource, declaration.start(), declaration.end())); jsdocSupport.processVariable(declaration, variable, fReporter, fTypeChecker); final VariableNode variableNode = new VariableNode(peek(), declaration, variable); peek().addChild(variableNode); if (scopes.size() == 1) { // TODO (alex) option to treat it as field or local addFieldDeclaration(declaration.getIdentifier(), variable.getType()); } else { nodes.add( new LocalVariableDeclarationNode( declaration.getIdentifier(), referenceSource.getSourceModule(), variable.getType())); } }