当前位置: 首页>>代码示例>>Java>>正文


Java InsertionContext类代码示例

本文整理汇总了Java中com.intellij.codeInsight.completion.InsertionContext的典型用法代码示例。如果您正苦于以下问题:Java InsertionContext类的具体用法?Java InsertionContext怎么用?Java InsertionContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InsertionContext类属于com.intellij.codeInsight.completion包,在下文中一共展示了InsertionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
@Override
public void handleInsert(final InsertionContext insertionContext,
    final LookupElement lookupElement) {
  if (shouldUseQuotes(lookupElement)) {
    final boolean hasDoubleQuotes =
        hasStartingOrEndingQuoteOfType(insertionContext, lookupElement, DOUBLE_QUOTE);

    if (hasDoubleQuotes) {
      handleEndingQuote(insertionContext, DOUBLE_QUOTE);
      handleStartingQuote(insertionContext, lookupElement, DOUBLE_QUOTE);
    } else {
      handleEndingQuote(insertionContext, SINGLE_QUOTE);
      handleStartingQuote(insertionContext, lookupElement, SINGLE_QUOTE);
    }
  }
}
 
开发者ID:1tontech,项目名称:intellij-spring-assistant,代码行数:17,代码来源:YamlValueInsertHandler.java

示例2: deleteLookupTextAndRetrieveOldValue

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
@Nullable
private void deleteLookupTextAndRetrieveOldValue(InsertionContext context,
    @NotNull PsiElement elementAtCaret) {
  if (elementAtCaret.getNode().getElementType() != YAMLTokenTypes.SCALAR_KEY) {
    deleteLookupPlain(context);
  } else {
    YAMLKeyValue keyValue = PsiTreeUtil.getParentOfType(elementAtCaret, YAMLKeyValue.class);
    assert keyValue != null;
    context.commitDocument();
    if (keyValue.getValue() != null) {
      YAMLKeyValue dummyKV =
          YAMLElementGenerator.getInstance(context.getProject()).createYamlKeyValue("foo", "b");
      dummyKV.setValue(keyValue.getValue());
    }

    context.setTailOffset(keyValue.getTextRange().getEndOffset());
    WriteCommandAction.runWriteCommandAction(context.getProject(), () -> {
      keyValue.getParentMapping().deleteKeyValue(keyValue);
    });
  }
}
 
开发者ID:1tontech,项目名称:intellij-spring-assistant,代码行数:22,代码来源:YamlKeyInsertHandler.java

示例3: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
  final Object object = item.getObject();
  if (object instanceof PsiMethod) {
    final PsiElement newElement = PsiUtilCore.getElementAtOffset(context.getFile(), context.getStartOffset());
    final int start = newElement.getTextRange().getEndOffset();
    final PsiElement params = newElement.getParent().getParent();
    final int end = params.getTextRange().getEndOffset() - 1;
    final String types = getMethodTypes((PsiMethod)object);
    context.getDocument().replaceString(start, end, types);
    context.commitDocument();
    final PsiElement firstParam = PsiUtilCore.getElementAtOffset(context.getFile(), context.getStartOffset());
    final PsiMethodCallExpression methodCall = PsiTreeUtil.getParentOfType(firstParam, PsiMethodCallExpression.class);
    if (methodCall != null) {
      JavaCodeStyleManager.getInstance(context.getProject()).shortenClassReferences(methodCall);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:JavaLangClassMemberReference.java

示例4: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
@Override
public void handleInsert(final InsertionContext context) {
  super.handleInsert(context);
  if (!myMergedOverloads || isUniqueMethod(myMethod)) {
    context.commitDocument();
    context.getDocument()
      .insertString(context.getTailOffset() - 1, ChainCompletionLookupElementUtil.fillMethodParameters(myMethod, myReplaceElements));
    final PsiFile file = context.getFile();
    assert file instanceof PsiJavaFile;
    final PsiJavaFile javaFile = (PsiJavaFile)file;
    if (myReplaceElements != null) {
      myReplaceElements.forEachValue(new TObjectProcedure<SubLookupElement>() {
        @Override
        public boolean execute(final SubLookupElement subLookupElement) {
          subLookupElement.doImport(javaFile);
          return true;
        }
      });
    }
    context.commitDocument();
    context.getEditor().getCaretModel().moveToOffset(context.getTailOffset());
    context.commitDocument();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:ChainCompletionMethodCallLookupElement.java

示例5: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
@Override
public void handleInsert(InsertionContext context) {
  final LookupElement delegate = getDelegate();
  final TailType tailType = computeTailType(context);

  final LookupItem lookupItem = delegate.as(LookupItem.CLASS_CONDITION_KEY);
  if (lookupItem != null && tailType != null) {
    lookupItem.setTailType(TailType.UNKNOWN);
  }
  delegate.handleInsert(context);
  if (tailType != null && tailType.isApplicable(context)) {
    PostprocessReformattingAspect.getInstance(context.getProject()).doPostponedFormatting();
    int tailOffset = context.getTailOffset();
    if (tailOffset < 0) {
      throw new AssertionError("tailOffset < 0: delegate=" + getDelegate() + "; this=" + this + "; tail=" + tailType);
    }
    tailType.processTail(context.getEditor(), tailOffset);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:TailTypeDecorator.java

示例6: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
public void handleInsert(InsertionContext context, LookupElement item) {
  final Editor editor = context.getEditor();
  final Document document = editor.getDocument();
  if (context.getCompletionChar() == '(') {
    context.setAddCompletionChar(false);
    final int offset = context.getTailOffset();
    document.insertString(offset, "()");

    PyClass pyClass = (PyClass) item.getObject();
    PyFunction init = pyClass.findInitOrNew(true, null);
    if (init != null && PyFunctionInsertHandler.hasParams(context, init)) {
      editor.getCaretModel().moveToOffset(offset+1);
      AutoPopupController.getInstance(context.getProject()).autoPopupParameterInfo(context.getEditor(), init);
    }
    else {
      editor.getCaretModel().moveToOffset(offset+2);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:PyClassInsertHandler.java

示例7: handleUserSelection

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
private static void handleUserSelection(InsertionContext context, @NotNull Function<Color, String> colorToStringConverter) {
  Color myColorAtCaret = null;

  Editor selectedTextEditor = context.getEditor();
  PsiElement element = context.getFile().findElementAt(selectedTextEditor.getCaretModel().getOffset());

  if (element instanceof XmlToken) {
    myColorAtCaret = getColorFromElement(element);
  }

  context.getDocument().deleteString(context.getStartOffset(), context.getTailOffset());

  List<ColorPickerListener> listeners = ColorPickerListenerFactory.createListenersFor(element);
  Color color = ColorChooser.chooseColor(WindowManager.getInstance().suggestParentWindow(context.getProject()),
                                         XmlBundle.message("choose.color.dialog.title"), myColorAtCaret, true, listeners, true);

  if (color != null) {
    String colorString = colorToStringConverter.fun(color);
    context.getDocument().insertString(context.getStartOffset(), colorString);
    context.getEditor().getCaretModel().moveToOffset(context.getTailOffset());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:UserColorLookup.java

示例8: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
@Override
public void handleInsert(final InsertionContext context, LookupElement item) {
  if (TemplateManager.getInstance(context.getProject()).getActiveTemplate(context.getEditor()) != null) {
    return; // Don't brake the template.
  }

  context.commitDocument();

  XmlFile xmlFile = (XmlFile)context.getFile();

  PsiElement element = xmlFile.findElementAt(context.getStartOffset());
  XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
  if (tag == null) return;

  XmlTag dependencyTag = tag.getParentTag();

  DomElement domElement = DomManager.getDomManager(context.getProject()).getDomElement(dependencyTag);
  if (!(domElement instanceof MavenDomDependency)) return;

  MavenDomDependency dependency = (MavenDomDependency)domElement;

  String artifactId = dependency.getArtifactId().getStringValue();
  if (StringUtil.isEmpty(artifactId)) return;

  MavenDependencyCompletionUtil.addTypeAndClassifierAndVersion(context, dependency, item.getLookupString(), artifactId);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:MavenArtifactCoordinatesGroupIdConverter.java

示例9: runClosureCompletion

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
public static boolean runClosureCompletion(InsertionContext context,
                                           PsiMethod method,
                                           PsiSubstitutor substitutor,
                                           Document document,
                                           int offset,
                                           PsiElement parent) {
  for (ClosureCompleter completer : EP_NAME.getExtensions()) {
    final List<ClosureParameterInfo> parameterInfos = completer.getParameterInfos(context, method, substitutor, parent);
    if (parameterInfos != null) {
      runClosureTemplate(context, document, offset, substitutor, method, parameterInfos);
      return true;
    }
  }

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:ClosureCompleter.java

示例10: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
@Override
public void handleInsert(InsertionContext context, JavaGlobalMemberLookupElement item) {
  GroovyInsertHandler.INSTANCE.handleInsert(context, item);
  final PsiMember member = item.getObject();
  PsiDocumentManager.getInstance(member.getProject()).commitDocument(context.getDocument());
  final GrReferenceExpression ref = PsiTreeUtil.
    findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), GrReferenceExpression.class, false);

  if (ref != null &&
      ref.getQualifier() == null &&
      context.getFile() instanceof GroovyFile &&
      !importAlreadyExists(member, ((GroovyFile)context.getFile()), ref) &&
      !PsiManager.getInstance(context.getProject()).areElementsEquivalent(ref.resolve(), member)) {
    ref.bindToElementViaStaticImport(member);
  }

}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:StaticImportInsertHandler.java

示例11: isAcceptable

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
@Override
public boolean isAcceptable(InsertionContext context, int startOffset, LookupElement item) {
  PsiFile file = context.getFile();
  if (!(file instanceof GroovyFile)) return false;

  PsiElement element = file.findElementAt(startOffset);
  while (element != null && !(element instanceof PsiFile) && !(element instanceof GrDocComment)) {
    element = element.getParent();
  }
  if (!(element instanceof GrDocComment)) return false;

  int offset = context.getEditor().getCaretModel().getOffset();
  String text = file.getText();
  return offset < text.length() && item.getObject() instanceof PsiMethod;

}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:GroovyDocMethodHandler.java

示例12: shortenParamterReferences

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
private static int shortenParamterReferences(InsertionContext context, int startOffset, PsiMethod method, StringBuffer buffer) {
  Document document = context.getEditor().getDocument();
  int offset = startOffset + method.getName().length();
  String paramText = buffer.toString();
  document.insertString(offset, paramText);
  int endOffset = offset + paramText.length();

  final Project project = context.getProject();
  PsiDocumentManager.getInstance(project).commitDocument(document);
  PsiReference ref = context.getFile().findReferenceAt(startOffset);
  if (ref instanceof GrDocMethodReference) {
    GrDocMethodReference methodReference = (GrDocMethodReference) ref;
    GrDocMethodParams list = methodReference.getParameterList();
    for (GrDocMethodParameter parameter : list.getParameters()) {
      JavaCodeStyleManager.getInstance(project).shortenClassReferences(parameter);
    }
    endOffset = methodReference.getTextRange().getEndOffset() + 1;
  }
  return endOffset;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:GroovyDocMethodHandler.java

示例13: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
/**
 * If we're wrapping with quotes, handle the (very common) case where we have a closing quote
 * after the caret -- we want to remove this quote.
 */
@Override
public void handleInsert(InsertionContext context) {
  if (!wrapWithQuotes || !insertClosingQuotes()) {
    super.handleInsert(context);
    return;
  }
  Document document = context.getDocument();
  context.commitDocument();
  PsiElement suffix = context.getFile().findElementAt(context.getTailOffset());
  if (suffix != null && suffix.getText().startsWith(quoteWrapping.quoteString)) {
    int offset = suffix.getTextOffset();
    document.deleteString(offset, offset + 1);
    context.commitDocument();
  }
  if (caretInsideQuotes()) {
    context.getEditor().getCaretModel().moveCaretRelatively(-1, 0, false, false, true);
  }
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:23,代码来源:BuildLookupElement.java

示例14: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
public void handleInsert(InsertionContext context, LookupElement item) {
    final Editor editor = context.getEditor();
    final Project project = editor.getProject();
    if (project != null) {

        final JSGraphQLEndpointImportDeclaration[] imports = PsiTreeUtil.getChildrenOfType(context.getFile(), JSGraphQLEndpointImportDeclaration.class);

        int insertionOffset = 0;
        if(imports != null && imports.length > 0) {
            JSGraphQLEndpointImportDeclaration lastImport = imports[imports.length - 1];
            insertionOffset = lastImport.getTextRange().getEndOffset();
        }

        final String name = JSGraphQLEndpointImportUtil.getImportName(project, fileToImport);
        String importDeclaration = "import \"" + name + "\"\n";
        if(insertionOffset > 0) {
            importDeclaration = "\n" + importDeclaration;
        }
        editor.getDocument().insertString(insertionOffset, importDeclaration);
    }
}
 
开发者ID:jimkyndemeyer,项目名称:js-graphql-intellij-plugin,代码行数:22,代码来源:JSGraphQLEndpointAutoImportInsertHandler.java

示例15: handleInsert

import com.intellij.codeInsight.completion.InsertionContext; //导入依赖的package包/类
@Override
public void handleInsert(InsertionContext context)
{
    if (keepQuotes) {
        return;
    }

    PsiElement rightSingleQuote = PsiUtilBase.getElementAtCaret(context.getEditor());
    if (rightSingleQuote == null || isNotQuote(rightSingleQuote)) {
        return;
    }

    PsiElement previousSibling = rightSingleQuote.getPrevSibling();
    if (previousSibling == null) {
        return;
    }

    PsiElement leftSingleQuote = previousSibling.getPrevSibling();
    if (leftSingleQuote == null || isNotQuote(leftSingleQuote)) {
        return;
    }

    leftSingleQuote.delete();
    rightSingleQuote.delete();
}
 
开发者ID:whitefire,项目名称:eZ-completion,代码行数:26,代码来源:Completion.java


注:本文中的com.intellij.codeInsight.completion.InsertionContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。