Examples of IClassDefAdapter


Examples of org.python.pydev.refactoring.ast.adapters.IClassDefAdapter

        return processors;
    }

    @Override
    public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
        IClassDefAdapter rootClass = this.info.getScopeClass();

        if (rootClass != null) {
            if (rootClass.getAttributes().size() > 0) {
                return status;
            }
        }

        status.addFatalError(Messages.constructorFieldUnavailable);
View Full Code Here

Examples of org.python.pydev.refactoring.ast.adapters.IClassDefAdapter

        return processors;
    }

    @Override
    public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
        IClassDefAdapter rootClass = this.info.getScopeClass();

        if (rootClass == null) {
            status.addFatalError(Messages.overrideMethodsUnavailable);
        }
View Full Code Here

Examples of org.python.pydev.refactoring.ast.adapters.IClassDefAdapter

        this(module, config.getClassSelection(), config.getAttributeSelection(), config.getMethodOffsetStrategy(),
                config.getPropertyOffsetStrategy(), config.getMethodSelection(), config.getAccessModifier());
    }

    public List<GeneratePropertiesRequest> getRefactoringRequests() {
        IClassDefAdapter clazz = module.getClasses().get(classSelection);

        List<INodeAdapter> attributes = new ArrayList<INodeAdapter>();
        for (int index : attributeSelection) {
            attributes.add(clazz.getAttributes().get(index));
        }

        List<PropertyTextAdapter> properties = new ArrayList<PropertyTextAdapter>();
        for (int elem : methodSelection) {
            properties.add(new PropertyTextAdapter(elem, ""));
View Full Code Here

Examples of org.python.pydev.refactoring.ast.adapters.IClassDefAdapter

    public MockupConstructorFieldRequestProcessor(ModuleAdapter module, MockupConstructorFieldConfig config) {
        this(module, config.getClassSelection(), config.getAttributeSelection(), config.getOffsetStrategy());
    }

    public List<ConstructorFieldRequest> getRefactoringRequests() {
        IClassDefAdapter clazz = module.getClasses().get(classSelection);
        List<INodeAdapter> attributes = new ArrayList<INodeAdapter>();

        for (int index : attributeSelection) {
            attributes.add(clazz.getAttributes().get(index));
        }
        ConstructorFieldRequest req = new ConstructorFieldRequest(clazz, attributes, this.offsetStrategy,
                new AdapterPrefs("\n", new IGrammarVersionProvider() {

                    public int getGrammarVersion() throws MisconfigurationException {
View Full Code Here

Examples of org.python.pydev.refactoring.ast.adapters.IClassDefAdapter

    }

    public List<OverrideMethodsRequest> getRefactoringRequests() throws MisconfigurationException {
        ClassDefAdapter clazz = (ClassDefAdapter) module.getClasses().get(editClass);

        IClassDefAdapter clazzSelection;

        int parsedInt = -1;
        try {
            parsedInt = Integer.parseInt(classSelection);
        } catch (NumberFormatException e) {
        }

        if (parsedInt != -1) {
            clazzSelection = module.getClasses().get(parsedInt);
        } else {
            List<String> split = StringUtils.split(classSelection, ",");
            if (split.size() != 2) {
                throw new RuntimeException("Right now can only handle with a single comma.");
            }
            clazzSelection = module.getClasses().get(Integer.parseInt(split.get(0)));
            List<IClassDefAdapter> classHierarchy = module.getClassHierarchy(clazz);
            boolean found = false;
            StringBuffer foundClasses = new StringBuffer("\nFound classes:");
            for (IClassDefAdapter iClassDefAdapter : classHierarchy) {
                foundClasses.append(iClassDefAdapter.getName());
                if (iClassDefAdapter.getName().equals(split.get(1))) {
                    clazzSelection = iClassDefAdapter;
                    found = true;
                    break;
                }
            }
            if (!found) {
                String message = "Could not find: " + split.get(1) + foundClasses;

                throw new RuntimeException(message);
            }
        }

        String baseClassName = clazzSelection.getName();
        List<FunctionDefAdapter> methods = new ArrayList<FunctionDefAdapter>();

        for (Object o : methodSelection) {
            if (o instanceof Integer) {
                methods.add(clazzSelection.getFunctions().get((Integer) o));
            } else if (o instanceof String) {
                List<FunctionDefAdapter> functions = clazzSelection.getFunctions();
                boolean found = false;
                for (FunctionDefAdapter f : functions) {
                    if (f.getName().equals(o)) {
                        methods.add(f);
                        found = true;
View Full Code Here

Examples of org.python.pydev.refactoring.ast.adapters.IClassDefAdapter

                module, module);
        Iterator<IClassDefAdapter> iter = visitor.iterator();

        buffer.append("# " + visitor.getAll().size() + "\n");
        while (iter.hasNext()) {
            IClassDefAdapter adapter = iter.next();
            buffer.append("# " + adapter.getName() + " " + adapter.isNested() + "\n");
        }
        this.setTestGenerated(buffer.toString().trim());

        assertEquals(3, visitor.getAll().size());
        assertEquals(getExpected(), getGenerated());
View Full Code Here

Examples of org.python.pydev.refactoring.ast.adapters.IClassDefAdapter

            List<String> parametersAfterCall) {
        PySelection pySelection = refactoringInfo.getPySelection();
        ModuleAdapter moduleAdapter = refactoringInfo.getModuleAdapter();
        String decorators = "";

        IClassDefAdapter targetClass = null;
        String body = "${pass}";
        if (createInClass != null) {
            List<IClassDefAdapter> classes = moduleAdapter.getClasses();
            for (IClassDefAdapter iClassDefAdapter : classes) {
                if (createInClass.equals(iClassDefAdapter.getName())) {
                    targetClass = iClassDefAdapter;
                    break;
                }
            }

            if (targetClass != null) {
                switch (createAs) {
                    case BOUND_METHOD:
                        parametersAfterCall = checkFirst(parametersAfterCall, "self");
                        break;

                    case CLASSMETHOD:
                        parametersAfterCall = checkFirst(parametersAfterCall, "cls");
                        decorators = "@classmethod\n";
                        break;

                    case STATICMETHOD:
                        decorators = "@staticmethod\n";
                        break;

                    case CONSTANT:
                        String indent = targetClass.getNodeBodyIndent();
                        Pass replacePassStatement = getLastPassFromNode(targetClass.getASTNode());

                        String constant = com.aptana.shared_core.string.StringUtils.format("\n%s = ${None}${cursor}\n", actTok);
                        Tuple<Integer, String> offsetAndIndent;
                        offsetAndIndent = getLocationOffset(AbstractPyCreateAction.LOCATION_STRATEGY_FIRST_METHOD,
                                pySelection, moduleAdapter, targetClass);

                        return createProposal(pySelection, constant, offsetAndIndent, false, replacePassStatement);

                    case FIELD:

                        parametersAfterCall = checkFirst(parametersAfterCall, "self");
                        FunctionDefAdapter firstInit = targetClass.getFirstInit();
                        if (firstInit != null) {
                            FunctionDef astNode = firstInit.getASTNode();
                            replacePassStatement = getLastPassFromNode(astNode);

                            //Create the field as the last line in the __init__
                            int nodeLastLine = firstInit.getNodeLastLine() - 1;
                            indent = firstInit.getNodeBodyIndent();
                            String pattern;

                            if (replacePassStatement == null) {
                                pattern = com.aptana.shared_core.string.StringUtils.format("\nself.%s = ${None}${cursor}", actTok);
                                try {
                                    IRegion region = pySelection.getDoc().getLineInformation(nodeLastLine);
                                    int offset = region.getOffset() + region.getLength();
                                    offsetAndIndent = new Tuple<Integer, String>(offset, indent);
                                } catch (BadLocationException e) {
                                    Log.log(e);
                                    return null;
                                }

                            } else {
                                pattern = com.aptana.shared_core.string.StringUtils.format("self.%s = ${None}${cursor}", actTok);
                                offsetAndIndent = new Tuple<Integer, String>(-1, ""); //offset will be from the pass stmt
                            }
                            return createProposal(pySelection, pattern, offsetAndIndent, false, replacePassStatement);

                        } else {
                            //Create the __init__ with the field declaration!
                            body = com.aptana.shared_core.string.StringUtils.format("self.%s = ${None}${cursor}", actTok);
                            actTok = "__init__";
                            locationStrategy = AbstractPyCreateAction.LOCATION_STRATEGY_FIRST_METHOD;
                        }

                        break;
                }
            } else {
                //We should create in a class and couldn't find it!
                return null;
            }
        }

        String params = "";
        String source;
        if (parametersAfterCall != null && parametersAfterCall.size() > 0) {
            params = createParametersList(parametersAfterCall).toString();
        }

        Tuple<Integer, String> offsetAndIndent;
        Pass replacePassStatement = null;
        if (targetClass != null) {
            replacePassStatement = getLastPassFromNode(targetClass.getASTNode());
            offsetAndIndent = getLocationOffset(locationStrategy, pySelection, moduleAdapter, targetClass);

        } else {
            offsetAndIndent = getLocationOffset(locationStrategy, pySelection, moduleAdapter);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.