Package org.python.pydev.refactoring.ast.adapters.offsetstrategy

Examples of org.python.pydev.refactoring.ast.adapters.offsetstrategy.IOffsetStrategy


    protected Tuple<Integer, String> getLocationOffset(int locationStrategy, PySelection pySelection,
            ModuleAdapter moduleAdapter, IClassDefAdapter targetClass) {
        Assert.isNotNull(targetClass);

        int offset;
        IOffsetStrategy strategy;
        try {
            switch (locationStrategy) {
                case LOCATION_STRATEGY_BEFORE_CURRENT:
                    String currentLine = pySelection.getLine();
                    int firstCharPosition = PySelection.getFirstCharPosition(currentLine);

                    LineStartingScope scopeStart = pySelection.getPreviousLineThatStartsScope(
                            PySelection.CLASS_AND_FUNC_TOKENS, false, firstCharPosition);

                    if (scopeStart == null) {
                        Log.log("Could not get proper scope to create code inside class.");
                        ClassDef astNode = targetClass.getASTNode();
                        if (astNode.body.length > 0) {
                            offset = NodeUtils.getLineEnd(astNode.body[astNode.body.length - 1]);

                        } else {
                            offset = NodeUtils.getLineEnd(astNode);
                        }
                    } else {
                        int iLineStartingScope = scopeStart.iLineStartingScope;
                        String line = pySelection.getLine(iLineStartingScope);

                        if (pySelection.matchesFunctionLine(line) || pySelection.matchesClassLine(line)) {
                            //check for decorators...
                            if (iLineStartingScope > 0) {
                                int i = iLineStartingScope - 1;
                                while (pySelection.getLine(i).trim().startsWith("@")) {
                                    iLineStartingScope = i;
                                    i--;
                                }
                            }
                        }
                        offset = pySelection.getLineOffset(iLineStartingScope);
                    }

                    break;

                case LOCATION_STRATEGY_END:
                    strategy = new EndOffset(targetClass, pySelection.getDoc(), moduleAdapter.getAdapterPrefs());
                    offset = strategy.getOffset();

                    break;

                case LOCATION_STRATEGY_FIRST_METHOD:
                    strategy = new BeginOffset(targetClass, pySelection.getDoc(), moduleAdapter.getAdapterPrefs());
                    offset = strategy.getOffset();

                    break;

                default:
                    throw new AssertionError("Unknown location strategy: " + locationStrategy);
View Full Code Here

TOP

Related Classes of org.python.pydev.refactoring.ast.adapters.offsetstrategy.IOffsetStrategy

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.