当前位置: 首页>>代码示例>>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;未经允许,请勿转载。