use of org.python.pydev.shared_core.string.FullRepIterable in project Pydev by fabioz.
the class FullRepIterableTest method testiterator2.
public void testiterator2() {
Iterator iterator = new FullRepIterable("var1").iterator();
assertTrue(iterator.hasNext());
assertEquals("var1", iterator.next());
assertFalse(iterator.hasNext());
}
use of org.python.pydev.shared_core.string.FullRepIterable in project Pydev by fabioz.
the class FullRepIterableTest method testiterator3.
public void testiterator3() {
Iterator iterator = new FullRepIterable("testlib.unittest.relative").iterator();
assertTrue(iterator.hasNext());
assertEquals("testlib", iterator.next());
assertEquals("testlib.unittest", iterator.next());
assertEquals("testlib.unittest.relative", iterator.next());
assertFalse(iterator.hasNext());
int i = 0;
for (String dummy : new FullRepIterable("testlib.unittest.relative")) {
i++;
}
assertEquals(3, i);
}
use of org.python.pydev.shared_core.string.FullRepIterable in project Pydev by fabioz.
the class FullRepIterableTest method testiterator2Rev.
public void testiterator2Rev() {
Iterator iterator = new FullRepIterable("var1", true).iterator();
assertTrue(iterator.hasNext());
assertEquals("var1", iterator.next());
assertFalse(iterator.hasNext());
}
use of org.python.pydev.shared_core.string.FullRepIterable in project Pydev by fabioz.
the class FullRepIterableTest method testiterator3Rev.
public void testiterator3Rev() {
Iterator iterator = new FullRepIterable("testlib.unittest.relative", true).iterator();
assertTrue(iterator.hasNext());
assertEquals("testlib.unittest.relative", iterator.next());
assertEquals("testlib.unittest", iterator.next());
assertEquals("testlib", iterator.next());
assertFalse(iterator.hasNext());
int i = 0;
for (String dummy : new FullRepIterable("testlib.unittest.relative")) {
i++;
}
assertEquals(3, i);
}
use of org.python.pydev.shared_core.string.FullRepIterable in project Pydev by fabioz.
the class UndefinedVariableQuickFixCreator method createImportQuickProposalsFromMarkerSelectedText.
public static void createImportQuickProposalsFromMarkerSelectedText(IAdaptable projectAdaptable, PySelection ps, int offset, IPythonNature initialNature, List<ICompletionProposalHandle> props, ICodeCompletionASTManager astManager, int start, int end, boolean forceReparseOnApply) throws BadLocationException {
ps.setSelection(start, end);
String markerContents = ps.getSelectedText();
String fullRep = ps.getFullRepAfterSelection();
IModulesManager projectModulesManager = astManager.getModulesManager();
IModulesManager[] managersInvolved = projectModulesManager.getManagersInvolved(true);
boolean doIgnoreImportsStartingWithUnder = AnalysisPreferences.doIgnoreImportsStartingWithUnder(projectAdaptable);
// Use a single buffer to create all the strings
FastStringBuffer buffer = new FastStringBuffer();
// Helper so that we don't add the same module multiple times.
Set<Tuple<String, String>> mods = new HashSet<Tuple<String, String>>();
for (IModulesManager iModulesManager : managersInvolved) {
Set<String> allModules = iModulesManager.getAllModuleNames(false, markerContents.toLowerCase());
// when an undefined variable is found, we can:
// - add an auto import (if it is a class or a method or some global attribute)
// - declare it as a local or global variable
// - change its name to some other global or local (mistyped)
// - create a method or class for it (if it is a call)
// 1. check if it is some module
CompareContext compareContext = new CompareContext(iModulesManager.getNature());
for (String completeName : allModules) {
FullRepIterable iterable = new FullRepIterable(completeName);
for (String mod : iterable) {
if (fullRep.startsWith(mod)) {
if (// it does not only start with, but it is equal to it.
fullRep.length() == mod.length() || (fullRep.length() > mod.length() && fullRep.charAt(mod.length()) == '.')) {
buffer.clear();
String realImportRep = buffer.append("import ").append(mod).toString();
buffer.clear();
String displayString = buffer.append("Import ").append(mod).toString();
addProp(props, realImportRep, displayString, IInfo.USE_PACKAGE_ICON, offset, mods, compareContext, forceReparseOnApply);
}
}
String[] strings = FullRepIterable.headAndTail(mod);
String packageName = strings[0];
String importRep = strings[1];
if (importRep.equals(markerContents)) {
if (packageName.length() > 0) {
buffer.clear();
String realImportRep = buffer.append("from ").append(packageName).append(" ").append("import ").append(strings[1]).toString();
buffer.clear();
String displayString = buffer.append("Import ").append(importRep).append(" (").append(packageName).append(")").toString();
addProp(props, realImportRep, displayString, IInfo.USE_PACKAGE_ICON, offset, mods, compareContext, forceReparseOnApply);
} else {
buffer.clear();
String realImportRep = buffer.append("import ").append(strings[1]).toString();
buffer.clear();
String displayString = buffer.append("Import ").append(importRep).toString();
addProp(props, realImportRep, displayString, IInfo.USE_PACKAGE_ICON, offset, mods, compareContext, forceReparseOnApply);
}
}
}
}
}
// 2. check if it is some global class or method
List<AbstractAdditionalTokensInfo> additionalInfo;
try {
additionalInfo = AdditionalProjectInterpreterInfo.getAdditionalInfo(initialNature);
} catch (MisconfigurationException e) {
return;
}
FastStringBuffer tempBuf = new FastStringBuffer();
for (AbstractAdditionalTokensInfo info : additionalInfo) {
Collection<IInfo> tokensEqualTo = info.getTokensEqualTo(markerContents, AbstractAdditionalTokensInfo.TOP_LEVEL);
for (IInfo found : tokensEqualTo) {
// there always is a declaring module
String name = found.getName();
String declPackage = found.getDeclaringModuleName();
String declPackageWithoutInit = declPackage;
if (declPackageWithoutInit.endsWith(".__init__")) {
declPackageWithoutInit = declPackageWithoutInit.substring(0, declPackageWithoutInit.length() - 9);
}
declPackageWithoutInit = AnalysisPreferences.removeImportsStartingWithUnderIfNeeded(declPackageWithoutInit, tempBuf, doIgnoreImportsStartingWithUnder);
buffer.clear();
String importDeclaration = buffer.append("from ").append(declPackageWithoutInit).append(" import ").append(name).toString();
buffer.clear();
String displayImport = buffer.append("Import ").append(name).append(" (").append(declPackage).append(")").toString();
addProp(props, importDeclaration, displayImport, found.getType(), offset, mods, new CompareContext(found.getNature()), forceReparseOnApply);
}
}
}
Aggregations