functionargadapter.java

来自「Python Development Environment (Python I」· Java 代码 · 共 69 行

JAVA
69
字号
package org.python.pydev.refactoring.ast.adapters;

import java.util.ArrayList;
import java.util.List;

import org.python.pydev.parser.jython.ast.argumentsType;
import org.python.pydev.parser.jython.ast.exprType;
import org.python.pydev.refactoring.ast.rewriter.RewriterVisitor;

public class FunctionArgAdapter extends AbstractNodeAdapter<argumentsType> {

	public FunctionArgAdapter(ModuleAdapter module, FunctionDefAdapter parent, argumentsType node, String endLineDelim) {
		super(module, parent, node, endLineDelim);
	}

	public boolean hasKwArg() {
		return getASTNode().kwarg != null;
	}

	public boolean hasVarArg() {
		return (getASTNode().vararg != null);
	}

	public boolean hasArg() {
		return (getASTNode().args != null) && (getASTNode().args.length > 0);
	}

	public List<String> getArgOnly() {
		List<String> args = new ArrayList<String>();
		for (exprType arg : getASTNode().args) {
			args.add(nodeHelper.getName(arg));
		}
		return args;
	}

	public List<String> getSelfFilteredArgNames() {
		List<String> args = new ArrayList<String>();
		for (exprType arg : getSelfFilteredArgs()) {
			args.add(nodeHelper.getName(arg));
		}
		return args;
	}

	public List<exprType> getSelfFilteredArgs() {
		List<exprType> args = new ArrayList<exprType>();
		if (getASTNode().args == null)
			return args;

		for (exprType arg : getASTNode().args) {
			String argument = nodeHelper.getName(arg);
			if (!nodeHelper.isSelf(argument))
				args.add(arg);
		}
		return args;
	}

	public boolean isEmptyArgument() {
		return (!hasArg()) && (!(hasVarArg())) && (!(hasKwArg()));
	}

	public boolean hasOnlySelf() {
		return getSelfFilteredArgs().size() == 0 && (!(hasVarArg())) && (!(hasKwArg()));
	}

	public String getSignature() {
		return RewriterVisitor.createSourceFromAST(this.getASTNode(), true, getModule().getEndLineDelimiter());
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?