Package com.aptana.shared_core.string

Examples of com.aptana.shared_core.string.FastStringBuffer


    protected String getRightAlignedFullCommentLine(String line) {
        Tuple<Integer, Character> colsAndChar = getColsAndChar();
        int cols = colsAndChar.o1;
        char c = colsAndChar.o2;

        FastStringBuffer buffer = makeBufferToIndent(line, cols);
        int lenOfStrWithTabsAsSpaces = getLenOfStrConsideringTabEditorLen(buffer.toString());
        int diff = lenOfStrWithTabsAsSpaces - buffer.length();

        buffer.append("#");
        for (int i = 0; i + line.length() + diff < cols - 2; i++) {
            buffer.append(c);
        }
        buffer.append(" ");
        return buffer.toString();
    }
View Full Code Here


        buffer.append(" ");
        return buffer.toString();
    }

    private FastStringBuffer makeBufferToIndent(String line, int cols) {
        FastStringBuffer buffer = new FastStringBuffer(cols);
        for (int i = 0; i < line.length(); i++) {
            char ch = line.charAt(i);
            if (ch == '\t' || ch == ' ') {
                buffer.append(ch);
            } else {
                break;
            }
        }
        return buffer;
View Full Code Here

            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);
View Full Code Here

            actTok = state.getActivationToken();
        }
        if (actTok == null) {
            return new IToken[0];
        }
        String act = new FastStringBuffer(name, 2 + actTok.length()).append('.').append(actTok).toString();
        return createTokens(act);
    }
View Full Code Here

        //try to see if that's a java class from a package... to do that, we must go iterating through the name found
        //to check if we're able to find modules with that name. If a module with that name is found, that means that
        //we actually have a java class.
        List<String> splitted = StringUtils.dotSplit(state.getActivationToken());
        FastStringBuffer modNameBuf = new FastStringBuffer(this.getName(), 128);
        IModule validModule = null;
        IModule module = null;
        int i = 0; //so that we know what will result in the tok
        for (String s : splitted) {
            modNameBuf.append(".");
            modNameBuf.append(s);
            module = nature.getAstManager().getModule(modNameBuf.toString(), nature, true, false);
            if (module != null) {
                validModule = module;
            } else {
                break;
            }
        }

        modNameBuf.clear();
        FastStringBuffer pathInJavaClass = modNameBuf; //get it cleared
        if (validModule == null) {
            validModule = this;
            pathInJavaClass.clear();
            pathInJavaClass.append(state.getActivationToken());
        } else {
            //After having found a valid java class, we must also check which was the resulting token within that class
            //to check if it's some method or something alike (that should be easy after having the class and the path
            //to the method we want to find within it).
            if (!(validModule instanceof AbstractJavaClassModule)) {
                throw new RuntimeException("The module found from a java class module was found as another kind: "
                        + validModule.getClass());
            }
            for (int j = i; j < splitted.size(); j++) {
                if (j != i) {
                    pathInJavaClass.append('.');
                }
                pathInJavaClass.append(splitted.get(j));
            }
        }

        AbstractJavaClassModule javaClassModule = (AbstractJavaClassModule) validModule;

        IJavaElement elementFound = null;
        String foundAs;
        if (pathInJavaClass.length() == 0) {
            //ok, now, if there is no path, the definition is the java class itself.
            foundAs = "";
            elementFound = findJavaElement(javaClassModule.getName());

        } else {
            //ok, it's not the class directly, so, we have to check what it actually is.
            foundAs = pathInJavaClass.toString();
            List<Tuple<IJavaElement, CompletionProposal>> javaCompletionProposals = getJavaCompletionProposals(
                    javaClassModule.getName(), foundAs);
            if (javaCompletionProposals.size() > 0) {
                elementFound = javaCompletionProposals.get(0).o1;
View Full Code Here

        //delimiter to use
        String delimiter = PyAction.getDelimiter(ps.getDoc());

        //get the 1st char (determines indent)
        FastStringBuffer startIndentBuffer = new FastStringBuffer(firstCharPosition + 1);
        startIndentBuffer.appendN(' ', firstCharPosition);
        final String startIndent = startIndentBuffer.toString();

        //code to be surrounded
        String surroundedCode = selectedText;
        surroundedCode = indentation + surroundedCode.replaceAll(delimiter, delimiter + indentation);
View Full Code Here

        return true;
    }

    private static String getStringToAnalyze(PySelection ps) {
        ParsingUtils parsingUtils = ParsingUtils.create(ps.getDoc());
        FastStringBuffer buf = new FastStringBuffer();
        String string = null;
        try {
            parsingUtils.getFullFlattenedLine(ps.getStartLineOffset(), buf);
            if (buf.length() > 0) {
                string = buf.toString();
            }
        } catch (SyntaxErrorException e) {
            //won't happen (we didn't ask for it)
            Log.log(e);
        }
View Full Code Here

            source = "";
        }
        //we have to work on this one to resolve to full files, as what is stored is the position
        //relative to the project location
        List<String> strings = StringUtils.splitAndRemoveEmptyTrimmed(source, '|');
        FastStringBuffer buf = new FastStringBuffer();

        IWorkspaceRoot root = null;

        ResourcesPlugin resourcesPlugin = ResourcesPlugin.getPlugin();
        for (String currentPath : strings) {
            if (currentPath.trim().length() > 0) {
                IPath p = new Path(currentPath);

                if (resourcesPlugin == null) {
                    //in tests
                    buf.append(currentPath);
                    buf.append("|");
                    continue;
                }

                if (root == null) {
                    root = ResourcesPlugin.getWorkspace().getRoot();
                }

                if (p.segmentCount() < 1) {
                    Log.log("Found no segment in: " + currentPath + " for: " + project);
                    continue; //No segment? Really weird!
                }

                //try to get relative to the workspace
                IContainer container = null;
                IResource r = null;
                try {
                    r = root.findMember(p);
                } catch (Exception e) {
                    Log.log(e);
                }

                if (!(r instanceof IContainer) && !(r instanceof IFile)) {

                    //If we didn't find the file, let's try to sync things, as this can happen if the workspace
                    //is still not properly synchronized.
                    String firstSegment = p.segment(0);
                    IResource firstSegmentResource = root.findMember(firstSegment);
                    if (!(firstSegmentResource instanceof IContainer) && !(firstSegmentResource instanceof IFile)) {
                        //we cannot even get the 1st part... let's do sync
                        long currentTimeMillis = System.currentTimeMillis();
                        if (doFullSynchAt == -1 || currentTimeMillis > doFullSynchAt) {
                            doFullSynchAt = currentTimeMillis + (60 * 2 * 1000); //do a full synch at most once every 2 minutes
                            try {
                                root.refreshLocal(p.segmentCount() + 1, null);
                            } catch (CoreException e) {
                                //ignore
                            }
                        }

                    } else {
                        Long doSynchAt = directMembersChecked.get(firstSegment);
                        long currentTimeMillis = System.currentTimeMillis();
                        if (doSynchAt == null || currentTimeMillis > doFullSynchAt) {
                            directMembersChecked.put(firstSegment, currentTimeMillis + (60 * 2 * 1000));
                            //OK, we can get to the 1st segment, so, let's do a refresh just from that point on, not in the whole workspace...
                            try {
                                firstSegmentResource.refreshLocal(p.segmentCount(), null);
                            } catch (CoreException e) {
                                //ignore
                            }
                        }

                    }

                    //Now, try to get it knowing that it's properly synched (it may still not be there, but at least we tried it)
                    try {
                        r = root.findMember(p);
                    } catch (Exception e) {
                        Log.log(e);
                    }
                }

                if (r instanceof IContainer) {
                    container = (IContainer) r;
                    buf.append(FileUtils.getFileAbsolutePath(container.getLocation().toFile()));
                    buf.append("|");

                } else if (r instanceof IFile) { //zip/jar/egg file
                    String extension = r.getFileExtension();
                    if (extension == null || FileTypesPreferencesPage.isValidZipFile("." + extension) == false) {
                        Log.log("Error: the path " + currentPath + " is a file but is not a recognized zip file.");

                    } else {
                        buf.append(FileUtils.getFileAbsolutePath(r.getLocation().toFile()));
                        buf.append("|");
                    }

                } else {
                    //We're now always making sure that it's all synchronized, so, if we got here, it really doesn't exist (let's warn about it)

                    //Not in workspace?... maybe it was removed, so, let the user know about it (and still add it to the pythonpath as is)
                    Log.log(IStatus.WARNING, "Unable to find the path " + currentPath + " in the project were it's \n"
                            + "added as a source folder for pydev (project: " + project.getName() + ") member:" + r,
                            null);

                    //No good: try to get it relative to the project
                    String curr = currentPath;
                    IPath path = new Path(curr.trim());
                    if (project.getFullPath().isPrefixOf(path)) {
                        path = path.removeFirstSegments(1);
                        if (FileTypesPreferencesPage.isValidZipFile(curr)) {
                            r = project.getFile(path);

                        } else {
                            //get it relative to the project
                            r = project.getFolder(path);
                        }
                        if (r != null) {
                            buf.append(FileUtils.getFileAbsolutePath(r.getLocation().toFile()));
                            buf.append("|");
                            continue; //Don't go on to append it relative to the workspace root.
                        }
                    }

                    //Nothing worked: force it to be relative to the workspace.
                    IPath rootLocation = root.getRawLocation();

                    //Note that this'll be cached for later use.
                    buf.append(FileUtils.getFileAbsolutePath(rootLocation.append(currentPath.trim()).toFile()));
                    buf.append("|");
                }
            }
        }

        if (external == null) {
            external = "";
        }
        return buf.append("|").append(external).append("|").append(contributed).toString();
    }
View Full Code Here

     *
     * @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();
    }
View Full Code Here

    }

    public String getText(Object element) {
        if (element instanceof IFile) {
            IFile f = (IFile) element;
            FastStringBuffer buffer = new FastStringBuffer();
            buffer.append(f.getName());
            buffer.append(" (");
            buffer.append(f.getFullPath().removeFileExtension().removeLastSegments(1).toString());
            buffer.append(")");
            return buffer.toString();
        }
        return provider.getText(element);
    }
View Full Code Here

TOP

Related Classes of com.aptana.shared_core.string.FastStringBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.