@Override public boolean enterFunctionNode(FunctionNode functionNode) { String name = builder.getFunctionName(functionNode); exp.add(name); if (typeOffset == -1) { typeOffset = functionNode.getIdent().getStart(); } return false; }
private boolean isFunctionAnonymous(FunctionNode fn) { boolean result = false; if (fn.isAnonymous() ) { Node lastVisited = getPreviousFromPath(2); if (fn.getIdent().getName().startsWith("L:") && !(lastVisited instanceof PropertyNode)) { //NOI18N // XXX this depends on the implemenation of parser. Find the better way result = true; } else if (fn.getIdent().getStart() == fn.getIdent().getFinish()) { if (lastVisited instanceof CallNode) { result = true; } } } return result; }
private List<Identifier> getName(PropertyNode propertyNode) { List<Identifier> name = new ArrayList(1); if (propertyNode.getGetter() != null || propertyNode.getSetter() != null) { // check whether this is not defining getter or setter of a property. Node previousNode = getPreviousFromPath(1); if (previousNode instanceof FunctionNode) { FunctionNode fNode = (FunctionNode)previousNode; String fName = fNode.getIdent().getName(); if (fName.startsWith("get ") || fName.startsWith("set ")) { //NOI18N name.add(new Identifier(fName, new OffsetRange(fNode.getIdent().getStart(), fNode.getIdent().getFinish()))); return name; } } } return getName(propertyNode, parserResult); }
private String debugInfo(Node node) { StringBuilder sb = new StringBuilder(); if (node instanceof FunctionNode) { FunctionNode fn = (FunctionNode)node; sb.append("FunctionNode name: ").append(fn.getName()); sb.append(", Ident: ").append(fn.getIdent()); if (fn.allVarsInScope()) sb.append(", allVarsInScope"); if (fn.isAnonymous()) sb.append(", isAnonymous"); if (fn.isDeclared()) sb.append(", isDeclared"); if (fn.isMethod()) sb.append(", isMethod"); if (fn.isNamedFunctionExpression()) sb.append(", isNamedFunctionExpression"); if (fn.isVarArg()) sb.append(", isVarArg"); if (fn.hasDeclaredFunctions()) sb.append(", hasDeclaredFunctions"); if (fn.hasDirectSuper()) sb.append(", hasDirectSuper"); // if (fn.hasScopeBlock()) sb.append(", hasScoprBlock"); } else if (node instanceof VarNode) { VarNode vn = (VarNode)node; sb.append("VarNode ").append(vn.getName()); if (vn.isBlockScoped()) sb.append(", isBlockScoped"); if (vn.isConst()) sb.append(", isConst"); if (vn.isFunctionDeclaration()) sb.append(", isFunctionDeclaration"); if (vn.isLet()) sb.append(", isLet"); } else { sb.append(node.getClass().getName()); } return sb.toString(); }
public String getFunctionName(FunctionNode node) { if (node.isAnonymous() ) { return globalObject.getName() + node.getName().replace(':', '#'); } else { if (node.isNamedFunctionExpression()) { return node.getName(); } return node.getIdent().getName(); } } }
return Collections.<Identifier>emptyList(); IdentNode ident = ((FunctionNode) node).getIdent(); return Arrays.<Identifier>asList(new Identifier( ident.getName(), getOffsetRange(ident)));
private void handleDeclaredFunction(DeclarationScopeImpl inScope, JsObject parent, FunctionNode fnNode) { LOGGER.log(Level.FINEST, " function: " + debugInfo(fnNode)); // NOI18N String name = fnNode.isAnonymous() ? modelBuilder.getFunctionName(fnNode) : fnNode.getIdent().getName(); Identifier fnName = new Identifier(name, new OffsetRange(fnNode.getIdent().getStart(), fnNode.getIdent().getFinish())); if (fnNode.isClassConstructor() && !ModelUtils.CONSTRUCTOR.equals(fnName.getName())) { // skip artifical/ syntetic constructor nodes, that are created // when a class extends different class return; } // process parameters List<Identifier> parameters = new ArrayList(fnNode.getParameters().size()); for(IdentNode node: fnNode.getParameters()) { Identifier param = create(parserResult, node); if (param != null && !node.isDestructuredParameter()) { // can be null, if it's a generated embeding. parameters.add(param); } } // The parent can be changed in the later processing JsFunctionImpl declaredFn = new JsFunctionImpl(inScope, parent, fnName, parameters, getOffsetRange(fnNode), inScope.getMimeType(), inScope.getSourceLabel()); inScope.addProperty(modelBuilder.getFunctionName(fnNode), declaredFn); if (fnName.getOffsetRange().getLength() > 0 && !fnNode.isNamedFunctionExpression()) { declaredFn.addOccurrence(fnName.getOffsetRange()); } }
private void processDeclarations(final JsFunctionImpl parentFn, final FunctionNode inNode) { LOGGER.log(Level.FINEST, "in function: " + inNode.getName() + ", ident: " + inNode.getIdent()); final JsDocumentationHolder docHolder = JsDocumentationSupport.getDocumentationHolder(parserResult); Expression expression = export.getExpression(); if ((expression instanceof ClassNode && ((ClassNode)expression).getIdent() != null) || (expression instanceof FunctionNode && ((FunctionNode)expression).getIdent() != null)) { export.accept(visitor);
Identifier refName = new Identifier(fn.getIdent().getName(), new OffsetRange(fn.getIdent().getStart(), fn.getIdent().getFinish())); JsFunctionReference jsRef = new JsFunctionReference(jsFunction, refName, jsFunction, true, EnumSet.of(Modifier.PRIVATE)); jsRef.addOccurrence(jsRef.getDeclarationName().getOffsetRange()); Identifier refName = new Identifier(fn.getIdent().getName(), new OffsetRange(fn.getIdent().getStart(), fn.getIdent().getFinish())); JsFunctionReference jsRef = new JsFunctionReference(jsFunction, refName, jsFunction, true, EnumSet.of(Modifier.PRIVATE)); jsRef.addOccurrence(jsRef.getDeclarationName().getOffsetRange());