Update of /cvsroot/cpptool/rfta/src/eclipseplugin/PluginCode/src/org/eclipse/cpprefactoring/internal In directory sc8-pr-cvs1:/tmp/cvs-serv31495/org/eclipse/cpprefactoring/internal Added Files: RefactoringTextDocumentProvider.java RefactoringSourceRange.java EclipseBridge.java Log Message: Eclipse Plugin JAVA code --- NEW FILE: RefactoringTextDocumentProvider.java --- package org.eclipse.cpprefactoring.internal; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; /** * @author Andre Baresel * * */ public class RefactoringTextDocumentProvider { /** * Constructor RefactoringTextDocumentProvider. * @param iDocument * @param selectionProvider */ public RefactoringTextDocumentProvider( IDocument iDocument, ISelectionProvider selectionProvider) { this.doc = iDocument; this.selectionProvider = selectionProvider; } public String getAllText() { return doc.get(); } /*! Gets the selected text. * \return Selected text. EOL are in the original text format. */ public String getSelection() { ISelection sel = selectionProvider.getSelection(); if (sel instanceof ITextSelection) { ITextSelection textsel = (ITextSelection)sel; return textsel.getText(); } else return ""; } /*! Replace current selection text with the specified text. * \param text The selection is replaced with that text. If no * text is selected, then the specified text is * inserted at the selection location. */ public void replaceSelection( String text ) { try { ISelection sel = selectionProvider.getSelection(); if (sel instanceof ITextSelection) { ITextSelection textsel = (ITextSelection)sel; doc.replace(textsel.getOffset(),textsel.getLength(),text); } } catch (BadLocationException e) { System.out.println("Debugging: BadLocationException is not handled yet.\n"); } } /*! Gets the selected range. * \return The location range of the selection. */ public RefactoringSourceRange getSelectionRange() { ISelection sel = selectionProvider.getSelection(); if (sel instanceof ITextSelection) { ITextSelection textsel = (ITextSelection)sel; return new RefactoringSourceRange(textsel.getOffset(),textsel.getLength()); // sourcerange ! } else return new RefactoringSourceRange(); // sourcerange ! } /*! Select a specified range of text. * Line and column are zero-based. * \param selection start and length of the selection. */ public void setSelectionRange( RefactoringSourceRange selection ) { TextSelection sel = new TextSelection(doc,selection.startIndex_,selection.length_); selectionProvider.setSelection(sel); } /*! Move to a specific location. * Set the selection to an empty selection at the specified location. * Equivalent to selectText( range(to, 0) ). * \param toLocation Location the next setSelectedText() operation will insert * text at. */ public void moveTo( int toLocation ) { TextSelection sel = new TextSelection(doc,toLocation,0); selectionProvider.setSelection(sel); } private IDocument doc; private ISelectionProvider selectionProvider; } --- NEW FILE: RefactoringSourceRange.java --- package org.eclipse.cpprefactoring.internal; /** * @author Andre Baresel * * this is a very simple data type for the 'RefactoringTextDocumentProvider'. * we allow public access and no getter and setter will be written because * this class is only used to pass a structured data type between java and c++. */ public class RefactoringSourceRange { /** * Constructor RefactoringSourceRange. * @param start * @param len */ public RefactoringSourceRange(int start, int len) { startIndex_ = start; length_ = len; } /** * Constructor RefactoringSourceRange. */ public RefactoringSourceRange() { startIndex_ = -1; length_ = -1; } public int startIndex_; public int length_; } --- NEW FILE: EclipseBridge.java --- package org.eclipse.cpprefactoring.internal; import org.eclipse.core.runtime.Path; import org.eclipse.cpprefactoring.RefactorPluginMain; import org.eclipse.cpprefactoring.ui.RenameLocalVariableDialog; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.text.IRewriteTarget; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.window.Window; /** * @author Andre Baresel * * To change this generated comment edit the template variable "typecomment": * Window>Preferences>Java>Templates. * To enable and disable the creation of type comments go to * Window>Preferences>Java>Code Generation. */ public class EclipseBridge { static { // currently class loader does load the release version // of all DLLs. Maybe we should add a plugin class variable // the enables debug version to be executed. However I don't // know yet, if it's possible to debug a DLL started from the // JAVA VM. try { RefactorPluginMain dft = RefactorPluginMain.getDefault(); /** * TO DEBUG THE CPP-CODE: * String eclipseplugin = "eclipseplugin_d"; String rfta_file = dft.find(new Path("rfta_mdd.ext")).getFile(); String rftaparser_file = dft.find(new Path("rftaparser_mdd.ext")).getFile(); String cppunit_file = dft.find(new Path("cppunitd_dll.dll")).getFile(); System.load(cppunit_file); * **/ /** * TO RUN THE RELEASE VERSION OF CPP CODE: */ String eclipseplugin = "eclipseplugin"; String rfta_file = dft.find(new Path("rfta_mdr.ext")).getFile(); String rftaparser_file = dft.find(new Path("rftaparser_mdr.ext")).getFile(); // load the DLLs in the correct ordering, so that windows // does not try to find any depended DLL in the path. this will fail, // because the plugin directory (where the files are placed) is // not in the path. System.load(rftaparser_file); System.load(rfta_file); System.loadLibrary(eclipseplugin); // dll created by C++ project } catch (UnsatisfiedLinkError e1) { System.out.println("Path: "+ System.getProperty("java.library.path")); e1.printStackTrace(); throw e1; } } /** * does provide access to the selection in active editor */ private ISelectionProvider selectionProvider; private RefactoringTextDocumentProvider docProvider; /** * does provide write access to the editor contents. */ private IRewriteTarget targetDoc; public EclipseBridge(ISelectionProvider selectionProvider,IRewriteTarget targetDoc) { this.selectionProvider = selectionProvider; this.targetDoc = targetDoc; docProvider = new RefactoringTextDocumentProvider(targetDoc.getDocument(),selectionProvider); LogMessage("Refactoring-PlugIn is starting...\n"); } public void LogMessage(String message) { System.out.println(message); } /** * Implemented in C++ this member accesses 'selectionProvider' and 'targetDoc' * if refactoring was successful */ public native void applyRftaRenameLocaleVariable(Class dialogclass); } |