[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/correctionassist PythonCorrectionProcessor.
Brought to you by:
fabioz
|
From: Fabio Z. <fa...@us...> - 2005-02-16 16:49:02
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/correctionassist In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9724/src/org/python/pydev/editor/correctionassist Modified Files: PythonCorrectionProcessor.java Log Message: Code completion improvement Index: PythonCorrectionProcessor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/correctionassist/PythonCorrectionProcessor.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PythonCorrectionProcessor.java 13 Jan 2005 15:09:24 -0000 1.10 --- PythonCorrectionProcessor.java 16 Feb 2005 16:48:48 -0000 1.11 *************** *** 24,27 **** --- 24,30 ---- import org.python.pydev.editor.model.FunctionNode; import org.python.pydev.editor.model.ModelUtils; + import org.python.pydev.plugin.PydevPlugin; + import org.python.pydev.ui.ImageCache; + import org.python.pydev.ui.UIConstants; /** *************** *** 66,69 **** --- 69,73 ---- private PyEdit edit; + private ImageCache imageCache; /** *************** *** 72,75 **** --- 76,80 ---- public PythonCorrectionProcessor(PyEdit edit) { this.edit = edit; + this.imageCache = new ImageCache(PydevPlugin.getDefault().getBundle().getEntry("/")); } *************** *** 156,163 **** finall += "pass"; ! l.add(new CompletionProposal(except, start, end-start, excRelNewPos, null, "Surround with try..except", null, null)); ! l.add(new CompletionProposal(finall, start, end-start, finRelNewPos, null, "Surround with try..finally", null, null)); --- 161,168 ---- finall += "pass"; ! l.add(new CompletionProposal(except, start, end-start, excRelNewPos, imageCache.get(UIConstants.ASSIST_TRY_EXCEPT), "Surround with try..except", null, null)); ! l.add(new CompletionProposal(finall, start, end-start, finRelNewPos, imageCache.get(UIConstants.ASSIST_TRY_FINNALLY), "Surround with try..finally", null, null)); *************** *** 180,185 **** String delimiter = PyAction.getDelimiter(ps.doc, 0); if(i != -1){ ! l.add(new FixCompletionProposal(sel+delimiter, 0, 0, ps.startLine.getOffset(), null, "Move import to global scope", null, null, ps.startLineIndex+1)); } --- 185,203 ---- String delimiter = PyAction.getDelimiter(ps.doc, 0); + int lineToMoveImport = 0; + int lines = ps.doc.getNumberOfLines(); + for (int line = 0; line < lines; line++) { + String str = ps.getLine(line); + if(str.startsWith("import")){ + lineToMoveImport = line; + break; + } + } + + int offset = ps.doc.getLineOffset(lineToMoveImport+1); + + if(i != -1){ ! l.add(new FixCompletionProposal(sel+delimiter, offset, 0, ps.startLine.getOffset(), imageCache.get(UIConstants.ASSIST_MOVE_IMPORT), "Move import to global scope", null, null, ps.startLineIndex+1)); } *************** *** 238,246 **** } ! l.add(new FixCompletionProposal(cls, newPos, 0, cls.length()+1, null, "Make this a new class", null, null, ps.startLineIndex+4)); method = method.replaceFirst("%s", ""); ! l.add(new FixCompletionProposal(method, newPos, 0, method.length()+1, null, "Make this a new method", null, null, ps.startLineIndex+2)); --- 256,264 ---- } ! l.add(new FixCompletionProposal(cls, newPos, 0, cls.length()+1, imageCache.get(UIConstants.ASSIST_NEW_CLASS), "Make this a new class", null, null, ps.startLineIndex+4)); method = method.replaceFirst("%s", ""); ! l.add(new FixCompletionProposal(method, newPos, 0, method.length()+1, imageCache.get(UIConstants.ASSIST_NEW_METHOD), "Make this a new method", null, null, ps.startLineIndex+2)); *************** *** 287,291 **** method = method.replaceFirst("%s", self); ! l.add(new CompletionProposal(method, newPos, 0, method.length()-4, null, "Create new method (in class)", null, null)); } --- 305,309 ---- method = method.replaceFirst("%s", self); ! l.add(new CompletionProposal(method, newPos, 0, method.length()-4, imageCache.get(UIConstants.ASSIST_NEW_METHOD), "Create new method (in class)", null, null)); } *************** *** 312,321 **** finalMethod = finalMethod.replaceFirst("%s", "" ); ! l.add(new CompletionProposal(finalMethod, newPos, 0, finalMethod.length(), null, "Create new method (in global context)", null, null)); cls = cls+delim; ! l.add(new CompletionProposal(cls, newPos, 0, cls.length(), null, "Create new class (in global context)", null, null)); --- 330,339 ---- finalMethod = finalMethod.replaceFirst("%s", "" ); ! l.add(new CompletionProposal(finalMethod, newPos, 0, finalMethod.length(), imageCache.get(UIConstants.ASSIST_NEW_METHOD), "Create new method (in global context)", null, null)); cls = cls+delim; ! l.add(new CompletionProposal(cls, newPos, 0, cls.length(), imageCache.get(UIConstants.ASSIST_NEW_CLASS), "Create new class (in global context)", null, null)); *************** *** 345,349 **** method = method.replaceFirst("%s", "self"); } ! l.add(new FixCompletionProposal(method, newPos, 0, method.length()+1, null, "Make this a new method (in class)", null, null, ps.startLineIndex+3)); --- 363,367 ---- method = method.replaceFirst("%s", "self"); } ! l.add(new FixCompletionProposal(method, newPos, 0, method.length()+1, imageCache.get(UIConstants.ASSIST_NEW_METHOD), "Make this a new method (in class)", null, null, ps.startLineIndex+3)); *************** *** 400,406 **** if(callName.length() > 0){ //all that just to change first char to lower case. ! char[] ds = callName.toCharArray(); ! ds[0] = (""+ds[0]).toLowerCase().charAt(0); ! callName = new String(ds); }else{ callName = "result"; --- 418,426 ---- if(callName.length() > 0){ //all that just to change first char to lower case. ! callName = lowerChar(callName, 0); ! if (callName.startsWith("get")){ ! callName = callName.substring(3); ! callName = lowerChar(callName, 0); ! } }else{ callName = "result"; *************** *** 409,420 **** int firstCharPosition = PyAction.getFirstCharPosition(ps.doc, ps.absoluteCursorOffset); callName += " = "; ! l.add(new CompletionProposal(callName, firstCharPosition, 0, 0, null, "Assign to new local variable", null, null)); ! l.add(new CompletionProposal("self." + callName, firstCharPosition, 0, 5, null, "Assign to new field", null, null)); } return l; } /** --- 429,447 ---- int firstCharPosition = PyAction.getFirstCharPosition(ps.doc, ps.absoluteCursorOffset); callName += " = "; ! l.add(new CompletionProposal(callName, firstCharPosition, 0, 0, imageCache.get(UIConstants.ASSIST_ASSIGN_TO_LOCAL), "Assign to new local variable", null, null)); ! l.add(new CompletionProposal("self." + callName, firstCharPosition, 0, 5, imageCache.get(UIConstants.ASSIST_ASSIGN_TO_CLASS), "Assign to new field", null, null)); } return l; } + + private String lowerChar(String s, int pos){ + char[] ds = s.toCharArray(); + ds[pos] = (""+ds[pos]).toLowerCase().charAt(0); + return new String(ds); + } + /** |