本文整理汇总了Java中com.intellij.codeInsight.completion.InsertionContext.commitDocument方法的典型用法代码示例。如果您正苦于以下问题:Java InsertionContext.commitDocument方法的具体用法?Java InsertionContext.commitDocument怎么用?Java InsertionContext.commitDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.completion.InsertionContext
的用法示例。
在下文中一共展示了InsertionContext.commitDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
示例2: 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
示例3: 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);
}
}
示例4: qualifyFieldReference
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
private static void qualifyFieldReference(InsertionContext context, PsiField field)
{
context.commitDocument();
PsiFile file = context.getFile();
final PsiReference reference = file.findReferenceAt(context.getStartOffset());
if(reference instanceof PsiJavaCodeReferenceElement && ((PsiJavaCodeReferenceElement) reference).isQualified())
{
return;
}
PsiClass containingClass = field.getContainingClass();
if(containingClass != null && containingClass.getName() != null)
{
context.getDocument().insertString(context.getStartOffset(), ".");
JavaCompletionUtil.insertClassReference(containingClass, file, context.getStartOffset());
PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getDocument());
}
}
示例5: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context) {
final Editor editor = context.getEditor();
final Document document = editor.getDocument();
context.commitDocument();
document.insertString(context.getTailOffset(), "} ");
editor.getCaretModel().moveToOffset(context.getSelectionEndOffset());
}
示例6: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context) {
final RangeMarker rangeMarker = context.getDocument().createRangeMarker(context.getStartOffset(), context.getStartOffset());
getDelegate().handleInsert(context);
final PsiFile file = context.getFile();
((PsiJavaFile)file).importClass(myPsiClass);
final PsiElement caretElement = file.findElementAt(context.getEditor().getCaretModel().getOffset());
if (caretElement == null) {
log.error("element on caret position MUST BE not null");
return;
}
final PsiStatement statement = (PsiStatement) caretElement.getPrevSibling();
final PsiCodeBlock codeBlock = PsiTreeUtil.getParentOfType(statement, PsiCodeBlock.class);
if (codeBlock == null) {
log.error("code block MUST BE not null");
return;
}
final Project project = context.getProject();
final Ref<PsiElement> insertedStatementRef = Ref.create();
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
context.commitDocument();
new WriteCommandAction.Simple(project, file) {
@Override
protected void run() throws Throwable {
final PsiStatement statementFromText = elementFactory.createStatementFromText(String.format("%s %s = null;", myPsiClass.getName(), myNewVarName), null);
insertedStatementRef.set(codeBlock.addBefore(statementFromText, statement));
}
}.execute();
final PsiLiteralExpression nullKeyword = findNull(insertedStatementRef.get());
PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(context.getDocument());
context.getDocument().insertString(rangeMarker.getStartOffset(), myNewVarName + ".");
context.commitDocument();
final int offset = nullKeyword.getTextOffset();
final int endOffset = offset + nullKeyword.getTextLength();
context.getEditor().getSelectionModel().setSelection(offset, endOffset);
context.getEditor().getCaretModel().moveToOffset(offset);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:ChainCompletionNewVariableLookupElement.java
示例7: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
context.getDocument().deleteString(context.getStartOffset(), context.getTailOffset());
PsiMethod method = (PsiMethod)item.getObject();
List<PsiMethod> prototypes = OverrideImplementUtil.overrideOrImplementMethod(myPsiClass, method, false);
context.commitDocument();
GenerateMembersUtil.insertMembersAtOffset(context.getFile(), context.getStartOffset(),
OverrideImplementUtil.convert2GenerationInfos(prototypes));
}
示例8: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
@RequiredWriteAction
public void handleInsert(final InsertionContext context, final T item)
{
final Editor editor = context.getEditor();
final Document document = editor.getDocument();
context.commitDocument();
PsiElement elementAt = context.getFile().findElementAt(context.getStartOffset());
handleInsertImpl(context, item, editor, document);
if(myOpenChar == '{')
{
document.insertString(editor.getCaretModel().getOffset(), "\n");
}
context.commitDocument();
if(elementAt != null)
{
PsiElement parent = elementAt.getParent();
CodeStyleManager.getInstance(elementAt.getProject()).reformat(parent);
if(myOpenChar == '{')
{
EditorWriteActionHandler actionHandler = (EditorWriteActionHandler) EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
actionHandler.executeWriteAction(editor, DataManager.getInstance().getDataContext(editor.getContentComponent()));
}
}
}
示例9: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
final Editor editor = context.getEditor();
final Document document = editor.getDocument();
context.commitDocument();
PsiElement element = findElementBeforeNameFragment(context);
if (element instanceof LeafPsiElement
&& ((LeafPsiElement) element).getElementType() != XQueryTypes.DOLLAR_SIGN) {
document.insertString(context.getStartOffset(), "$");
}
InsertHandlerUtils.removePreviousNamespaceAndColonIfPresent(context);
}
示例10: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
super.handleInsert(context, item);
final Object object = item.getObject();
if (object instanceof JavaFxClassBackedElementDescriptor) {
final XmlFile xmlFile = (XmlFile)context.getFile();
final String shortName = ((JavaFxClassBackedElementDescriptor)object).getName();
context.commitDocument();
JavaFxPsiUtil.insertImportWhenNeeded(xmlFile, shortName, ((JavaFxClassBackedElementDescriptor)object).getQualifiedName());
}
}
示例11: lookupExpression
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@NotNull
private static LookupElement lookupExpression(@NotNull PsiExpression expression, @Nullable Icon icon, @NotNull String presentableText, @NotNull String lookupText)
{
final LookupElement element = new ExpressionLookupItem(expression, icon, presentableText, lookupText)
{
@Override
public void handleInsert(InsertionContext context)
{
context.getDocument().deleteString(context.getStartOffset(), context.getTailOffset());
context.commitDocument();
replaceText(context, getObject().getText());
}
};
return PrioritizedLookupElement.withPriority(element, 1);
}
示例12: handleParametersInsertion
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
private static void handleParametersInsertion(@NotNull InsertionContext context, @NotNull String text)
{
PsiElement newElement = PsiUtilCore.getElementAtOffset(context.getFile(), context.getStartOffset());
PsiExpressionList parameterList = PsiTreeUtil.getParentOfType(newElement, PsiExpressionList.class);
if(parameterList != null)
{
final TextRange range = parameterList.getTextRange();
context.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), "(" + text + ")");
context.commitDocument();
shortenArgumentsClassReferences(context);
}
}
示例13: replaceText
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
static void replaceText(@NotNull InsertionContext context, @NotNull String text)
{
final PsiElement newElement = PsiUtilCore.getElementAtOffset(context.getFile(), context.getStartOffset());
final PsiElement params = newElement.getParent().getParent();
final int end = params.getTextRange().getEndOffset() - 1;
final int start = Math.min(newElement.getTextRange().getEndOffset(), end);
context.getDocument().replaceString(start, end, text);
context.commitDocument();
shortenArgumentsClassReferences(context);
}
示例14: deleteLookupPlain
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
private void deleteLookupPlain(InsertionContext context) {
Document document = context.getDocument();
document.deleteString(context.getStartOffset(), context.getTailOffset());
context.commitDocument();
}
示例15: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context, final T item) {
final Editor editor = context.getEditor();
final Document document = editor.getDocument();
context.commitDocument();
PsiElement element = findNextToken(context);
final char completionChar = context.getCompletionChar();
final boolean putCaretInside = completionChar == '(' || placeCaretInsideParentheses(context, item);
if (completionChar == '(') {
context.setAddCompletionChar(false);
}
if (isToken(element, "(")) {
int lparenthOffset = element.getTextRange().getStartOffset();
if (mySpaceBeforeParentheses && lparenthOffset == context.getTailOffset()) {
document.insertString(context.getTailOffset(), " ");
lparenthOffset++;
}
if (completionChar == '(' || completionChar == '\t') {
editor.getCaretModel().moveToOffset(lparenthOffset + 1);
} else {
editor.getCaretModel().moveToOffset(context.getTailOffset());
}
context.setTailOffset(lparenthOffset + 1);
PsiElement list = element.getParent();
PsiElement last = list.getLastChild();
if (isToken(last, ")")) {
int rparenthOffset = last.getTextRange().getStartOffset();
context.setTailOffset(rparenthOffset + 1);
if (!putCaretInside) {
for (int i = lparenthOffset + 1; i < rparenthOffset; i++) {
if (!Character.isWhitespace(document.getCharsSequence().charAt(i))) {
return;
}
}
editor.getCaretModel().moveToOffset(context.getTailOffset());
} else if (mySpaceBetweenParentheses && document.getCharsSequence().charAt(lparenthOffset) == ' ') {
editor.getCaretModel().moveToOffset(lparenthOffset + 2);
} else {
editor.getCaretModel().moveToOffset(lparenthOffset + 1);
}
return;
}
} else {
document.insertString(context.getTailOffset(), getSpace(mySpaceBeforeParentheses) + "(" + getSpace(mySpaceBetweenParentheses));
editor.getCaretModel().moveToOffset(context.getTailOffset());
}
if (!myMayInsertRightParenthesis) return;
if (context.getCompletionChar() == '(') {
//todo use BraceMatchingUtil.isPairedBracesAllowedBeforeTypeInFileType
int tail = context.getTailOffset();
if (tail < document.getTextLength() && StringUtil.isJavaIdentifierPart(document.getCharsSequence().charAt(tail))) {
return;
}
}
document.insertString(context.getTailOffset(), getSpace(mySpaceBetweenParentheses) + ")");
if (!putCaretInside) {
editor.getCaretModel().moveToOffset(context.getTailOffset());
}
}