log("internalGenerateGetCompletionsForModule", module, state);
}
ArrayList<IToken> importedModules = new ArrayList<IToken>();
ILocalScope localScope = null;
int line = state.getLine();
int col = state.getCol();
if (state.getLocalImportsGotten() == false) {
//in the first analyzed module, we have to get the local imports too.
state.setLocalImportsGotten(true);
if (module != null && line >= 0) {
localScope = module.getLocalScope(line, col);
if (localScope != null) {
importedModules.addAll(localScope.getLocalImportedModules(line + 1, col + 1, module.getName()));
}
}
}
IToken[] builtinsCompletions = getBuiltinsCompletions(state);
if (builtinsCompletions != null) {
return builtinsCompletions;
}
String act = state.getActivationToken();
int parI = act.indexOf('(');
if (parI != -1) {
state.setFullActivationToken(act);
act = act.substring(0, parI);
state.setActivationToken(act);
state.setLookingFor(ICompletionState.LOOKING_FOR_INSTANCED_VARIABLE);
}
if (module != null) {
//get the tokens (global, imported and wild imported)
IToken[] globalTokens = module.getGlobalTokens();
List<IToken> tokenImportedModules = Arrays.asList(module.getTokenImportedModules());
importedModules.addAll(tokenImportedModules);
state.setTokenImportedModules(importedModules);
IToken[] wildImportedModules = module.getWildImportedModules();
//now, lets check if this is actually a module that is an __init__ (if so, we have to get all
//the other .py files as modules that are in the same level as the __init__)
Set<IToken> initial = new HashSet<IToken>();
if (searchSameLevelMods) {
//now, we have to ask for the module if it's a 'package' (folders that have __init__.py for python
//or only folders -- not classes -- in java).
if (module.isPackage()) {
HashSet<IToken> gotten = new HashSet<IToken>();
//the module also decides how to get its submodules
getAbsoluteImportTokens(module.getPackageFolderName(), gotten, IToken.TYPE_IMPORT, true, null,
false);
for (IToken token : gotten) {
if (token.getRepresentation().equals("__init__") == false) {
initial.add(token);
}
}
}
}
if (state.getActivationToken().length() == 0) {
List<IToken> completions = getGlobalCompletions(globalTokens,
importedModules.toArray(EMPTY_ITOKEN_ARRAY), wildImportedModules, state, module);
//now find the locals for the module
if (line >= 0) {
IToken[] localTokens = module.getLocalTokens(line, col, localScope);
for (int i = 0; i < localTokens.length; i++) {
completions.add(localTokens[i]);
}
}
completions.addAll(initial); //just add all that are in the same level if it was an __init__
return completions.toArray(EMPTY_ITOKEN_ARRAY);
} else { //ok, we have a token, find it and get its completions.
//first check if the token is a module... if it is, get the completions for that module.
IToken[] tokens = findTokensOnImportedMods(importedModules.toArray(EMPTY_ITOKEN_ARRAY), state, module);
if (tokens != null && tokens.length > 0) {
return decorateWithLocal(tokens, localScope, state);
}
//if it is an __init__, modules on the same level are treated as local tokens
if (searchSameLevelMods) {
tokens = searchOnSameLevelMods(initial, state);
if (tokens != null && tokens.length > 0) {
return decorateWithLocal(tokens, localScope, state);
}
}
//for wild imports, we must get the global completions with __all__ filtered
//wild imports: recursively go and get those completions and see if any matches it.
for (int i = 0; i < wildImportedModules.length; i++) {
IToken name = wildImportedModules[i];
IModule mod = getModule(name.getAsRelativeImport(module.getName()), state.getNature(), false); //relative (for wild imports this is ok... only a module can be used in wild imports)
if (mod == null) {
mod = getModule(name.getOriginalRep(), state.getNature(), false); //absolute
}
if (mod != null) {
state.checkFindModuleCompletionsMemory(mod, state.getActivationToken());
IToken[] completionsForModule = getCompletionsForModule(mod, state);
if (completionsForModule.length > 0)
return decorateWithLocal(completionsForModule, localScope, state);
} else {
//"Module not found:" + name.getRepresentation()
}
}
//it was not a module (would have returned already), so, try to get the completions for a global token defined.
tokens = module.getGlobalTokens(state, this);
if (tokens.length > 0) {
return decorateWithLocal(tokens, localScope, state);
}
//If it was still not found, go to builtins.
IModule builtinsMod = getBuiltinMod(state.getNature());
if (builtinsMod != null && builtinsMod != module) {
tokens = getCompletionsForModule(builtinsMod, state);
if (tokens.length > 0) {
if (tokens[0].getRepresentation().equals("ERROR:") == false) {
return decorateWithLocal(tokens, localScope, state);
}
}
}
if (lookForArgumentCompletion && localScope != null) {
//now, if we have to look for arguments and search things in the local scope, let's also
//check for assert (isinstance...) in this scope with the given variable.
List<String> lookForClass = localScope.getPossibleClassesForActivationToken(state
.getActivationToken());
if (lookForClass.size() > 0) {
HashSet<IToken> hashSet = new HashSet<IToken>();
getCompletionsForClassInLocalScope(module, state, searchSameLevelMods,