Search in sources :

Example 21 with FastStringBuffer

use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.

the class AbstractInterpreterManager method getStringToPersist.

/**
 * @param executables executables that should be persisted
 * @return string to persist with the passed executables.
 */
public static String getStringToPersist(IInterpreterInfo[] executables) {
    FastStringBuffer buf = new FastStringBuffer();
    for (IInterpreterInfo info : executables) {
        if (info != null) {
            buf.append(info.toString());
            buf.append("&&&&&");
        }
    }
    return buf.toString();
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo)

Example 22 with FastStringBuffer

use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.

the class PythonNature method getVersionAndError.

@Override
public Tuple<String, String> getVersionAndError(boolean translateIfInterpreter) throws CoreException {
    if (project != null) {
        if (versionPropertyCache == null) {
            String storeVersion = getStore().getPropertyFromXml(getPythonProjectVersionQualifiedName());
            if (storeVersion == null) {
                // there is no such property set (let's set it to the default)
                // will set the versionPropertyCache too
                setVersion(getDefaultVersion(false), null);
            } else {
                // now, before returning and setting in the cache, let's make sure it's a valid version.
                if (!IPythonNature.Versions.ALL_VERSIONS_ANY_FLAVOR.contains(storeVersion)) {
                    Log.log("The stored version is invalid (" + storeVersion + "). Setting default.");
                    // will set the versionPropertyCache too
                    setVersion(getDefaultVersion(false), null);
                } else {
                    // Ok, it's correct.
                    versionPropertyCache = storeVersion;
                }
            }
        }
    } else {
        String msg = "Trying to get version without project set. Returning default.";
        Log.log(msg);
        return new Tuple<String, String>(getDefaultVersion(translateIfInterpreter), msg);
    }
    if (versionPropertyCache == null) {
        String msg = "The cached version is null. Returning default.";
        Log.log(msg);
        return new Tuple<String, String>(getDefaultVersion(translateIfInterpreter), msg);
    } else if (!IPythonNature.Versions.ALL_VERSIONS_ANY_FLAVOR.contains(versionPropertyCache)) {
        String msg = "The cached version (" + versionPropertyCache + ") is invalid. Returning default.";
        Log.log(msg);
        return new Tuple<String, String>(getDefaultVersion(translateIfInterpreter), msg);
    }
    if (translateIfInterpreter && versionPropertyCache.endsWith(IPythonNature.Versions.INTERPRETER_VERSION)) {
        Tuple<String, String> split = StringUtils.splitOnFirst(versionPropertyCache, ' ');
        String errorMessage;
        try {
            IInterpreterInfo info = this.getProjectInterpreter();
            String version = info.getVersion();
            if (version != null) {
                return new Tuple<String, String>(IPythonNature.Versions.convertToInternalVersion(new FastStringBuffer(split.o1, 6).append(' '), version), null);
            } else {
                errorMessage = "Unable to get version from interpreter info: " + info.getNameForUI() + " - " + info.getExecutableOrJar();
                Log.log(errorMessage);
            }
        } catch (MisconfigurationException | PythonNatureWithoutProjectException e) {
            Log.log(e);
            errorMessage = e.getMessage();
        }
        return new Tuple<String, String>(split.o1 + " " + "2.7", errorMessage + " (in project: " + getProject() + ")");
    }
    return new Tuple<String, String>(versionPropertyCache, null);
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) MisconfigurationException(org.python.pydev.core.MisconfigurationException) PythonNatureWithoutProjectException(org.python.pydev.core.PythonNatureWithoutProjectException) Tuple(org.python.pydev.shared_core.structure.Tuple)

Example 23 with FastStringBuffer

use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.

the class PythonPathNature method getContributedSourcePath.

/**
 * Gets the source path contributed by plugins.
 *
 * See: http://sourceforge.net/tracker/index.php?func=detail&aid=1988084&group_id=85796&atid=577329
 *
 * @throws CoreException
 */
@SuppressWarnings("unchecked")
private String getContributedSourcePath(IProject project) throws CoreException {
    FastStringBuffer buff = new FastStringBuffer();
    List<IPythonPathContributor> contributors = ExtensionHelper.getParticipants("org.python.pydev.pydev_pythonpath_contrib");
    for (IPythonPathContributor contributor : contributors) {
        String additionalPythonPath = contributor.getAdditionalPythonPath(project);
        if (additionalPythonPath != null && additionalPythonPath.trim().length() > 0) {
            if (buff.length() > 0) {
                buff.append("|");
            }
            buff.append(additionalPythonPath.trim());
        }
    }
    return buff.toString();
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer)

Example 24 with FastStringBuffer

use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.

the class PyAutoIndentStrategy method autoIndentSameAsPrevious.

/**
 * Copies the indentation of the previous line.
 *
 * @param d the document to work on
 * @param text the string that should added to the start of the returned string
 * @param considerEmptyLines whether we should consider empty lines in this function
 * @param c the command to deal with
 *
 * @return a string with text+ the indentation found in the previous line (or previous non-empty line).
 */
private String autoIndentSameAsPrevious(IDocument d, int offset, String text, boolean considerEmptyLines) {
    if (offset == -1 || d.getLength() == 0) {
        return null;
    }
    try {
        // find start of line
        IRegion info = d.getLineInformationOfOffset(offset);
        String line = d.get(info.getOffset(), info.getLength());
        if (!considerEmptyLines) {
            int currLine = d.getLineOfOffset(offset);
            while (PySelection.containsOnlyWhitespaces(line)) {
                currLine--;
                if (currLine < 0) {
                    break;
                }
                info = d.getLineInformation(currLine);
                line = d.get(info.getOffset(), info.getLength());
            }
        }
        int start = info.getOffset();
        // find white spaces
        int end = findEndOfWhiteSpace(d, start, offset);
        FastStringBuffer buf = new FastStringBuffer(text, end - start + 1);
        if (end > start) {
            // append to input
            buf.append(d.get(start, end - start));
        }
        return buf.toString();
    } catch (BadLocationException excp) {
        // stop work
        return null;
    }
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 25 with FastStringBuffer

use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.

the class DiskCache method loadFrom.

/**
 * Loads from a reader a string that was acquired from writeTo.
 * @param objectsPoolMap
 */
public static DiskCache loadFrom(FastBufferedReader reader, ObjectsPoolMap objectsPoolMap) throws IOException {
    DiskCache diskCache = new DiskCache();
    FastStringBuffer line = reader.readLine();
    if (line.startsWith("-- ")) {
        throw new RuntimeException("Unexpected line: " + line);
    }
    diskCache.folderToPersist = line.toString();
    FastStringBuffer buf = new FastStringBuffer();
    CompleteIndexKey key = null;
    char[] internalCharsArray = line.getInternalCharsArray();
    while (true) {
        line = reader.readLine();
        key = null;
        if (line == null || line.startsWith("-- ")) {
            if (line != null && line.startsWith("-- END DISKCACHE")) {
                return diskCache;
            }
            throw new RuntimeException("Unexpected line: " + line);
        } else {
            int length = line.length();
            int part = 0;
            for (int i = 0; i < length; i++) {
                char c = internalCharsArray[i];
                if (c == '|') {
                    switch(part) {
                        case 0:
                            key = new CompleteIndexKey(ObjectsInternPool.internLocal(objectsPoolMap, buf.toString()));
                            diskCache.add(key);
                            break;
                        case 1:
                            key.lastModified = org.python.pydev.shared_core.string.StringUtils.parsePositiveLong(buf);
                            break;
                        case 2:
                            if (buf.length() > 0) {
                                key.key.file = new File(ObjectsInternPool.internLocal(objectsPoolMap, buf.toString()));
                            }
                            break;
                        case 3:
                            // regular folder path or zip path
                            if (buf.endsWith("|^")) {
                                key.key = new ModulesKeyForFolder(key.key.name, key.key.file);
                            } else {
                                key.key = new ModulesKeyForZip(key.key.name, key.key.file, ObjectsInternPool.internLocal(objectsPoolMap, buf.toString()), true);
                            }
                            break;
                        case 4:
                            // isfile in zip
                            if (buf.toString().equals("0")) {
                                ((ModulesKeyForZip) key.key).isFile = true;
                            }
                            break;
                        default:
                            throw new RuntimeException("Unexpected part in line: " + line);
                    }
                    part++;
                    buf.clear();
                } else {
                    buf.append(c);
                }
            }
            // Found end of line... this is the last part and depends on where we stopped previously.
            if (buf.length() > 0) {
                switch(part) {
                    case 1:
                        key.lastModified = StringUtils.parsePositiveLong(buf);
                        break;
                    case 2:
                        // File also written.
                        key.key.file = new File(ObjectsInternPool.internLocal(objectsPoolMap, buf.toString()));
                        break;
                    case 3:
                        // path in zip
                        key.key = new ModulesKeyForZip(key.key.name, key.key.file, ObjectsInternPool.internLocal(objectsPoolMap, buf.toString()), true);
                        break;
                    case 4:
                        // isfile in zip
                        if (buf.toString().equals("0")) {
                            ((ModulesKeyForZip) key.key).isFile = true;
                        }
                        break;
                }
                buf.clear();
            }
        }
    }
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) ModulesKeyForZip(org.python.pydev.core.ModulesKeyForZip) File(java.io.File) ModulesKeyForFolder(org.python.pydev.core.ModulesKeyForFolder)

Aggregations

FastStringBuffer (org.python.pydev.shared_core.string.FastStringBuffer)300 ArrayList (java.util.ArrayList)32 Tuple (org.python.pydev.shared_core.structure.Tuple)26 File (java.io.File)25 IOException (java.io.IOException)20 CoreException (org.eclipse.core.runtime.CoreException)19 MisconfigurationException (org.python.pydev.core.MisconfigurationException)18 IDocument (org.eclipse.jface.text.IDocument)16 SimpleNode (org.python.pydev.parser.jython.SimpleNode)15 Document (org.eclipse.jface.text.Document)14 HashSet (java.util.HashSet)13 IFile (org.eclipse.core.resources.IFile)13 BadLocationException (org.eclipse.jface.text.BadLocationException)12 HashMap (java.util.HashMap)11 List (java.util.List)10 IRegion (org.eclipse.jface.text.IRegion)10 ModulesKey (org.python.pydev.core.ModulesKey)10 ParseException (org.python.pydev.parser.jython.ParseException)10 Entry (java.util.Map.Entry)9 IPythonNature (org.python.pydev.core.IPythonNature)9