private List<FoldingEntry> getMarks(Document doc, int grammarVersion) { ParseOutput r = PyParser.reparseDocument(new PyParser.ParserInfo(doc, grammarVersion, null)); List<FoldingEntry> marks = CodeFoldingSetter.getMarks(doc, (SimpleNode) r.ast, true); if (DEBUG) { for (FoldingEntry entry : marks) { System.out.println(entry); } } return marks; }
/** * @param request this is the request for the completion * @param theList OUT - returned completions are added here. (IToken instances) * @param getOnlySupers whether we should only get things from super classes (in this case, we * won't get things from the current class) * @param checkIfInCorrectScope if true, we'll first check if we're in a scope that actually has a * method with 'self' or 'cls' * @return true if we actually tried to get the completions for self or cls. * @throws MisconfigurationException */ @SuppressWarnings("unchecked") public static boolean getSelfOrClsCompletions( CompletionRequest request, List theList, ICompletionState state, boolean getOnlySupers, boolean checkIfInCorrectScope, String lookForRep) throws MisconfigurationException { SimpleNode s = PyParser.reparseDocument( new PyParser.ParserInfo(request.doc, true, request.nature, state.getLine())) .o1; if (s != null) { FindScopeVisitor visitor = new FindScopeVisitor(state.getLine(), 0); try { s.accept(visitor); if (checkIfInCorrectScope) { boolean scopeCorrect = false; FastStack<SimpleNode> scopeStack = visitor.scope.getScopeStack(); for (Iterator<SimpleNode> it = scopeStack.topDownIterator(); scopeCorrect == false && it.hasNext(); ) { SimpleNode node = it.next(); if (node instanceof FunctionDef) { FunctionDef funcDef = (FunctionDef) node; if (funcDef.args != null && funcDef.args.args != null && funcDef.args.args.length > 0) { // ok, we have some arg, let's check for self or cls String rep = NodeUtils.getRepresentationString(funcDef.args.args[0]); if (rep != null && (rep.equals("self") || rep.equals("cls"))) { scopeCorrect = true; } } } } if (!scopeCorrect) { return false; } } if (lookForRep.equals("self")) { state.setLookingFor(ICompletionState.LOOKING_FOR_INSTANCED_VARIABLE); } else { state.setLookingFor(ICompletionState.LOOKING_FOR_CLASSMETHOD_VARIABLE); } getSelfOrClsCompletions(visitor.scope, request, theList, state, getOnlySupers); } catch (Exception e1) { PydevPlugin.log(e1); } return true; } return false; }
/** * This function creates the module given that you have a document (that will be parsed) * * @throws MisconfigurationException */ public static SourceModule createModuleFromDoc( String name, File f, IDocument doc, IPythonNature nature, boolean checkForPath, IGrammarVersionProvider grammarVersionProvider) throws MisconfigurationException { // for doc, we are only interested in python files. if (f != null) { if (!checkForPath || PythonPathHelper.isValidSourceFile(f.getName())) { ParseOutput obj = PyParser.reparseDocument(new PyParser.ParserInfo(doc, grammarVersionProvider, name, f)); return new SourceModule(name, f, (SimpleNode) obj.ast, obj.error, nature); } } else { ParseOutput obj = PyParser.reparseDocument(new PyParser.ParserInfo(doc, grammarVersionProvider, name, f)); return new SourceModule(name, f, (SimpleNode) obj.ast, obj.error, nature); } return null; }
public static Module getRootNode(IDocument doc) throws ParseException { Tuple<SimpleNode, Throwable> objects = PyParser.reparseDocument( new PyParser.ParserInfo(doc, false, IPythonNature.LATEST_GRAMMAR_VERSION)); Throwable exception = objects.o2; if (exception != null) { /* We try to get rid of the 'Throwable' exception, if possible */ if (exception instanceof ParseException) { throw (ParseException) exception; } else if (exception instanceof TokenMgrError) { /* Error from Lexer */ throw new ParseException(exception.toString()); } else { throw new RuntimeException(exception); } } if (objects.o2 != null) throw new RuntimeException(objects.o2); return (Module) objects.o1; }