use of org.python.pydev.refactoring.ast.adapters.INodeAdapter in project Pydev by fabioz.
the class ConstructorFieldRequestProcessor method getFields.
private List<INodeAdapter> getFields(Iterator<ITreeNode> iter) {
List<INodeAdapter> fields = new ArrayList<INodeAdapter>();
ITreeNode field = iter.next();
while (field instanceof TreeNodeField) {
fields.add(field.getAdapter());
if (iter.hasNext()) {
field = iter.next();
} else {
break;
}
}
return fields;
}
use of org.python.pydev.refactoring.ast.adapters.INodeAdapter in project Pydev by fabioz.
the class ConstructorFieldRequestProcessor method generateRequests.
private List<ConstructorFieldRequest> generateRequests() {
List<ConstructorFieldRequest> requests = new ArrayList<ConstructorFieldRequest>();
List<ITreeNode> nodes = new ArrayList<ITreeNode>();
for (Object o : checked) {
nodes.add((ITreeNode) o);
}
Iterator<ITreeNode> iter = nodes.iterator();
while (iter.hasNext()) {
ITreeNode node = iter.next();
if (node instanceof TreeNodeClassField) {
List<INodeAdapter> fields = getFields(iter);
if (!fields.isEmpty()) {
ClassDefAdapter clazz = (ClassDefAdapter) node.getAdapter();
ConstructorFieldRequest request = new ConstructorFieldRequest(clazz, fields, offsetStrategy, adapterPrefs);
requests.add(request);
}
}
}
return requests;
}
use of org.python.pydev.refactoring.ast.adapters.INodeAdapter in project Pydev by fabioz.
the class MockupConstructorFieldRequestProcessor method getRefactoringRequests.
@Override
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() {
@Override
public int getGrammarVersion() throws MisconfigurationException {
return IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_2_7;
}
@Override
public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() throws MisconfigurationException {
return null;
}
}));
List<ConstructorFieldRequest> requests = new ArrayList<ConstructorFieldRequest>();
requests.add(req);
return requests;
}
use of org.python.pydev.refactoring.ast.adapters.INodeAdapter in project Pydev by fabioz.
the class ConstructorMethodEdit method getEditNode.
/**
* Tricky :)
* @throws MisconfigurationException
*/
@Override
protected SimpleNode getEditNode() throws MisconfigurationException {
List<IClassDefAdapter> bases = classAdapter.getBaseClasses();
// extractArguments
NameTokType varArg = null;
NameTokType kwArg = null;
Set<String> argsNames = new LinkedHashSet<String>();
for (IClassDefAdapter baseClass : bases) {
FunctionDefAdapter init = baseClass.getFirstInit();
if (init != null) {
if (!init.getArguments().hasOnlySelf()) {
argsNames.addAll(init.getArguments().getSelfFilteredArgNames());
}
if (varArg == null && init.getArguments().hasVarArg()) {
varArg = new NameTok(ARGS, NameTok.VarArg);
}
if (kwArg == null && init.getArguments().hasKwArg()) {
kwArg = new NameTok(KWARGS, NameTok.KwArg);
}
}
}
// addOwnArguments
for (INodeAdapter adapter1 : attributes) {
argsNames.add(nodeHelper.getPublicAttr(adapter1.getName()));
}
List<exprType> argsExprList = new ArrayList<exprType>();
Name selfArg = new Name(NodeHelper.KEYWORD_SELF, Name.Param, false);
argsExprList.add(selfArg);
for (String parameter : argsNames) {
argsExprList.add(new Name(parameter.trim(), Name.Param, false));
}
exprType[] argsExpr = argsExprList.toArray(new exprType[0]);
argumentsType args = new argumentsType(argsExpr, varArg, kwArg, null, null, null, null, null, null, null);
// constructorCalls
List<stmtType> body = new ArrayList<stmtType>();
for (IClassDefAdapter base : bases) {
Expr init = extractConstructorInit(base);
if (init != null) {
body.add(init);
}
}
// initAttributes
for (INodeAdapter adapter : attributes) {
exprType target = new Attribute(new Name(NodeHelper.KEYWORD_SELF, Name.Load, false), new NameTok(adapter.getName(), NameTok.Attrib), Attribute.Store);
Assign initParam1 = new Assign(new exprType[] { target }, new Name(nodeHelper.getPublicAttr(adapter.getName()), Name.Load, false), null);
Assign initParam = initParam1;
body.add(initParam);
}
// create function def
return new FunctionDef(new NameTok(NodeHelper.KEYWORD_INIT, NameTok.FunctionName), args, body.toArray(new stmtType[0]), null, null, false);
}
use of org.python.pydev.refactoring.ast.adapters.INodeAdapter in project Pydev by fabioz.
the class MockupGeneratePropertiesRequestProcessor method getRefactoringRequests.
@Override
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, ""));
}
List<GeneratePropertiesRequest> requests = new ArrayList<GeneratePropertiesRequest>();
GeneratePropertiesRequest req;
for (INodeAdapter elem : attributes) {
req = new GeneratePropertiesRequest(clazz, elem, properties, methodOffsetStrategy, propertyOffsetStrategy, accessModifier, new AdapterPrefs("\n", new IGrammarVersionProvider() {
@Override
public int getGrammarVersion() throws MisconfigurationException {
return IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_2_7;
}
@Override
public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() throws MisconfigurationException {
return null;
}
}));
requests.add(req);
}
return requests;
}
Aggregations