[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor PythonCompletionProcessor.java,1.6,1.7 PyEd
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-07-19 18:06:26
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14608/src/org/python/pydev/editor Modified Files: PythonCompletionProcessor.java PyEdit.java Log Message: Code folding capabilities added. Index: PyEdit.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/PyEdit.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** PyEdit.java 2 Jul 2004 02:50:38 -0000 1.17 --- PyEdit.java 19 Jul 2004 18:06:17 -0000 1.18 *************** *** 31,35 **** import org.eclipse.ui.PartInitException; import org.eclipse.ui.editors.text.ILocationProvider; - import org.eclipse.ui.editors.text.TextEditor; import org.eclipse.ui.texteditor.DefaultRangeIndicator; import org.eclipse.ui.texteditor.IEditorStatusLine; --- 31,34 ---- *************** *** 42,45 **** --- 41,46 ---- import org.python.parser.TokenMgrError; import org.python.pydev.editor.actions.PyOpenAction; + import org.python.pydev.editor.codefolding.CodeFoldingSetter; + import org.python.pydev.editor.codefolding.PyEditProjection; import org.python.pydev.editor.model.AbstractNode; import org.python.pydev.editor.model.IModelListener; *************** *** 47,51 **** import org.python.pydev.editor.model.ModelMaker; import org.python.pydev.outline.PyOutlinePage; - import org.python.pydev.parser.IParserListener; import org.python.pydev.parser.PyParser; import org.python.pydev.plugin.PydevPlugin; --- 48,51 ---- *************** *** 69,73 **** * */ ! public class PyEdit extends TextEditor implements IParserListener { static public String EDITOR_ID = "org.python.pydev.editor.PythonEditor"; --- 69,73 ---- * */ ! public class PyEdit extends PyEditProjection { static public String EDITOR_ID = "org.python.pydev.editor.PythonEditor"; *************** *** 102,106 **** indentStrategy = (PyAutoIndentStrategy)editConfiguration.getAutoIndentStrategy(null, IDocument.DEFAULT_CONTENT_TYPE); setRangeIndicator(new DefaultRangeIndicator()); // enables standard vertical ruler ! } --- 102,109 ---- indentStrategy = (PyAutoIndentStrategy)editConfiguration.getAutoIndentStrategy(null, IDocument.DEFAULT_CONTENT_TYPE); setRangeIndicator(new DefaultRangeIndicator()); // enables standard vertical ruler ! ! //Added to set the code folding. ! CodeFoldingSetter codeFoldingSetter = new CodeFoldingSetter(this); ! this.addModelListener(codeFoldingSetter); } *************** *** 248,251 **** --- 251,255 ---- sourceViewer.revealRange(offset, length); } + /** Index: PythonCompletionProcessor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/PythonCompletionProcessor.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PythonCompletionProcessor.java 14 Jun 2004 18:52:38 -0000 1.6 --- PythonCompletionProcessor.java 19 Jul 2004 18:06:17 -0000 1.7 *************** *** 7,234 **** package org.python.pydev.editor; - import java.io.IOException; - import java.net.MalformedURLException; - import java.net.URL; - import java.util.ArrayList; - import java.util.List; - import java.util.Properties; - - import org.eclipse.core.runtime.Platform; - import org.eclipse.core.runtime.Plugin; - import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextViewer; - import org.eclipse.jface.text.contentassist.CompletionProposal; import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.text.contentassist.IContextInformation; import org.eclipse.jface.text.contentassist.IContextInformationValidator; - import org.eclipse.swt.graphics.Point; - import org.python.core.PyException; - import org.python.core.PyList; - import org.python.core.PyObject; - import org.python.core.PyString; - import org.python.core.PySystemState; - import org.python.util.PythonInterpreter; - - /** - * @author Dmoore - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ - public class PythonCompletionProcessor implements IContentAssistProcessor { - - /* (non-Javadoc) - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int) - */ - int docBoundary = -1; // the document prior to the activation token - int docBoundary2 = 0; - public ICompletionProposal[] computeCompletionProposals( - ITextViewer viewer, - int documentOffset) { - List propList = new ArrayList(); - IDocument doc = viewer.getDocument(); - // System.out.println("The document:"+doc.get()); - Point selectedRange = viewer.getSelectedRange(); - // there may not be a selected range - java.lang.String theDoc = doc.get(); - calcDocBoundary(theDoc, documentOffset); - String activationToken = this.getActivationToken(theDoc, documentOffset); - // System.out.println("DBG:theActivationToken: "+activationToken); - theDoc = partialDocument(theDoc, documentOffset); - // System.out.println("DBG:theDoc: "+theDoc); - PythonInterpreter interp = initInterpreter(null); - java.lang.String qualifier = getQualifier(doc, documentOffset); - int qlen = qualifier.length(); - try { - System.out.println("Interpreted doc: "+theDoc); - PyList theList = autoComplete(interp, theDoc, activationToken); - PyObject o = new PyObject(); - for (int i = 0; i < theList.__len__(); i++) { - String p = theList.__getitem__(i).toString(); - // System.out.println("Item:" + p); - CompletionProposal proposal = - new CompletionProposal( - p, - documentOffset - qlen, - qlen, - p.length()); - propList.add(proposal); - } - - } catch (PyException e) { - e.printStackTrace(); - } - - PyObject theCode = null; - - ICompletionProposal[] proposals = - new ICompletionProposal[propList.size()]; - // and fill with list elements - propList.toArray(proposals); - // Return the proposals - return proposals; - - } - private PyList autoComplete( - PythonInterpreter interp, - java.lang.String theCode, - java.lang.String theActivationToken) - throws PyException { - StringBuffer example = new StringBuffer(); - interp.exec("from PyDev import jintrospect"); - // System.out.println("DBG:from PyDev import jintrospect:done"); - interp.exec("class object:pass"); //TODO: REMOVE AFTER JYTHON ADDS SUPPORT TO NEW STYLE CLASSES. - interp.exec(theCode); - String xCommand = "theList = jintrospect.getAutoCompleteList(command='"+theActivationToken+"', locals=locals())"; - // System.out.println("DBG:xCommand:"+xCommand); - interp.exec(xCommand); - PyList theList = (PyList) interp.get("theList"); - return theList; - } - - /** - * @param qualifier - * @param documentOffset - * @param proposals - */ - public void calcDocBoundary(String theDoc, int documentOffset){ - this.docBoundary = theDoc.substring(0, documentOffset).lastIndexOf('\n'); - } - public String getActivationToken(String theDoc, int documentOffset) { - if (this.docBoundary < 0){ - calcDocBoundary(theDoc,documentOffset); - } - return theDoc.substring(this.docBoundary+1, documentOffset); - } - - /** - * @param theDoc - */ - private String partialDocument(String theDoc, int documentOffset) { - if (this.docBoundary < 0){ - calcDocBoundary(theDoc,documentOffset); - } - - String before = theDoc.substring(0, this.docBoundary); - return before; - } - /** - * @param doc - * @param documentOffset - */ - private java.lang.String getQualifier(IDocument doc, int documentOffset) { - // this routine should return any partial entry after the activation character - return ""; - } ! /* (non-Javadoc) ! * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int) ! */ ! public IContextInformation[] computeContextInformation( ! ITextViewer viewer, ! int documentOffset) { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() ! */ ! public char[] getCompletionProposalAutoActivationCharacters() { ! return new char[] { '.', '(' , '['}; ! } ! /* (non-Javadoc) ! * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters() ! */ ! public char[] getContextInformationAutoActivationCharacters() { ! // is this _really_ what we want to use?? ! return new char[] { '.' }; ! } ! /* (non-Javadoc) ! * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage() ! */ ! public java.lang.String getErrorMessage() { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator() ! */ ! public IContextInformationValidator getContextInformationValidator() { ! // TODO Auto-generated method stub ! return null; ! } ! // 1. create the PythonSystemState with the embedded $py.class files inserted into its path ! // 2. ! protected PythonInterpreter initInterpreter(java.lang.String[] argv) { ! Properties p = System.getProperties(); ! // p.setProperty("python.path", "c:\\Jython\\Lib"); ! PySystemState.initialize(); ! PythonInterpreter.initialize(System.getProperties(), p, null); ! return new PythonInterpreter(null, createPySystemState()); ! } ! /** ! * Create a new Python interpreter system state object aware for standard ! * Jython library. ! * ! * @return Python interpreter system state. ! * ! * @throws JythonRuntimeException if it fails to locate the Jython ! * libraries. The exception message will contain an explanation of the ! * reason to fail. ! */ ! private String _jythonLib = null; ! public PySystemState createPySystemState() { ! if (_jythonLib == null) { ! // Locate org.jython plugin and grab the jar location ! Plugin jythonPlugin = Platform.getPlugin("org.pydev.jython"); ! String jythonPath = ! jythonPlugin.getDescriptor().getInstallURL().toString() + "jythonlib.jar"; ! try { ! _jythonLib = Platform.asLocalURL(new URL(jythonPath)).getFile(); ! // System.out.println("_jythonLib:"+_jythonLib); ! } catch (MalformedURLException e) { ! System.out.println( ! "Failed to located Python System library because of invalid URL."+ ! e); ! } catch (IOException e) { ! System.out.println( ! "Failed to located Python System library because of IO Error."+ ! e); ! } ! } ! PySystemState result = new PySystemState(); ! result.path.insert(0, new PyString(_jythonLib + "/Lib")); ! // System.out.println("result.path: "+result.path); ! // Location of the jython/python modules ! return result; ! } } --- 7,268 ---- package org.python.pydev.editor; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.jface.text.contentassist.IContextInformation; import org.eclipse.jface.text.contentassist.IContextInformationValidator; ! public class PythonCompletionProcessor implements IContentAssistProcessor { ! /* (non-Javadoc) ! * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int) ! */ ! public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int) ! */ ! public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() ! */ ! public char[] getCompletionProposalAutoActivationCharacters() { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters() ! */ ! public char[] getContextInformationAutoActivationCharacters() { ! // TODO Auto-generated method stub ! return null; ! } ! /* (non-Javadoc) ! * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage() ! */ ! public String getErrorMessage() { ! // TODO Auto-generated method stub ! return null; ! } + /* (non-Javadoc) + * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator() + */ + public IContextInformationValidator getContextInformationValidator() { + // TODO Auto-generated method stub + return null; + } } + ///** + // * @author Dmoore + // * + // * To change the template for this generated type comment go to + // * Window>Preferences>Java>Code Generation>Code and Comments + // */ + //public class PythonCompletionProcessor implements IContentAssistProcessor { + // + // /* (non-Javadoc) + // * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int) + // */ + // int docBoundary = -1; // the document prior to the activation token + // int docBoundary2 = 0; + // public ICompletionProposal[] computeCompletionProposals( + // ITextViewer viewer, + // int documentOffset) { + // List propList = new ArrayList(); + // IDocument doc = viewer.getDocument(); + // // System.out.println("The document:"+doc.get()); + // Point selectedRange = viewer.getSelectedRange(); + // // there may not be a selected range + // java.lang.String theDoc = doc.get(); + // calcDocBoundary(theDoc, documentOffset); + // String activationToken = this.getActivationToken(theDoc, documentOffset); + //// System.out.println("DBG:theActivationToken: "+activationToken); + // theDoc = partialDocument(theDoc, documentOffset); + //// System.out.println("DBG:theDoc: "+theDoc); + // PythonInterpreter interp = initInterpreter(null); + // java.lang.String qualifier = getQualifier(doc, documentOffset); + // int qlen = qualifier.length(); + // try { + // System.out.println("Interpreted doc: "+theDoc); + // PyList theList = autoComplete(interp, theDoc, activationToken); + // PyObject o = new PyObject(); + // for (int i = 0; i < theList.__len__(); i++) { + // String p = theList.__getitem__(i).toString(); + //// System.out.println("Item:" + p); + // CompletionProposal proposal = + // new CompletionProposal( + // p, + // documentOffset - qlen, + // qlen, + // p.length()); + // propList.add(proposal); + // } + // + // } catch (PyException e) { + // e.printStackTrace(); + // } + // + // PyObject theCode = null; + // + // ICompletionProposal[] proposals = + // new ICompletionProposal[propList.size()]; + // // and fill with list elements + // propList.toArray(proposals); + // // Return the proposals + // return proposals; + // + // } + // private PyList autoComplete( + // PythonInterpreter interp, + // java.lang.String theCode, + // java.lang.String theActivationToken) + // throws PyException { + // StringBuffer example = new StringBuffer(); + // interp.exec("from PyDev import jintrospect"); + //// System.out.println("DBG:from PyDev import jintrospect:done"); + // interp.exec("class object:pass"); //TODO: REMOVE AFTER JYTHON ADDS SUPPORT TO NEW STYLE CLASSES. + // interp.exec(theCode); + // String xCommand = "theList = jintrospect.getAutoCompleteList(command='"+theActivationToken+"', locals=locals())"; + //// System.out.println("DBG:xCommand:"+xCommand); + // interp.exec(xCommand); + // PyList theList = (PyList) interp.get("theList"); + // return theList; + // } + // + // /** + // * @param qualifier + // * @param documentOffset + // * @param proposals + // */ + // public void calcDocBoundary(String theDoc, int documentOffset){ + // this.docBoundary = theDoc.substring(0, documentOffset).lastIndexOf('\n'); + // } + // public String getActivationToken(String theDoc, int documentOffset) { + // if (this.docBoundary < 0){ + // calcDocBoundary(theDoc,documentOffset); + // } + // return theDoc.substring(this.docBoundary+1, documentOffset); + // } + // + // /** + // * @param theDoc + // */ + // private String partialDocument(String theDoc, int documentOffset) { + // if (this.docBoundary < 0){ + // calcDocBoundary(theDoc,documentOffset); + // } + // + // String before = theDoc.substring(0, this.docBoundary); + // return before; + // + // } + // + // /** + // * @param doc + // * @param documentOffset + // */ + // private java.lang.String getQualifier(IDocument doc, int documentOffset) { + // // this routine should return any partial entry after the activation character + // return ""; + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int) + // */ + // public IContextInformation[] computeContextInformation( + // ITextViewer viewer, + // int documentOffset) { + // // TODO Auto-generated method stub + // return null; + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() + // */ + // public char[] getCompletionProposalAutoActivationCharacters() { + // return new char[] { '.', '(' , '['}; + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters() + // */ + // public char[] getContextInformationAutoActivationCharacters() { + // // is this _really_ what we want to use?? + // return new char[] { '.' }; + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage() + // */ + // public java.lang.String getErrorMessage() { + // // TODO Auto-generated method stub + // return null; + // } + // + // /* (non-Javadoc) + // * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator() + // */ + // public IContextInformationValidator getContextInformationValidator() { + // // TODO Auto-generated method stub + // return null; + // } + //// 1. create the PythonSystemState with the embedded $py.class files inserted into its path + //// 2. + // protected PythonInterpreter initInterpreter(java.lang.String[] argv) { + // Properties p = System.getProperties(); + //// p.setProperty("python.path", "c:\\Jython\\Lib"); + // PySystemState.initialize(); + // PythonInterpreter.initialize(System.getProperties(), p, null); + // return new PythonInterpreter(null, createPySystemState()); + // } + // /** + // * Create a new Python interpreter system state object aware for standard + // * Jython library. + // * + // * @return Python interpreter system state. + // * + // * @throws JythonRuntimeException if it fails to locate the Jython + // * libraries. The exception message will contain an explanation of the + // * reason to fail. + // */ + // private String _jythonLib = null; + // public PySystemState createPySystemState() { + // if (_jythonLib == null) { + // // Locate org.jython plugin and grab the jar location + // Plugin jythonPlugin = Platform.getPlugin("org.pydev.jython"); + // + // String jythonPath = + // jythonPlugin.getDescriptor().getInstallURL().toString() + "jythonlib.jar"; + // try { + // _jythonLib = Platform.asLocalURL(new URL(jythonPath)).getFile(); + //// System.out.println("_jythonLib:"+_jythonLib); + // } catch (MalformedURLException e) { + // System.out.println( + // "Failed to located Python System library because of invalid URL."+ + // e); + // } catch (IOException e) { + // System.out.println( + // "Failed to located Python System library because of IO Error."+ + // e); + // } + // } + // PySystemState result = new PySystemState(); + // result.path.insert(0, new PyString(_jythonLib + "/Lib")); + //// System.out.println("result.path: "+result.path); + // // Location of the jython/python modules + // return result; + // } + // + //} |