Search in sources :

Example 96 with FastStringBuffer

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

the class CommentBlocksPreferences method updateMulti.

private void updateMulti(String val) {
    FastStringBuffer buf = new FastStringBuffer(200);
    if (val.length() == 0) {
        buf.append("Invalid");
        buf.appendN(' ', 23);
        buf.append('\n');
        buf.appendN(' ', 30);
        buf.append('\n');
        buf.appendN(' ', 30);
    } else {
        buf.append("#");
        // Use only the pos 0!
        buf.appendN(val.charAt(0), 26);
        buf.append("\n# my multi block");
        buf.append("\n#");
        buf.appendN(val.charAt(0), 26);
    }
    labelMulti.setText("Result:\n" + buf.toString() + "\n\n\n");
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer)

Example 97 with FastStringBuffer

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

the class CommentBlocksPreferences method updateSingle.

private void updateSingle(String val, boolean alignToRight) {
    FastStringBuffer buf = new FastStringBuffer(200);
    if (val.length() == 0) {
        buf.append("Invalid");
        buf.appendN(' ', 23);
    } else {
        // Use only the pos 0!
        buf.appendN(val.charAt(0), 10);
        if (alignToRight) {
            buf.append(" my single block");
        } else {
            buf.insert(0, " my single block ");
        }
        buf.insert(0, '#');
    }
    labelSingle.setText("Result:\n" + buf.toString());
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer)

Example 98 with FastStringBuffer

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

the class IgnoreCompletionProposalInSameLine method apply.

@Override
public void apply(IDocument document) {
    String messageToIgnore = fReplacementString;
    FastStringBuffer strToAdd = new FastStringBuffer(messageToIgnore, 5);
    int lineLen = line.length();
    int endLineIndex = ps.getEndLineOffset();
    boolean isComment = ParsingUtils.isCommentPartition(document, endLineIndex);
    int whitespacesAtEnd = 0;
    char c = '\0';
    for (int i = lineLen - 1; i >= 0; i--) {
        c = line.charAt(i);
        if (c == ' ') {
            whitespacesAtEnd += 1;
        } else {
            break;
        }
    }
    if (isComment) {
        if (whitespacesAtEnd == 0) {
            // it's a comment already, but as it has no spaces in the end, let's add one.
            strToAdd.insert(0, ' ');
        }
    } else {
        FormatStd formatStd = this.format;
        if (formatStd == null) {
            if (edit != null) {
                formatStd = ((PyEdit) edit).getFormatStd();
            } else {
                // Shouldn't happen when not in test mode
                Log.log("Error: using default format (not considering project preferences).");
                formatStd = PyFormatterPreferences.getFormatStd(null);
            }
        }
        strToAdd.insert(0, '#');
        PyFormatter.formatComment(formatStd, strToAdd, true);
        // Just add spaces before the '#' if there's actually some content in the line.
        if (c != '\r' && c != '\n' && c != '\0' && c != ' ') {
            int spacesBeforeComment = formatStd.spacesBeforeComment;
            if (spacesBeforeComment < 0) {
                // If 'manual', add a single space.
                spacesBeforeComment = 1;
            }
            spacesBeforeComment = spacesBeforeComment - whitespacesAtEnd;
            if (spacesBeforeComment > 0) {
                strToAdd.insertN(0, ' ', spacesBeforeComment);
            }
        }
    }
    fReplacementString = strToAdd.toString();
    super.apply(document);
}
Also used : FormatStd(org.python.pydev.core.formatter.FormatStd) FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer)

Example 99 with FastStringBuffer

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

the class AbstractJavaClassModule method createTokens.

/**
 * This method will create the tokens for a given package.
 */
protected CompiledToken[] createTokens(String packagePlusactTok) {
    ArrayList<CompiledToken> lst = new ArrayList<CompiledToken>();
    try {
        // TODO: if we don't want to depend on jdt inner classes, we should create a org.eclipse.jdt.core.CompletionRequestor
        // (it's not currently done because its API is not as easy to handle).
        // we should be able to check the CompletionProposalCollector to see how we can transform the info we want...
        // also, making that change, it should be faster, because we won't need to 1st create a java proposal to then
        // create a pydev token (it would be a single step to transform it from a Completion Proposal to an IToken).
        List<Tuple<IJavaElement, CompletionProposal>> elementsFound = getJavaCompletionProposals(packagePlusactTok, null);
        HashMap<String, IJavaElement> generatedProperties = new HashMap<String, IJavaElement>();
        FastStringBuffer tempBuffer = new FastStringBuffer(128);
        for (Tuple<IJavaElement, CompletionProposal> element : elementsFound) {
            IJavaElement javaElement = element.o1;
            String args = "";
            if (javaElement instanceof IMethod) {
                tempBuffer.clear();
                tempBuffer.append("()");
                IMethod method = (IMethod) javaElement;
                for (String param : method.getParameterTypes()) {
                    if (tempBuffer.length() > 2) {
                        tempBuffer.insert(1, ", ");
                    }
                    // now, let's make the parameter 'pretty'
                    String lastPart = FullRepIterable.getLastPart(param);
                    if (lastPart.length() > 0) {
                        lastPart = PyAction.lowerChar(lastPart, 0);
                        if (lastPart.charAt(lastPart.length() - 1) == ';') {
                            lastPart = lastPart.substring(0, lastPart.length() - 1);
                        }
                    }
                    // we may have to replace it for some other word
                    String replacement = replacementMap.get(lastPart);
                    if (replacement != null) {
                        lastPart = replacement;
                    }
                    tempBuffer.insert(1, lastPart);
                }
                args = tempBuffer.toString();
                String elementName = method.getElementName();
                if (elementName.startsWith("get") || elementName.startsWith("set")) {
                    // Create a property for it
                    tempBuffer.clear();
                    elementName = elementName.substring(3);
                    if (elementName.length() > 0) {
                        tempBuffer.append(Character.toLowerCase(elementName.charAt(0)));
                        tempBuffer.append(elementName.substring(1));
                        String propertyName = tempBuffer.toString();
                        IJavaElement existing = generatedProperties.get(propertyName);
                        if (existing != null) {
                            if (existing.getElementName().startsWith("set")) {
                                // getXXX has precedence over the setXXX.
                                generatedProperties.put(propertyName, javaElement);
                            }
                        } else {
                            generatedProperties.put(propertyName, javaElement);
                        }
                    }
                }
            }
            if (DEBUG_JAVA_COMPLETIONS) {
                System.out.println("Element: " + javaElement);
            }
            lst.add(new JavaElementToken(javaElement.getElementName(), "", args, this.name, getType(javaElement.getElementType()), javaElement, element.o2));
        }
        // Fill our generated properties.
        for (Entry<String, IJavaElement> entry : generatedProperties.entrySet()) {
            IJavaElement javaElement = entry.getValue();
            lst.add(new JavaElementToken(entry.getKey(), "", "", this.name, IToken.TYPE_ATTR, javaElement, PyCodeCompletionImages.getImageForType(IToken.TYPE_ATTR)));
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return lst.toArray(new CompiledToken[lst.size()]);
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) AbstractJavaCompletionProposal(org.eclipse.jdt.internal.ui.text.java.AbstractJavaCompletionProposal) CompletionProposal(org.eclipse.jdt.core.CompletionProposal) IJavaCompletionProposal(org.eclipse.jdt.ui.text.java.IJavaCompletionProposal) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JavaElementToken(org.python.pydev.editor.codecompletion.JavaElementToken) JavaModelException(org.eclipse.jdt.core.JavaModelException) CompiledToken(org.python.pydev.ast.codecompletion.revisited.modules.CompiledToken) IMethod(org.eclipse.jdt.core.IMethod) Tuple(org.python.pydev.shared_core.structure.Tuple)

Example 100 with FastStringBuffer

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

the class AbstractJavaClassModule method getGlobalTokens.

/**
 * @see org.python.pydev.ast.codecompletion.revisited.modules.AbstractModule#getGlobalTokens(java.lang.String)
 */
@Override
public TokensList getGlobalTokens(ICompletionState state, ICodeCompletionASTManager manager) {
    String actTok = state.getFullActivationToken();
    if (actTok == null) {
        actTok = state.getActivationToken();
    }
    if (actTok == null) {
        return new TokensList(new IToken[0]);
    }
    String act = new FastStringBuffer(name, 2 + actTok.length()).append('.').append(actTok).toString();
    return new TokensList(createTokens(act));
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) TokensList(org.python.pydev.core.TokensList)

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