use of org.python.pydev.parser.visitors.scope.ASTEntry in project Pydev by fabioz.
the class IOUtils method addAstInfo.
/**
* Adds ast info information for a module.
*
* @param m the module we want to add to the info
*/
public List<IInfo> addAstInfo(SimpleNode node, ModulesKey key, boolean generateDelta) {
List<IInfo> createdInfos = new ArrayList<IInfo>();
if (node == null || key.name == null) {
return createdInfos;
}
try {
Tuple<DefinitionsASTIteratorVisitor, Iterator<ASTEntry>> tup = getInnerEntriesForAST(node);
if (DebugSettings.DEBUG_ANALYSIS_REQUESTS) {
org.python.pydev.shared_core.log.ToLogFile.toLogFile(this, "Adding ast info to: " + key.name);
}
try {
Iterator<ASTEntry> entries = tup.o2;
FastStack<SimpleNode> tempStack = new FastStack<SimpleNode>(10);
synchronized (this.lock) {
synchronized (ObjectsInternPool.lock) {
final String file = key.file != null ? ObjectsInternPool.internUnsynched(key.file.toString()) : null;
key.name = ObjectsInternPool.internUnsynched(key.name);
while (entries.hasNext()) {
ASTEntry entry = entries.next();
IInfo infoCreated = null;
if (entry.parent == null) {
// we only want those that are in the global scope
if (entry.node instanceof ClassDef) {
// no intern construct (locked in this loop)
NameTok name = (NameTok) ((ClassDef) entry.node).name;
ClassInfo info = new ClassInfo(ObjectsInternPool.internUnsynched(name.id), key.name, null, false, getNature(), file, name.beginLine, name.beginColumn);
add(info, TOP_LEVEL);
infoCreated = info;
} else if (entry.node instanceof FunctionDef) {
// no intern construct (locked in this loop)
NameTok name = (NameTok) ((FunctionDef) entry.node).name;
FuncInfo info2 = new FuncInfo(ObjectsInternPool.internUnsynched(name.id), key.name, null, false, getNature(), file, name.beginLine, name.beginColumn);
add(info2, TOP_LEVEL);
infoCreated = info2;
} else {
// it is an assign
infoCreated = this.addAssignTargets(entry, key.name, TOP_LEVEL, null, false, file);
}
} else {
if (entry.node instanceof ClassDef || entry.node instanceof FunctionDef) {
// ok, it has a parent, so, let's check to see if the path we got only has class definitions
// as the parent (and get that path)
Tuple<String, Boolean> pathToRoot = this.getPathToRoot(entry, false, false, tempStack);
if (pathToRoot != null && pathToRoot.o1 != null && pathToRoot.o1.length() > 0) {
if (entry.node instanceof ClassDef) {
NameTok name = ((NameTok) ((ClassDef) entry.node).name);
ClassInfo info = new ClassInfo(ObjectsInternPool.internUnsynched(name.id), key.name, ObjectsInternPool.internUnsynched(pathToRoot.o1), false, getNature(), file, name.beginLine, name.beginColumn);
add(info, INNER);
infoCreated = info;
} else {
// FunctionDef
NameTok name = ((NameTok) ((FunctionDef) entry.node).name);
FuncInfo info2 = new FuncInfo(ObjectsInternPool.internUnsynched(name.id), key.name, ObjectsInternPool.internUnsynched(pathToRoot.o1), false, getNature(), file, name.beginLine, name.beginColumn);
add(info2, INNER);
infoCreated = info2;
}
}
} else {
// it is an assign
Tuple<String, Boolean> pathToRoot = this.getPathToRoot(entry, true, false, tempStack);
if (pathToRoot != null && pathToRoot.o1 != null && pathToRoot.o1.length() > 0) {
infoCreated = this.addAssignTargets(entry, key.name, INNER, pathToRoot.o1, pathToRoot.o2, file);
}
}
}
if (infoCreated != null) {
createdInfos.add(infoCreated);
}
}
// end while
}
// end lock ObjectsPool.lock
}
// end this.lock
} catch (Exception e) {
Log.log(e);
}
} catch (Exception e) {
Log.log(e);
}
return createdInfos;
}
use of org.python.pydev.parser.visitors.scope.ASTEntry in project Pydev by fabioz.
the class IOUtils method getInnerEntriesForAST.
/**
* @return an iterator that'll get the outline entries for the given ast.
*/
public static Tuple<DefinitionsASTIteratorVisitor, Iterator<ASTEntry>> getInnerEntriesForAST(SimpleNode node) throws Exception {
DefinitionsASTIteratorVisitor visitor = new DefinitionsASTIteratorVisitor();
node.accept(visitor);
Iterator<ASTEntry> entries = visitor.getOutline();
return new Tuple<DefinitionsASTIteratorVisitor, Iterator<ASTEntry>>(visitor, entries);
}
use of org.python.pydev.parser.visitors.scope.ASTEntry in project Pydev by fabioz.
the class TddCodeGenerationQuickFixParticipant method checkInitCreation.
private boolean checkInitCreation(PyEdit edit, PySelection callPs, ItemPointer[] pointers, List<ICompletionProposalHandle> ret) {
for (ItemPointer pointer : pointers) {
Definition definition = pointer.definition;
if (definition != null && definition.ast instanceof ClassDef) {
ClassDef d = (ClassDef) definition.ast;
ASTEntry initEntry = findInitInClass(d);
if (initEntry == null) {
// Give the user a chance to create the __init__.
PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
pyCreateMethod.setCreateAs(PyCreateMethodOrField.BOUND_METHOD);
String className = NodeUtils.getRepresentationString(d);
pyCreateMethod.setCreateInClass(className);
List<String> parametersAfterCall = callPs.getParametersAfterCall(callPs.getAbsoluteCursorOffset());
String displayString = StringUtils.format("Create %s __init__ (%s)", className, definition.module.getName());
TddRefactorCompletionInModule completion = new TddRefactorCompletionInModule("__init__", tddQuickFixParticipant.imageMethod, displayString, null, displayString, IPyCompletionProposal.PRIORITY_CREATE, edit, definition.module.getFile(), parametersAfterCall, pyCreateMethod, callPs);
completion.locationStrategy = AbstractPyCreateAction.LOCATION_STRATEGY_FIRST_METHOD;
ret.add(completion);
return true;
}
}
}
return false;
}
use of org.python.pydev.parser.visitors.scope.ASTEntry in project Pydev by fabioz.
the class AbstractRenameRefactorProcessTest method createString.
private void createString(List<ASTEntry> initial) {
ASTEntry entry = new ASTEntry(null);
entry.setAdditionalInfo(AstEntryScopeAnalysisConstants.AST_ENTRY_FOUND_LOCATION, AstEntryScopeAnalysisConstants.AST_ENTRY_FOUND_IN_STRING);
add(entry, initial);
}
use of org.python.pydev.parser.visitors.scope.ASTEntry in project Pydev by fabioz.
the class AbstractRenameRefactorProcessTest method createComment.
private void createComment(List<ASTEntry> initial) {
ASTEntry entry = new ASTEntry(null);
entry.setAdditionalInfo(AstEntryScopeAnalysisConstants.AST_ENTRY_FOUND_LOCATION, AstEntryScopeAnalysisConstants.AST_ENTRY_FOUND_IN_COMMENT);
add(entry, initial);
}
Aggregations