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)); } } } } }
public String getDescription() { FunctionStatement f = getFunctionStatement(getScriptFile(), getProblemStartIdx()); ISourceModule sourceModule = DLTKCore.createSourceModuleFrom(getScriptFile()); try { String functionString = sourceModule.getBuffer().getText(f.sourceStart(), f.sourceEnd() - f.sourceStart()); int lineEnd = functionString.indexOf('\n'); StringBuilder sb = new StringBuilder(lineEnd + 100); sb.append("<html><body> *<b>"); sb.append(getAnnotation()); sb.append("</b><br/> */<br/>"); sb.append(functionString.substring(0, lineEnd)); sb.append("</body></html>"); return sb.toString(); } catch (ModelException e) { } return getLabel(); }
/** * @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; }
protected MultiTextEdit getTextEdit(final IFile scriptFile, final int position) { MultiTextEdit textEdit = new MultiTextEdit(); FunctionStatement fs = getFunctionStatement(scriptFile, position); if (fs != null) { // TODO identation should be get.. int insertOffset = -1; Comment documentation = fs.getDocumentation(); if (documentation != null && documentation.isDocumentation()) { insertOffset = documentation.sourceEnd() - 2; InsertEdit suppressTextEdit = new InsertEdit( insertOffset, "* " + getAnnotation() + "\n "); // $NON-NLS-1$ //$NON-NLS-2$ textEdit.addChild(suppressTextEdit); } else { textEdit.addChild( new InsertEdit(fs.sourceStart(), "/**\n * " + getAnnotation() + "\n*/\n")); } } return textEdit; }
@Override protected JSMethod createMethod(FunctionStatement node) { JSMethod method = super.createMethod(node); if (method != null && method.isDeprecated()) { if (node.getName() != null) { requestor.addPosition( node.getName().sourceStart(), node.getName().sourceEnd(), JS_DEPRECATED); } else if (node.getParent() instanceof BinaryOperation && ((BinaryOperation) node.getParent()).getLeftExpression() instanceof PropertyExpression) { PropertyExpression exp = (PropertyExpression) ((BinaryOperation) node.getParent()).getLeftExpression(); requestor.addPosition( exp.getProperty().sourceStart(), exp.getProperty().sourceEnd(), JS_DEPRECATED); } else if (node.getParent() instanceof PropertyInitializer) { Expression name = ((PropertyInitializer) node.getParent()).getName(); requestor.addPosition(name.sourceStart(), name.sourceEnd(), JS_DEPRECATED); } } return method; }
@Override public IMatchLocatorValue visitFunctionStatement(FunctionStatement node) { return createFunctionDeclaration(node, node.getName()); }