Package org.python.pydev.core.docutils

Examples of org.python.pydev.core.docutils.PySelection$ActivationTokenAndQual


            MakeAstValidForPrettyPrintingVisitor.makeValid(functionDef);
        } catch (Exception e) {
            Log.log(e);
        }
        String printed = printAst(edit, functionDef, delimiter);
        PySelection ps = new PySelection(document, offset);
        try {
            String lineContentsToCursor = ps.getLineContentsToCursor();
            int defIndex = lineContentsToCursor.indexOf("def");
            int defOffset = ps.getLineOffset() + defIndex;
            printed = StringUtils.indentTo(printed, lineContentsToCursor.substring(0, defIndex), false);
            printed = StringUtils.rightTrim(printed);

            this.fLen += offset - defOffset;
View Full Code Here


        //let's see if we should do a code-completion in the current scope...

        //this engine does not work 'correctly' in the default scope on:
        //- class definitions - after 'class' and before '('
        //- method definitions - after 'def' and before '('
        PySelection ps = request.getPySelection();
        int lineCtx = ps.isInDeclarationLine();
        if (lineCtx != PySelection.DECLARATION_NONE) {
            if (lineCtx == PySelection.DECLARATION_METHOD) {
                Image imageOverride = PydevPlugin.getImageCache().get(UIConstants.METHOD_ICON);
                String lineContentsToCursor = ps.getLineContentsToCursor();
                LineStartingScope scopeStart = ps.getPreviousLineThatStartsScope(PySelection.CLASS_TOKEN, false,
                        PySelection.getFirstCharPosition(lineContentsToCursor));

                String className = null;
                if (scopeStart != null) {
                    className = PySelection.getClassNameInLine(scopeStart.lineStartingScope);
                    if (className != null && className.length() > 0) {
                        Tuple<List<String>, Integer> insideParensBaseClasses = ps.getInsideParentesisToks(true,
                                scopeStart.iLineStartingScope);
                        if (insideParensBaseClasses != null) {

                            //representation -> token and base class
                            OrderedMap<String, ImmutableTuple<IToken, String>> map = new OrderedMap<String, ImmutableTuple<IToken, String>>();

                            for (String baseClass : insideParensBaseClasses.o1) {
                                try {
                                    ICompletionState state = new CompletionState(-1, -1, null, request.nature,
                                            baseClass);
                                    state.setActivationToken(baseClass);
                                    state.setIsInCalltip(false);

                                    IPythonNature pythonNature = request.nature;
                                    checkPythonNature(pythonNature);

                                    ICodeCompletionASTManager astManager = pythonNature.getAstManager();
                                    if (astManager == null) {
                                        //we're probably still loading it.
                                        return ret;
                                    }
                                    //Ok, looking for a token in globals.
                                    IModule module = request.getModule();
                                    if (module == null) {
                                        continue;
                                    }
                                    IToken[] comps = astManager.getCompletionsForModule(module, state, true, true);
                                    for (int i = 0; i < comps.length; i++) {
                                        IToken iToken = comps[i];
                                        String representation = iToken.getRepresentation();
                                        ImmutableTuple<IToken, String> curr = map.get(representation);
                                        if (curr != null && curr.o1 instanceof SourceToken) {
                                            continue; //source tokens are never reset!
                                        }

                                        int type = iToken.getType();
                                        if (iToken instanceof SourceToken
                                                && ((SourceToken) iToken).getAst() instanceof FunctionDef) {
                                            map.put(representation, new ImmutableTuple<IToken, String>(iToken,
                                                    baseClass));

                                        } else if (type == IToken.TYPE_FUNCTION || type == IToken.TYPE_UNKNOWN
                                                || type == IToken.TYPE_BUILTIN) {
                                            map.put(representation, new ImmutableTuple<IToken, String>(iToken,
                                                    baseClass));

                                        }
                                    }
                                } catch (Exception e) {
                                    Log.log(e);
                                }
                            }

                            for (ImmutableTuple<IToken, String> tokenAndBaseClass : map.values()) {
                                FunctionDef functionDef = null;

                                //No checkings needed for type (we already did that above).
                                if (tokenAndBaseClass.o1 instanceof SourceToken) {
                                    SourceToken sourceToken = (SourceToken) tokenAndBaseClass.o1;
                                    SimpleNode ast = sourceToken.getAst();
                                    if (ast instanceof FunctionDef) {
                                        functionDef = (FunctionDef) ast;
                                    } else {
                                        functionDef = sourceToken.getAliased().createCopy();
                                        NameTok t = (NameTok) functionDef.name;
                                        t.id = sourceToken.getRepresentation();
                                    }
                                } else {
                                    //unfortunately, for builtins we usually cannot trust the parameters.
                                    String representation = tokenAndBaseClass.o1.getRepresentation();
                                    PyAstFactory factory = new PyAstFactory(new AdapterPrefs(ps.getEndLineDelim(),
                                            request.nature));
                                    functionDef = factory.createFunctionDef(representation);
                                    functionDef.args = factory.createArguments(true);
                                    functionDef.args.vararg = new NameTok("args", NameTok.VarArg);
                                    functionDef.args.kwarg = new NameTok("kwargs", NameTok.KwArg);
                                    if (!representation.equals("__init__")) {
                                        functionDef.body = new stmtType[] { new Return(null) }; //signal that the return should be added
                                    }
                                }

                                if (functionDef != null) {
                                    ret.add(new OverrideMethodCompletionProposal(ps.getAbsoluteCursorOffset(), 0, 0,
                                            imageOverride, functionDef, tokenAndBaseClass.o2, //baseClass
                                            className));
                                }
                            }
View Full Code Here

    private void handleKeywordParam(CompletionRequest request, int line, Map<String, IToken> alreadyChecked)
            throws BadLocationException, CompletionRecursionException {
        if (request.isInMethodKeywordParam) {

            PySelection ps = new PySelection(request.doc, request.offsetForKeywordParam);
            RefactoringRequest findRequest = new RefactoringRequest(request.editorFile, ps, new NullProgressMonitor(),
                    request.nature, null);
            ArrayList<IDefinition> selected = new ArrayList<IDefinition>();
            PyRefactoringFindDefinition.findActualDefinition(findRequest, new CompletionCache(), selected);
View Full Code Here

    public AdapterPrefs getAdapterPrefs() {
        return new AdapterPrefs(getNewLineDelim(), versionProvider);
    }

    public PySelection getPySelection() {
        return new PySelection(doc, userSelection);
    }
View Full Code Here

         */
        private void notifyCursorPositionChanged() {
            if (!initFinished) {
                return;
            }
            PySelection ps = new PySelection(PyEdit.this);
            for (IPyEditListener listener : getAllListeners()) {
                try {
                    if (listener instanceof IPyEditListener2) {
                        ((IPyEditListener2) listener).handleCursorPositionChanged(PyEdit.this, ps);
                    }
View Full Code Here

     * @return a PySelection that represents the current request. If it doesn't exist, create it and cache
     * for other requests.
     */
    public PySelection getPySelection() {
        if (this.ps == null) {
            this.ps = new PySelection(this.doc, this.documentOffset);
        }
        return this.ps;
    }
View Full Code Here

    public static PyDocumentTemplateContext createContext(final TemplateContextType contextType,
            final ITextViewer viewer, final IRegion region) {
        if (contextType != null) {
            IDocument document = viewer.getDocument();
            PySelection selection = new PySelection(document, viewer.getTextWidget().getSelection().x);
            String indent = selection.getIndentationFromLine();
            return createContext(contextType, viewer, region, indent);
        }
        return null;
    }
View Full Code Here

                return;
            }

            PyEdit pyEdit = (PyEdit) getTextEditor();
            IIndentPrefs indentPrefs = pyEdit.getIndentPrefs();
            PySelection ps = new PySelection(pyEdit);
            perform(ps, indentPrefs);
        } catch (Exception e) {
            beep(e);
        }
    }
View Full Code Here

            if (!canModifyEditor()) {
                return;
            }

            // Select from text editor
            PySelection ps = new PySelection(getTextEditor());
            // Perform the action
            Tuple<Integer, Integer> repRegion = perform(ps);

            // Put cursor at the first area of the selection
            getTextEditor().selectAndReveal(repRegion.o1, repRegion.o2);
View Full Code Here

        return false;
    }

    public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
        int offset = invocationContext.getOffset();
        PySelection base = edit.createPySelection();
        if (!(this.edit instanceof PyEdit) || base == null) {
            return new ICompletionProposal[0];
        }
        PyEdit editor = (PyEdit) this.edit;

        List<ICompletionProposal> results = new ArrayList<ICompletionProposal>();
        String sel = PyAction.getLineWithoutComments(base);

        List<IAssistProps> assists = new ArrayList<IAssistProps>();
        synchronized (PythonCorrectionProcessor.additionalAssists) {
            for (IAssistProps prop : additionalAssists.values()) {
                assists.add(prop);
            }
        }

        assists.add(new AssistSurroundWith());
        assists.add(new AssistImport());
        assists.add(new AssistDocString());
        assists.add(new AssistAssign());
        assists.add(new AssistPercentToFormat());

        assists.addAll(ExtensionHelper.getParticipants(ExtensionHelper.PYDEV_CTRL_1));
        ImageCache imageCache = PydevPlugin.getImageCache();
        File editorFile = edit.getEditorFile();
        IPythonNature pythonNature = null;
        try {
            pythonNature = edit.getPythonNature();
        } catch (MisconfigurationException e1) {
            Log.log(e1);
        }

        for (IAssistProps assist : assists) {
            //Always create a new for each assist, as any given assist may change it.
            PySelection ps = new PySelection(base);
            try {
                if (assist.isValid(ps, sel, editor, offset)) {
                    try {
                        results.addAll(assist.getProps(ps, imageCache, editorFile, pythonNature, editor, offset));
                    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.python.pydev.core.docutils.PySelection$ActivationTokenAndQual

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.