當前位置: 首頁>>代碼示例>>Java>>正文


Java Completion類代碼示例

本文整理匯總了Java中org.eclipse.che.ide.api.editor.codeassist.Completion的典型用法代碼示例。如果您正苦於以下問題:Java Completion類的具體用法?Java Completion怎麽用?Java Completion使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Completion類屬於org.eclipse.che.ide.api.editor.codeassist包,在下文中一共展示了Completion類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: applyCompletion

import org.eclipse.che.ide.api.editor.codeassist.Completion; //導入依賴的package包/類
private void applyCompletion(Completion completion) {
  textEditor.setFocus();
  UndoableEditor undoableEditor = textEditor;
  HandlesUndoRedo undoRedo = undoableEditor.getUndoRedo();

  try {
    if (undoRedo != null) {
      undoRedo.beginCompoundChange();
    }
    completion.apply(textEditor.getDocument());
    final LinearRange selection = completion.getSelection(textEditor.getDocument());
    if (selection != null) {
      selectInEditor(selection);
    }
  } catch (final Exception e) {
    Log.error(getClass(), e);
  } finally {
    if (undoRedo != null) {
      undoRedo.endCompoundChange();
    }
  }
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:23,代碼來源:ContentAssistWidget.java

示例2: createItem

import org.eclipse.che.ide.api.editor.codeassist.Completion; //導入依賴的package包/類
public Element createItem(final CompletionProposal proposal) {
  final Element element = Elements.createLiElement(popupResources.popupStyle().item());

  final Element icon = Elements.createDivElement(popupResources.popupStyle().icon());
  if (proposal.getIcon() != null && proposal.getIcon().getSVGImage() != null) {
    icon.appendChild((Node) proposal.getIcon().getSVGImage().getElement());
  } else if (proposal.getIcon() != null && proposal.getIcon().getImage() != null) {
    icon.appendChild((Node) proposal.getIcon().getImage().getElement());
  }
  element.appendChild(icon);

  final SpanElement label = Elements.createSpanElement(popupResources.popupStyle().label());
  label.setInnerHTML(proposal.getDisplayString());
  element.appendChild(label);

  final EventListener validateListener =
      new EventListener() {
        @Override
        public void handleEvent(final Event evt) {
          proposal.getCompletion(
              new CompletionProposal.CompletionCallback() {
                @Override
                public void onCompletion(final Completion completion) {
                  HandlesUndoRedo undoRedo = null;
                  if (textEditor instanceof UndoableEditor) {
                    UndoableEditor undoableEditor =
                        (UndoableEditor) QuickAssistWidget.this.textEditor;
                    undoRedo = undoableEditor.getUndoRedo();
                  }
                  try {
                    if (undoRedo != null) {
                      undoRedo.beginCompoundChange();
                    }
                    completion.apply(textEditor.getDocument());
                    final LinearRange selection =
                        completion.getSelection(textEditor.getDocument());
                    if (selection != null) {
                      textEditor.getDocument().setSelectedRange(selection, true);
                    }
                  } catch (final Exception e) {
                    Log.error(getClass(), e);
                  } finally {
                    if (undoRedo != null) {
                      undoRedo.endCompoundChange();
                    }
                  }
                }
              });
          hide();
        }
      };

  element.addEventListener(Event.DBLCLICK, validateListener, false);
  element.addEventListener(CUSTOM_EVT_TYPE_VALIDATE, validateListener, false);

  return element;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:58,代碼來源:QuickAssistWidget.java

示例3: shouldUseInsertText

import org.eclipse.che.ide.api.editor.codeassist.Completion; //導入依賴的package包/類
@Test
public void shouldUseInsertText() throws Exception {
  when(serverCapabilities.getCompletionProvider()).thenReturn(completionOptions);
  when(completionOptions.getResolveProvider()).thenReturn(false);

  when(document.getCursorPosition()).thenReturn(new TextPosition(0, 5));
  when(completion.getInsertText()).thenReturn("foo");

  Completion[] completions = new Completion[1];
  proposal.getCompletion(completion -> completions[0] = completion);

  completions[0].apply(document);

  verify(document).getCursorPosition();
  verify(document, times(1)).replace(eq(0), eq(5), eq(0), eq(5), eq("foo"));
  verify(document, times(1)).replace(anyInt(), anyInt(), anyInt(), anyInt(), anyString());
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:18,代碼來源:CompletionItemBasedCompletionProposalTest.java

示例4: shouldUseLabelIfInsertTextIsNull

import org.eclipse.che.ide.api.editor.codeassist.Completion; //導入依賴的package包/類
@Test
public void shouldUseLabelIfInsertTextIsNull() throws Exception {
  when(serverCapabilities.getCompletionProvider()).thenReturn(completionOptions);
  when(completionOptions.getResolveProvider()).thenReturn(false);

  when(document.getCursorPosition()).thenReturn(new TextPosition(0, 5));
  when(completion.getInsertText()).thenReturn(null);
  when(completion.getLabel()).thenReturn("bar");

  Completion[] completions = new Completion[1];
  proposal.getCompletion(completion -> completions[0] = completion);

  completions[0].apply(document);

  verify(document).getCursorPosition();
  verify(document, times(1)).replace(eq(0), eq(5), eq(0), eq(5), eq("bar"));
  verify(document, times(1)).replace(anyInt(), anyInt(), anyInt(), anyInt(), anyString());
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:19,代碼來源:CompletionItemBasedCompletionProposalTest.java

示例5: shouldPlaceCursorInRightPositionWithInsertedText

import org.eclipse.che.ide.api.editor.codeassist.Completion; //導入依賴的package包/類
@Test
public void shouldPlaceCursorInRightPositionWithInsertedText() throws Exception {

  when(serverCapabilities.getCompletionProvider()).thenReturn(completionOptions);
  when(completionOptions.getResolveProvider()).thenReturn(false);

  when(document.getCursorPosition()).thenReturn(new TextPosition(0, 5));
  when(completion.getInsertText()).thenReturn("foo");

  when(document.getIndexFromPosition(any())).thenReturn(5);

  Completion[] completions = new Completion[1];
  proposal.getCompletion(completion -> completions[0] = completion);

  completions[0].apply(document);
  LinearRange selection = completions[0].getSelection(document);

  assertEquals(8, selection.getStartOffset());
  assertEquals(0, selection.getLength());
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:21,代碼來源:CompletionItemBasedCompletionProposalTest.java

示例6: shouldReturnNotNullCompletion

import org.eclipse.che.ide.api.editor.codeassist.Completion; //導入依賴的package包/類
@Test
public void shouldReturnNotNullCompletion() throws Exception {
  when(serverCapabilities.getCompletionProvider()).thenReturn(completionOptions);
  when(completionOptions.getResolveProvider()).thenReturn(false);

  Completion[] completions = new Completion[1];
  proposal.getCompletion(completion -> completions[0] = completion);

  assertNotNull(completions[0]);
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:11,代碼來源:CompletionItemBasedCompletionProposalTest.java

示例7: shouldUseTextEditFirst

import org.eclipse.che.ide.api.editor.codeassist.Completion; //導入依賴的package包/類
@Test
public void shouldUseTextEditFirst() throws Exception {
  TextEdit textEdit = mock(TextEdit.class);
  Range range = mock(Range.class);
  Position startPosition = mock(Position.class);
  Position endPosition = mock(Position.class);

  when(serverCapabilities.getCompletionProvider()).thenReturn(completionOptions);
  when(completionOptions.getResolveProvider()).thenReturn(false);

  when(document.getCursorPosition()).thenReturn(new TextPosition(0, 5));
  when(completion.getInsertText()).thenReturn("foo");
  when(completion.getLabel()).thenReturn("bar");
  when(completion.getTextEdit()).thenReturn(textEdit);

  when(textEdit.getRange()).thenReturn(range);
  when(textEdit.getNewText()).thenReturn("fooBar");

  when(range.getStart()).thenReturn(startPosition);
  when(range.getEnd()).thenReturn(endPosition);

  when(startPosition.getLine()).thenReturn(1);
  when(startPosition.getCharacter()).thenReturn(5);

  when(endPosition.getLine()).thenReturn(1);
  when(endPosition.getCharacter()).thenReturn(5);

  Completion[] completions = new Completion[1];
  proposal.getCompletion(completion -> completions[0] = completion);

  completions[0].apply(document);

  verify(document, times(1)).replace(eq(1), eq(5), eq(1), eq(5), eq("fooBar"));
  verify(document, times(1)).replace(anyInt(), anyInt(), anyInt(), anyInt(), anyString());
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:36,代碼來源:CompletionItemBasedCompletionProposalTest.java

示例8: shouldPlaceCursorInRightPositionWithTextEdit

import org.eclipse.che.ide.api.editor.codeassist.Completion; //導入依賴的package包/類
@Test
public void shouldPlaceCursorInRightPositionWithTextEdit() throws Exception {
  TextEdit textEdit = mock(TextEdit.class);
  Range range = mock(Range.class);
  Position startPosition = mock(Position.class);
  Position endPosition = mock(Position.class);

  when(serverCapabilities.getCompletionProvider()).thenReturn(completionOptions);
  when(completionOptions.getResolveProvider()).thenReturn(false);

  when(document.getCursorPosition()).thenReturn(new TextPosition(0, 5));
  when(completion.getInsertText()).thenReturn("foo");
  when(completion.getLabel()).thenReturn("bar");
  when(completion.getTextEdit()).thenReturn(textEdit);

  when(textEdit.getRange()).thenReturn(range);
  when(textEdit.getNewText()).thenReturn("fooBar");

  when(range.getStart()).thenReturn(startPosition);
  when(range.getEnd()).thenReturn(endPosition);

  when(startPosition.getLine()).thenReturn(1);
  when(startPosition.getCharacter()).thenReturn(5);

  when(endPosition.getLine()).thenReturn(1);
  when(endPosition.getCharacter()).thenReturn(5);

  when(document.getIndexFromPosition(any())).thenReturn(5);

  Completion[] completions = new Completion[1];
  proposal.getCompletion(completion -> completions[0] = completion);

  completions[0].apply(document);
  LinearRange selection = completions[0].getSelection(document);

  assertEquals(11, selection.getStartOffset());
  assertEquals(0, selection.getLength());
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:39,代碼來源:CompletionItemBasedCompletionProposalTest.java


注:本文中的org.eclipse.che.ide.api.editor.codeassist.Completion類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。