@Override public IRegion getHoverRegion(ITextViewer textViewer, int offset) { IDocument document = textViewer.getDocument(); /* Vérifie qu'on est dans une String de KSP */ boolean isSqlString = DocumentUtils.isContentType(document, offset, KspRegionType.STRING); if (!isSqlString) { return null; } /* Extrait le mot courant. */ ITextSelection selection = new TextSelection(document, offset, 0); ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.SNAKE_CASE); if (currentWordSelection == null) { return null; } String currentWord = currentWordSelection.getText(); if (currentWord == null) { return null; } /* Renvoie la région du mot. */ return new Region(currentWordSelection.getOffset(), currentWordSelection.getLength()); }
private void insertMultiLiner(BracketInsertion data, ISelectionProvider selectionProvider, int offset, IDocument document) throws BadLocationException { IRegion region = document.getLineInformationOfOffset(offset); if (region == null) { return; } int length = region.getLength(); String textBeforeColumn = document.get(offset - length, length-1); //-1 to get not he bracket itself String relevantColumnsBefore = TextUtil.trimRightWhitespaces(textBeforeColumn); InsertionData result = support.prepareInsertionString( data.createMultiLineTemplate(SourceCodeInsertionSupport.CURSOR_VARIABLE), relevantColumnsBefore); document.replace(offset - 1, 1, result.getSourceCode()); selectionProvider.setSelection(new TextSelection(offset + result.getCursorOffset() - 1, 0)); }
public void run() { if (editor == null) return; ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); TexCompletionProposal prop = new TexCompletionProposal(entry, selection.getOffset() + 1, 0, editor.getViewer()); try { // insert a backslash first doc.replace(selection.getOffset(), 0, "\\"); prop.apply(doc); int newOffset = selection.getOffset() + entry.key.length() + 1; if (entry.arguments > 0) { newOffset += 1; } editor.getSelectionProvider().setSelection(new TextSelection(newOffset, 0)); } catch (BadLocationException e) { TexlipsePlugin.log("Error while trying to insert command", e); } }
public void run() { try { handler.editor = EditorUtil.getTLAEditorWithFocus(); handler.doc = editor.getDocumentProvider().getDocument( editor.getEditorInput()); handler.selectionProvider = editor.getSelectionProvider(); handler.selection = (TextSelection) selectionProvider .getSelection(); handler.offset = selection.getOffset(); // Get the module. String moduleName = editor.getModuleName(); handler.moduleNode = ResourceHelper.getModuleNode(moduleName); handler.realExecute(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void run() { try { handler.editor = EditorUtil.getTLAEditorWithFocus(); handler.doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); handler.selectionProvider = editor.getSelectionProvider(); handler.selection = (TextSelection) selectionProvider.getSelection(); handler.offset = selection.getOffset(); // Get the module. String moduleName = editor.getModuleName(); handler.moduleNode = ResourceHelper.getModuleNode(moduleName); handler.realExecute() ; } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private void startBoxedComment() throws org.eclipse.jface.text.BadLocationException { int indent = offset - lineInfo.getOffset() + 1; // set dontAddNewLine to true iff the rest of the line, starting from offset // consists entirely of // space characters. int restOfLineLength = lineInfo.getOffset() - offset + lineInfo.getLength(); String restOfLine = doc.get(offset, restOfLineLength); boolean dontAddNewLine = StringHelper.onlySpaces(restOfLine); String asterisks = StringHelper.copyString("*", Math.max(3, RightMargin - indent - 1)); String newText = "(" + asterisks + StringHelper.newline + StringHelper.newline + StringHelper.copyString(" ", indent) + asterisks + ")" + (dontAddNewLine ? "" : StringHelper.newline); doc.replace(selection.getOffset(), selection.getLength(), newText); selectionProvider.setSelection(new TextSelection(offset + 1 + asterisks.length() + StringHelper.newline.length(), 0)); }
public void commentSelection(TextSelection selection, IDocument doc){ if (selection.getLength() > 0) { try { int offset; offset = selection.getOffset(); doc.replace(offset, 0, commentBegin); offset += selection.getLength() + commentBegin.length(); doc.replace(offset, 0, commentEnd); } catch (BadLocationException e) { e.printStackTrace(); } } else { // TODO: Comment the range! System.out.println("Comment the range!"); } }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { markSpec = getMark(); IEditorPart edPart = HandlerUtil.getActiveEditor(event); if (edPart instanceof FluentMkEditor) { editor = (FluentMkEditor) edPart; doc = editor.getDocument(); if (doc != null) { ISelection sel = HandlerUtil.getCurrentSelection(event); if (sel instanceof TextSelection) { TextSelection tsel = (TextSelection) sel; int beg = tsel.getOffset(); int len = tsel.getLength(); cpos = editor.getCursorOffset(); if (len == 0) beg = cpos; try { if (samePartition(beg, len)) { toggle(beg, len); } } catch (BadLocationException e) {} } } } return null; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart edPart = HandlerUtil.getActiveEditor(event); if (edPart instanceof FluentMkEditor) { FluentMkEditor editor = (FluentMkEditor) edPart; IDocument doc = editor.getDocument(); if (doc != null) { ISelection sel = HandlerUtil.getCurrentSelection(event); if (sel instanceof TextSelection) { TextSelection tsel = (TextSelection) sel; int beg = tsel.getOffset(); int len = tsel.getLength(); switch (checkPartition(doc, beg, len)) { case NONE: addComment(doc, beg, len); break; case SAME: removeComment(doc, beg); break; } } } } return null; }
@Override public void open() { // Open Implementation dialog Display.getDefault().asyncExec(() -> { try { Shell parent = Display.getDefault().getActiveShell(); TypeScriptImplementationDialog dialog = new TypeScriptImplementationDialog(parent, SWT.RESIZE, tsFile); int offset = tsFile.getPosition(getRange().startLineNumber, getRange().startColumn); ITextSelection selection = new TextSelection(offset, 1); dialog.setSize(450, 500); dialog.setInput(selection); dialog.open(); } catch (TypeScriptException e) { e.printStackTrace(); } }); }
/** * Given a selection on a document, computes the lines fully or partially covered by * <code>selection</code>. A line in the document is considered covered if * <code>selection</code> comprises any characters on it, including the terminating delimiter. * <p>Note that the last line in a selection is not considered covered if the selection only * comprises the line delimiter at its beginning (that is considered part of the second last * line). * As a special case, if the selection is empty, a line is considered covered if the caret is * at any position in the line, including between the delimiter and the start of the line. The * line containing the delimiter is not considered covered in that case. * </p> * * @param document the document <code>selection</code> refers to * @param selection a selection on <code>document</code> * @param viewer the <code>ISourceViewer</code> displaying <code>document</code> * @return a selection describing the range of lines (partially) covered by * <code>selection</code>, without any terminating line delimiters * @throws BadLocationException if the selection is out of bounds (when the underlying document has changed during the call) */ private ITextSelection getMovingSelection(IDocument document, ITextSelection selection, ITextViewer viewer) throws BadLocationException { int low= document.getLineOffset(selection.getStartLine()); int endLine= selection.getEndLine(); int high= document.getLineOffset(endLine) + document.getLineLength(endLine); // get everything up to last line without its delimiter String delim= document.getLineDelimiter(endLine); if (delim != null) high -= delim.length(); // the new selection will cover the entire lines being moved, except for the last line's // delimiter. The exception to this rule is an empty last line, which will stay covered // including its delimiter if (delim != null && document.getLineLength(endLine) == delim.length()) fAddDelimiter= true; else fAddDelimiter= false; return new TextSelection(document, low, high - low); }
@Override public void run() { IXtextDocument document = editor.getDocument(); ISelection selection = editor.getSelectionProvider().getSelection(); if (selection instanceof TextSelection) { TextSelection textSelection = (TextSelection) selection; if (textSelection.getLength()==0) { IRegion region = matcher.match(document, textSelection.getOffset()); if (region != null) { if (region.getOffset()+1==textSelection.getOffset()) { editor.selectAndReveal(region.getOffset()+region.getLength(),0); } else { editor.selectAndReveal(region.getOffset()+1,0); } } } } }
/** * @param selection * @return first element of the selection */ public static Object getFirstSelectedElement(ISelection selection) { if (selection instanceof TreeSelection) { TreeSelection treeSelection = (TreeSelection) selection; return treeSelection.getFirstElement(); } else if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; return structuredSelection.getFirstElement(); } else if (selection instanceof IFileEditorInput) { IFileEditorInput editorInput = (FileEditorInput) selection; return editorInput.getFile(); } else if (selection instanceof TextSelection) { return null; } else { throw new RuntimeException( Messages.GeneratorUtils_SelectionNotSupported); } }
@Override public void modifyText(final ModifyEvent e) { boolean wrap = true; final String text = find.getText(); if (lastText.startsWith(text)) { wrap = false; } lastText = text; if (EMPTY.equals(text) || "".equals(text)) { adjustEnablement(false, null); final ISelectionProvider selectionProvider = editor.getSelectionProvider(); if (selectionProvider != null) { final ISelection selection = selectionProvider.getSelection(); if (selection instanceof TextSelection) { final ITextSelection textSelection = (ITextSelection) selection; selectionProvider.setSelection(new TextSelection(textSelection.getOffset(), 0)); } } } else { find(true, true, wrap); } }
public void search() { final IWorkbenchPart part = WorkbenchHelper.getActivePart(); if (part instanceof IEditorPart) { final IEditorPart editor = (IEditorPart) part; final IWorkbenchPartSite site = editor.getSite(); if (site != null) { final ISelectionProvider provider = site.getSelectionProvider(); if (provider != null) { final ISelection viewSiteSelection = provider.getSelection(); if (viewSiteSelection instanceof TextSelection) { final TextSelection textSelection = (TextSelection) viewSiteSelection; text.setText(textSelection.getText()); } } } } activate(null); text.setFocus(); }
@Override public void reloadDocumentContent() { if (!(getDocument() instanceof CooperateXtextDocument)) { throw new IllegalStateException( String.format("The document has to be of type %s.", CooperateXtextDocument.class)); } if (!(getDocumentProvider() instanceof IReinitializingDocumentProvider)) { throw new IllegalStateException(String.format("The document provider has to be of type %s.", IReinitializingDocumentProvider.class)); } TextSelection actualSelection = (TextSelection) getSelectionProvider().getSelection(); CooperateXtextDocument currentDocument = (CooperateXtextDocument) getDocument(); IReinitializingDocumentProvider documentProvider = (IReinitializingDocumentProvider) getDocumentProvider(); documentProvider.reinitializeDocumentContent(currentDocument, currentDocument.getResource().getContents().get(0)); waitForReconcileToStartAndFinish(); getSelectionProvider().setSelection(actualSelection); documentProvider.setNotDirty(getEditorInput()); }
@Override public void doSave(IProgressMonitor progressMonitor) { CooperateXtextDocument cooperateXtextDocument = getDocument().getAdapter(CooperateXtextDocument.class); TextSelection actualSelection = (TextSelection) getSelectionProvider().getSelection(); Collection<Issue> syntaxIssues = getSyntaxErrors(cooperateXtextDocument); if (!syntaxIssues.isEmpty()) { openErrorDialog("Save Error", "Can't save because of syntax errors.", syntaxIssues); return; } performPreSaveActions(); IStatus status = scheduleValidation(cooperateXtextDocument); if (status.isOK()) { if (!tryDocumentSave(cooperateXtextDocument)) { return; } } else if (status.matches(IStatus.CANCEL)) { openErrorDialog("Wait for validation", "Wait for Validation to finish before saving!", null); return; } getSelectionProvider().setSelection(actualSelection); }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelection(event); if ( selection instanceof TextSelection ) { TextSelection s = (TextSelection) selection; IEditorInput input = HandlerUtil.getActiveEditorInput(event); IEditorPart editor = HandlerUtil.getActiveEditor(event); if ( editor instanceof AtlEditorExt ) { AtlEditorExt atlEditor = (AtlEditorExt) editor; IFile file = (IFile) atlEditor.getUnderlyingResource(); AnalysisResult analysis = AnalysisIndex.getInstance().getAnalysis(file); if ( analysis != null ) { ATLModel model = analysis.getATLModel(); new HOTGenerator(model).generate(); } } } System.out.println(selection); return null; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelection(event); if ( selection instanceof TextSelection ) { TextSelection s = (TextSelection) selection; IEditorInput input = HandlerUtil.getActiveEditorInput(event); IEditorPart editor = HandlerUtil.getActiveEditor(event); if ( editor instanceof AtlEditorExt ) { AtlEditorExt atlEditor = (AtlEditorExt) editor; IFile file = (IFile) atlEditor.getUnderlyingResource(); AnalysisResult r = AnalysisIndex.getInstance().getAnalysis(file); if ( r != null ) { Query unit = generate(r); try { serialize(unit, file); } catch (CoreException e) { throw new ExecutionException("Cannot serialize!", e); } } } } return null; }
public static void generateTestMethod(String preparedText, int lineNumber, IDocument doc) { ITextEditor editor = EditorHandler.getEditor(); if (!EditorHandler.isValidEditor("php")) { return; } if (editor == null || !editor.isEditable() || !EditorHandler.getPage().getActivePartReference().getId().toString() .toLowerCase().contains(".php.editor")) { return; } try { IRegion lineInfo = doc.getLineInformation(lineNumber); editor.selectAndReveal(lineInfo.getOffset(), lineInfo.getLength()); ISelection sel = editor.getSelectionProvider().getSelection(); if (sel instanceof TextSelection) { EditorHandler.insertMethod((TextSelection) sel, preparedText, doc); } } catch(Exception e) {} }
/** * @see com.mulgasoft.emacsplus.commands.SexpBaseBackwardHandler#consoleDispatch(TextConsoleViewer, IConsoleView, ExecutionEvent) */ public Object consoleDispatch(final TextConsoleViewer viewer, final IConsoleView activePart, ExecutionEvent event) { IDocument doc = viewer.getDocument(); boolean isBackup = getUniversalCount() > 0; // normal direction ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection(); try { int offset = doTransform(doc, selection, viewer.getTextWidget().getCaretOffset(),isBackup); if (offset == NO_OFFSET) { unbalanced(activePart,false); } else { endTransform(viewer, offset, selection, new TextSelection(null,offset,offset - selection.getOffset())); } } catch (BadLocationException e) {} return null; }
/** * @see com.mulgasoft.emacsplus.commands.EmacsPlusCmdHandler#transform(ITextEditor, IDocument, ITextSelection, ExecutionEvent) */ @Override protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection, ExecutionEvent event) throws BadLocationException { ITextSelection selection = getLineSelection(editor,document,currentSelection); if (selection != null) { int offset = selection.getOffset(); int endOffset = offset+selection.getLength(); int begin = document.getLineOfOffset(offset); int end = document.getLineOfOffset(endOffset); if (begin != end && begin < end) { // grab the lines int len = end-begin+1; String[] array = new String[len]; for (int i = 0; i < len; i++) { IRegion region = document.getLineInformation(begin+i); array[i] = document.get(region.getOffset(),region.getLength()); } // and reverse them updateLines(document,new TextSelection(document,offset,endOffset-offset),reverse(array)); } } else { EmacsPlusUtils.showMessage(editor, NO_REGION, true); } return NO_OFFSET; }
/** * @see com.mulgasoft.emacsplus.commands.IConsoleDispatch#consoleDispatch(org.eclipse.ui.console.TextConsoleViewer, org.eclipse.ui.console.IConsoleView, org.eclipse.core.commands.ExecutionEvent) */ public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) { IDocument document = viewer.getDocument(); ITextSelection currentSelection = (ITextSelection)viewer.getSelectionProvider().getSelection(); ITextSelection selection = new TextSelection(document, viewer.getTextWidget().getCaretOffset(), 0); try { selection = getNextSexp(document, selection); if (selection == null) { selection = currentSelection; unbalanced(activePart,true); return null; } else { return endTransform(viewer, selection.getOffset() + selection.getLength(), currentSelection, selection); } } catch (BadLocationException e) { } return null; }
/** * A semi-hack... This uses stuff that may change at any time in Eclipse. * In the java editor, the projection annotation model contains the collapsible regions which correspond to methods (and other areas * such as import groups). * * This may work in other editor types as well... TBD */ protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection, ExecutionEvent event) throws BadLocationException { ITextViewerExtension viewer = MarkUtils.getITextViewer(editor); if (viewer instanceof ProjectionViewer) { ProjectionAnnotationModel projection = ((ProjectionViewer)viewer).getProjectionAnnotationModel(); @SuppressWarnings("unchecked") // the method name says it all Iterator<Annotation> pit = projection.getAnnotationIterator(); while (pit.hasNext()) { Position p = projection.getPosition(pit.next()); if (p.includes(currentSelection.getOffset())) { if (isUniversalPresent()) { // Do this here to prevent subsequent scrolling once range is revealed MarkUtils.setSelection(editor, new TextSelection(document, p.offset, 0)); } // the viewer is pretty much guaranteed to be a TextViewer if (viewer instanceof TextViewer) { ((TextViewer)viewer).revealRange(p.offset, p.length); } break; } } } return NO_OFFSET; }
private RefactoringInfo setupInfo(MockupSelectionConfig config) throws Throwable { IDocument doc = new Document(data.source); ITextSelection selection = new TextSelection(doc, data.sourceSelection.getOffset(), data.sourceSelection.getLength()); RefactoringInfo info = new RefactoringInfo(doc, selection, new IGrammarVersionProvider() { @Override public int getGrammarVersion() throws MisconfigurationException { return IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_2_7; } @Override public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() throws MisconfigurationException { return null; } }); return info; }
/** * Restores the selection previously gotten. */ public void restoreSelection(ISelectionProvider selectionProvider, IDocument doc) { //OK, now, the start line and the end line should not change -- because the document changed, //the columns may end up being wrong, so, we must update things so that the selection stays OK. int numberOfLines = doc.getNumberOfLines(); int startLine = fixBasedOnNumberOfLines(this.startLine, numberOfLines); int endLine = fixBasedOnNumberOfLines(this.endLine, numberOfLines); final int startLineOffset = getOffset(doc, startLine); final int startLineLen = getLineLength(doc, startLine); final int startLineDelimiterLen = getLineDelimiterLen(doc, startLine); int startOffset = fixOffset(startLineOffset + startCol, startLineOffset, startLineOffset + startLineLen - startLineDelimiterLen); final int endLineOffset = getOffset(doc, endLine); final int endLineLen = getLineLength(doc, endLine); final int endLineDelimiterLen = getLineDelimiterLen(doc, endLine); int endOffset = fixOffset(endLineOffset + endCol, endLineOffset, endLineOffset + endLineLen - endLineDelimiterLen); selectionProvider.setSelection(new TextSelection(startOffset, endOffset - startOffset)); }
/** * Called right after a ' or " */ public void handleAutoClose(IDocument document, DocumentCommand command, char start, char end) { TextSelectionUtils ps = new TextSelectionUtils(document, new TextSelection(document, command.offset, command.length)); try { char nextChar = ps.getCharAfterCurrentOffset(); if (Character.isJavaIdentifierPart(nextChar)) { //we're just before a word (don't try to do anything in this case) //e.g. |var (| is cursor position) return; } } catch (BadLocationException e) { } command.text = Character.toString(start) + Character.toString(end); command.shiftsCaret = false; command.caretOffset = command.offset + 1; }
public void handleAutoSkip(IDocument document, DocumentCommand command, char c) { TextSelectionUtils ps = new TextSelectionUtils(document, new TextSelection(document, command.offset, command.length)); Tuple<String, String> beforeAndAfterMatchingChars = ps.getBeforeAndAfterMatchingChars(c); //Reminder: int matchesBefore = beforeAndAfterMatchingChars.o1.length(); int matchesAfter = beforeAndAfterMatchingChars.o2.length(); if (matchesAfter == 1) { //just walk the caret command.text = ""; command.shiftsCaret = false; command.caretOffset = command.offset + 1; } }
public void testPyCreateMethodGlobal() { PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField(); String source = "MyMethod()"; IDocument document = new Document(source); ITextSelection selection = new TextSelection(document, 0, 0); RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER); pyCreateMethod.execute(info, AbstractPyCreateAction.LOCATION_STRATEGY_BEFORE_CURRENT); assertContentsEqual("" + "def MyMethod():\n" + " ${pass}${cursor}\n" + "\n" + "\n" + "MyMethod()" + "", document.get()); }
public void testPyCreateMethodGlobalParams() { PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField(); String source = "MyMethod(a, b())"; IDocument document = new Document(source); ITextSelection selection = new TextSelection(document, 0, 0); RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER); pyCreateMethod.execute(info, AbstractPyCreateAction.LOCATION_STRATEGY_BEFORE_CURRENT); assertContentsEqual("" + "def MyMethod(${a}, ${b}):\n" + " ${pass}${cursor}\n" + "\n" + "\n" + "MyMethod(a, b())" + "", document.get()); }
public void testPyCreateMethodGlobal1() { PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField(); String source = "a = MyMethod()"; IDocument document = new Document(source); ITextSelection selection = new TextSelection(document, 5, 0); RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER); pyCreateMethod.execute(info, AbstractPyCreateAction.LOCATION_STRATEGY_END); assertContentsEqual("" + "a = MyMethod()\n" + "\n" + "def MyMethod():\n" + " ${pass}${cursor}\n" + "\n" + "\n" + "", document.get()); }
public void testPyCreateClassInSameModule() throws Exception { PyCreateClass pyCreateClass = new PyCreateClass(); String source = "MyClass()"; IDocument document = new Document(source); ITextSelection selection = new TextSelection(document, 0, 0); RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER); pyCreateClass.execute(info, PyCreateClass.LOCATION_STRATEGY_BEFORE_CURRENT); assertContentsEqual("" + "class MyClass(${object}):\n" + " ${pass}${cursor}\n" + "\n" + "\n" + "MyClass()" + "", document.get()); }
public void testPyCreateClassWithParameters() throws Exception { PyCreateClass pyCreateClass = new PyCreateClass(); String source = "MyClass(aa, bb, 10)"; IDocument document = new Document(source); ITextSelection selection = new TextSelection(document, 0, 0); RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER); pyCreateClass.execute(info, PyCreateClass.LOCATION_STRATEGY_BEFORE_CURRENT); assertContentsEqual("" + "class MyClass(${object}):\n" + " \n" + " def __init__(self, ${aa}, ${bb}, ${param2}):\n" + " ${pass}${cursor}\n" + "\n" + "\n" + "MyClass(aa, bb, 10)" + "", document.get()); }
public void testPyCreateClassWithParameters2() throws Exception { PyCreateClass pyCreateClass = new PyCreateClass(); String source = "MyClass(aa, bb, MyFoo())"; IDocument document = new Document(source); ITextSelection selection = new TextSelection(document, 0, 0); RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER); pyCreateClass.execute(info, PyCreateClass.LOCATION_STRATEGY_BEFORE_CURRENT); assertContentsEqual("" + "class MyClass(${object}):\n" + " \n" + " def __init__(self, ${aa}, ${bb}, ${my_foo}):\n" + " ${pass}${cursor}\n" + "\n" + "\n" + "MyClass(aa, bb, MyFoo())" + "", document.get()); }
public void testPyCreateClassEndOfFile2() throws Exception { PyCreateClass pyCreateClass = new PyCreateClass(); String source = ""; IDocument document = new Document(source); ITextSelection selection = new TextSelection(document, 0, 0); RefactoringInfo info = new RefactoringInfo(document, selection, PY_27_ONLY_GRAMMAR_VERSION_PROVIDER); pyCreateClass.createProposal(info, "Foo", PyCreateClass.LOCATION_STRATEGY_END, new ArrayList<String>()).apply( document); assertContentsEqual("" + "class Foo(${object}):\n" + " ${pass}${cursor}\n" + "\n" + "\n", document.get()); }
/** * @throws BadLocationException * */ public void testGeneral() throws BadLocationException { ps = new PySelection(doc, new TextSelection(doc, 0, 0)); assertEquals("TestLine1", ps.getCursorLineContents()); assertEquals("", ps.getLineContentsToCursor()); ps.selectCompleteLine(); assertEquals("TestLine1", ps.getCursorLineContents()); assertEquals("TestLine1", ps.getLine(0)); assertEquals("TestLine2#comm2", ps.getLine(1)); ps.deleteLine(0); assertEquals("TestLine2#comm2", ps.getLine(0)); ps.addLine("TestLine1", 0); }
public void testSelectAll() { ps = new PySelection(doc, new TextSelection(doc, 0, 0)); ps.selectAll(true); assertEquals(docContents, ps.getCursorLineContents() + "\n"); assertEquals(docContents, ps.getSelectedText()); ps = new PySelection(doc, new TextSelection(doc, 0, 9)); //first line selected ps.selectAll(true); //changes assertEquals(docContents, ps.getCursorLineContents() + "\n"); assertEquals(docContents, ps.getSelectedText()); ps = new PySelection(doc, new TextSelection(doc, 0, 9)); //first line selected ps.selectAll(false); //nothing changes assertEquals(ps.getLine(0), ps.getCursorLineContents()); assertEquals(ps.getLine(0), ps.getSelectedText()); }
public void testCodingStd() throws BadLocationException { assist = new AssistAssign(new NonCamelCodingStd()); String d = "" + "from testAssist import assist\n" + "assist.NewMethod(a = 1, b = 2)"; Document doc = new Document(d); PySelection ps = new PySelection(doc, new TextSelection(doc, d.length(), 0)); String sel = PyAction.getLineWithoutComments(ps); assertEquals(true, assist.isValid(ps, sel, null, d.length())); List<ICompletionProposal> props = assist.getProps(ps, null, null, null, null, d.length()); assertEquals(2, props.size()); assertContains("Assign to local (new_method)", props); }
public void testSimple8() throws BadLocationException { assist = new AssistAssign(new NonCamelCodingStd()); String d = "" + "def m1():\n" + " IKVMClass"; Document doc = new Document(d); PySelection ps = new PySelection(doc, new TextSelection(doc, d.length(), 0)); String sel = PyAction.getLineWithoutComments(ps); assertEquals(true, assist.isValid(ps, sel, null, d.length())); List<ICompletionProposal> props = assist.getProps(ps, null, null, null, null, d.length()); assertEquals(2, props.size()); assertContains("Assign to local (ikvmclass)", props); }
public void testSimple9() throws BadLocationException { assist = new AssistAssign(new NonCamelCodingStd()); String d = "" + "def m1():\n" + " IKVMClassBBBar"; Document doc = new Document(d); PySelection ps = new PySelection(doc, new TextSelection(doc, d.length(), 0)); String sel = PyAction.getLineWithoutComments(ps); assertEquals(true, assist.isValid(ps, sel, null, d.length())); List<ICompletionProposal> props = assist.getProps(ps, null, null, null, null, d.length()); assertEquals(2, props.size()); assertContains("Assign to local (ikvmclass_bbbar)", props); }