/**
   * @param lastMayBeMethod if true, it gets the path and accepts a method (if it is the last in the
   *     stack) if false, null is returned if a method is found.
   * @param tempStack is a temporary stack object (which may be cleared)
   * @return a tuple, where the first element is the path where the entry is located (may return
   *     null). and the second element is a boolen that indicates if the last was actually a method
   *     or not.
   */
  private Tuple<String, Boolean> getPathToRoot(
      ASTEntry entry, boolean lastMayBeMethod, boolean acceptAny, FastStack<SimpleNode> tempStack) {
    if (entry.parent == null) {
      return null;
    }
    // just to be sure that it's empty
    tempStack.clear();

    boolean lastIsMethod = false;
    // if the last 'may be a method', in this case, we have to remember that it will actually be the
    // first one
    // to be analyzed.

    // let's get the stack
    while (entry.parent != null) {
      if (entry.parent.node instanceof ClassDef) {
        tempStack.push(entry.parent.node);

      } else if (entry.parent.node instanceof FunctionDef) {
        if (!acceptAny) {
          if (lastIsMethod) {
            // already found a method
            return null;
          }

          if (!lastMayBeMethod) {
            return null;
          }

          // ok, the last one may be a method... (in this search, it MUST be the first one...)
          if (tempStack.size() != 0) {
            return null;
          }
        }

        // ok, there was a class, so, let's go and set it
        tempStack.push(entry.parent.node);
        lastIsMethod = true;

      } else {
        return null;
      }
      entry = entry.parent;
    }

    // now that we have the stack, let's make it into a path...
    FastStringBuffer buf = new FastStringBuffer();
    while (tempStack.size() > 0) {
      if (buf.length() > 0) {
        buf.append(".");
      }
      buf.append(NodeUtils.getRepresentationString(tempStack.pop()));
    }
    return new Tuple<String, Boolean>(buf.toString(), lastIsMethod);
  }
  /**
   * @see
   *     org.python.pydev.parser.jython.ast.VisitorBase#visitClassDef(org.python.pydev.parser.jython.ast.ClassDef)
   */
  public Object visitClassDef(ClassDef node) throws Exception {
    globalDeclarationsStack.push(new HashSet<String>());
    defsStack.push(node);

    node.traverse(this);

    defsStack.pop();
    globalDeclarationsStack.pop();

    checkDeclaration(node, (NameTok) node.name);
    return null;
  }
Example #3
0
 public void pushTemporaryModule(String moduleName, IModule module) {
   synchronized (lockTemporaryModules) {
     if (temporaryModules == null) {
       temporaryModules = new HashMap<String, FastStack<IModule>>();
     }
     FastStack<IModule> stack = temporaryModules.get(moduleName);
     if (stack == null) {
       stack = new FastStack<IModule>(3); // small initial size!
       temporaryModules.put(moduleName, stack);
     }
     stack.push(module);
   }
 }
  public AbstractContextVisitor(
      ModuleAdapter module, AbstractNodeAdapter<? extends SimpleNode> parent) {
    super();
    assert (module != null);

    this.moduleAdapter = module;

    nodeHelper = new NodeHelper(module.getAdapterPrefs());

    stack = new FastStack<SimpleNode>();
    parents = new FastStack<AbstractScopeNode<?>>();
    parents.push(moduleAdapter);
    stack.push(module.getASTNode());

    nodes = new ArrayList<T>();
  }
  /**
   * @see
   *     org.python.pydev.parser.jython.ast.VisitorBase#visitFunctionDef(org.python.pydev.parser.jython.ast.FunctionDef)
   */
  public Object visitFunctionDef(FunctionDef node) throws Exception {
    globalDeclarationsStack.push(new HashSet<String>());
    defsStack.push(node);

    if (node.args != null && node.args.args != null) {
      for (exprType arg : node.args.args) {
        if (arg instanceof Name) {
          checkParam((Name) arg);
        }
      }
    }
    node.traverse(this);

    defsStack.pop();
    globalDeclarationsStack.pop();

    checkDeclaration(node, (NameTok) node.name);
    return null;
  }
 protected AbstractNodeAdapter<? extends SimpleNode> before(SimpleNode node) {
   AbstractNodeAdapter<? extends SimpleNode> context = createContext(node);
   stack.push(node);
   return context;
 }