Search in sources :

Example 11 with FastStringBuffer

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

the class TabNanny method createBadIndentForSpacesMessages.

/**
 * Creates the errors that are related to a bad indentation (number of space chars is not ok).
 * @param monitor
 */
private static void createBadIndentForSpacesMessages(IDocument doc, IAnalysisPreferences analysisPrefs, IIndentPrefs indentPrefs, ArrayList<IMessage> ret, List<IndentInfo> validsAre, IProgressMonitor monitor) {
    int tabWidth = indentPrefs.getTabWidth();
    // if we're analyzing the spaces, let's mark invalid indents (tabs are not searched for those because
    // a tab always marks a full indent).
    FastStringBuffer buffer = new FastStringBuffer();
    for (IndentInfo indentation : validsAre) {
        if (monitor.isCanceled()) {
            return;
        }
        if (!indentation.hasNonIndentChars) {
            // if it does not have more contents (its only whitespaces), let's keep on going!
            continue;
        }
        String indentStr = indentation.indent;
        if (indentStr.indexOf("\t") != -1) {
            // the ones that appear in tabs and spaces should not be analyzed here (they'll have their own error messages).
            continue;
        }
        int lenFound = indentStr.length();
        int extraChars = lenFound % tabWidth;
        if (extraChars != 0) {
            Integer offset = indentation.startOffset;
            int startLine = PySelection.getLineOfOffset(doc, offset) + 1;
            int startCol = 1;
            int endCol = startCol + lenFound;
            buffer.clear();
            ret.add(new Message(IAnalysisPreferences.TYPE_INDENTATION_PROBLEM, buffer.append("Bad Indentation (").append(lenFound).append(" spaces)").toString(), startLine, startLine, startCol, endCol, analysisPrefs));
        }
    }
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) IndentInfo(org.python.pydev.core.docutils.TabNannyDocIterator.IndentInfo) Message(org.python.pydev.ast.analysis.messages.Message) IMessage(org.python.pydev.ast.analysis.messages.IMessage)

Example 12 with FastStringBuffer

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

the class Found method toString.

@Override
public String toString() {
    FastStringBuffer buffer = new FastStringBuffer();
    buffer.append("Found { (used:");
    buffer.append(used);
    buffer.append(") [");
    for (GenAndTok g : found) {
        buffer.appendObject(g);
        buffer.append("  ");
    }
    buffer.append(" ]}");
    return buffer.toString();
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer)

Example 13 with FastStringBuffer

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

the class GenAndTok method toString.

@Override
public String toString() {
    FastStringBuffer buffer = new FastStringBuffer();
    buffer.append("GenAndTok [ ");
    buffer.append(generator.getRepresentation());
    buffer.append(" - ");
    buffer.append(tok.getRepresentation());
    buffer.append(" (scopeId:");
    buffer.append(scopeId);
    buffer.append(") ");
    if (references.size() > 0) {
        buffer.append(" (references:");
        for (IToken ref : references) {
            buffer.append(ref.getRepresentation());
            buffer.append(",");
        }
        // remove the last comma
        buffer.deleteLast();
        buffer.append(") ");
    }
    buffer.append("]");
    return buffer.toString();
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) IToken(org.python.pydev.core.IToken)

Example 14 with FastStringBuffer

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

the class TddCodeGenerationQuickFixParticipantTest method testCreate2.

public void testCreate2() throws Exception {
    String s = "" + "class MyClass(object):\n" + "    pass\n" + "def testName():\n" + "    obj = MyClass()\n" + "    obj.unimplementedFunction(a.x, 'Some comment in ticket.')\n" + "";
    TddCodeGenerationQuickFixParticipant participant = new TddCodeGenerationQuickFixParticipant();
    Document doc = new Document(s);
    List<ICompletionProposalHandle> props = participant.getTddProps(new PySelection(doc, s.length() - 1), null, null, nature, null, s.length() - 1, null);
    TddRefactorCompletionInModule proposal = (TddRefactorCompletionInModule) assertContains("Create unimplementedFunction method at MyClass (__module_not_in_the_pythonpath__)", props.toArray(new ICompletionProposalHandle[0]));
    // Todo: check result of apply as string is breaking!
    List<String> parametersAfterCall = proposal.getParametersAfterCall();
    FastStringBuffer createParametersList = AbstractPyCreateClassOrMethodOrField.createParametersList(parametersAfterCall);
    assertEquals("${x}, ${param1}", createParametersList.toString());
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) ICompletionProposalHandle(org.python.pydev.shared_core.code_completion.ICompletionProposalHandle) PySelection(org.python.pydev.core.docutils.PySelection) Document(org.eclipse.jface.text.Document)

Example 15 with FastStringBuffer

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

the class RefactoringRenameTestBase method setUp.

/**
 * In the setUp, it initializes the files in the refactoring project
 * @see com.python.pydev.analysis.refactoring.refactorer.refactorings.renamelocal.RefactoringLocalTestBase#setUp()
 */
@Override
public void setUp() throws Exception {
    super.setUp();
    if (filesInRefactoringProject == null) {
        filesInRefactoringProject = PyFileListing.getPyFilesBelow(new File(TestDependent.TEST_COM_REFACTORING_PYSRC_LOC), new NullProgressMonitor(), true).getFoundPyFileInfos();
        ArrayList<Tuple<List<ModulesKey>, IPythonNature>> iFiles = new ArrayList<Tuple<List<ModulesKey>, IPythonNature>>();
        List<ModulesKey> modules = new ArrayList<ModulesKey>();
        iFiles.add(new Tuple<List<ModulesKey>, IPythonNature>(modules, natureRefactoring));
        FastStringBuffer tempBuf = new FastStringBuffer();
        for (PyFileInfo info : filesInRefactoringProject) {
            File f = info.getFile();
            String modName = info.getModuleName(tempBuf);
            ModulesKey modulesKey = new ModulesKey(modName, f);
            modules.add(modulesKey);
            SourceModule mod = (SourceModule) AbstractModule.createModule(modName, f, natureRefactoring, true);
            // also create the additional info so that it can be used for finds
            AbstractAdditionalTokensInfo additionalInfo = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(natureRefactoring);
            additionalInfo.addAstInfo(mod.getAst(), modulesKey, false);
        }
    // RefactorerFindReferences.FORCED_RETURN = iFiles;
    }
    setUpConfigWorkspaceFiles();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SourceModule(org.python.pydev.ast.codecompletion.revisited.modules.SourceModule) ASTEntryWithSourceModule(org.python.pydev.ast.codecompletion.revisited.modules.ASTEntryWithSourceModule) FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) ArrayList(java.util.ArrayList) IPythonNature(org.python.pydev.core.IPythonNature) ModulesKey(org.python.pydev.core.ModulesKey) List(java.util.List) ArrayList(java.util.ArrayList) PyFileInfo(org.python.pydev.ast.listing_utils.PyFileListing.PyFileInfo) AbstractAdditionalTokensInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Tuple(org.python.pydev.shared_core.structure.Tuple)

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