本文整理汇总了Java中com.intellij.codeInsight.completion.InsertionContext.getFile方法的典型用法代码示例。如果您正苦于以下问题:Java InsertionContext.getFile方法的具体用法?Java InsertionContext.getFile怎么用?Java InsertionContext.getFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.completion.InsertionContext
的用法示例。
在下文中一共展示了InsertionContext.getFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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
示例2: 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);
}
}
示例3: 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;
}
示例4: findNextToken
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Nullable
@RequiredDispatchThread
protected PsiElement findNextToken(final InsertionContext context)
{
final PsiFile file = context.getFile();
PsiElement element = file.findElementAt(context.getTailOffset());
if(element instanceof PsiWhiteSpace)
{
boolean allowParametersOnNextLine = false;
if(!allowParametersOnNextLine && element.getText().contains("\n"))
{
return null;
}
element = file.findElementAt(element.getTextRange().getEndOffset());
}
return element;
}
示例5: findElementBeforeNameFragment
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
private PsiElement findElementBeforeNameFragment(InsertionContext context) {
final PsiFile file = context.getFile();
PsiElement element = file.findElementAt(context.getStartOffset() - 1);
element = getElementInFrontOfWhitespace(file, element);
if (element instanceof LeafPsiElement
&& ((LeafPsiElement) element).getElementType() == XQueryTypes.COLON) {
PsiElement elementBeforeColon = file.findElementAt(context.getStartOffset() - 2);
if (elementBeforeColon != null) {
element = elementBeforeColon;
PsiElement beforeElementBeforeColon = file.findElementAt(elementBeforeColon.getTextRange().getStartOffset() - 1);
if (beforeElementBeforeColon != null) {
element = getElementInFrontOfWhitespace(file, beforeElementBeforeColon);
}
}
}
return element;
}
示例6: 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());
}
}
示例7: addImportForItem
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
public static void addImportForItem(InsertionContext context, PsiClass aClass)
{
if(aClass.getQualifiedName() == null)
{
return;
}
PsiFile file = context.getFile();
int startOffset = context.getStartOffset();
int tail = context.getTailOffset();
int newTail = JavaCompletionUtil.insertClassReference(aClass, file, startOffset, tail);
if(newTail > context.getDocument().getTextLength() || newTail < 0)
{
LOG.error(LogMessageEx.createEvent("Invalid offset after insertion ", "offset=" + newTail + "\n" + "start=" + startOffset + "\n" + "tail=" + tail + "\n" + "file.length=" + file
.getTextLength() + "\n" + "document=" + context.getDocument() + "\n" + DebugUtil.currentStackTrace(), AttachmentFactory.createAttachment(context.getDocument())));
return;
}
context.setTailOffset(newTail);
JavaCompletionUtil.shortenReference(file, context.getStartOffset());
PostprocessReformattingAspect.getInstance(context.getProject()).doPostponedFormatting();
}
示例8: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context) {
PsiFile file = context.getFile();
boolean addDot = !(file instanceof PsiJavaCodeReferenceCodeFragment) || ((PsiJavaCodeReferenceCodeFragment)file).isClassesAccepted();
if (addDot) {
context.setAddCompletionChar(false);
TailType.DOT.processTail(context.getEditor(), context.getTailOffset());
}
if (addDot || context.getCompletionChar() == '.') {
AutoPopupController.getInstance(context.getProject()).scheduleAutoPopup(context.getEditor());
}
}
示例9: 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
示例10: findNextToken
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Nullable
protected PsiElement findNextToken(final InsertionContext context) {
final PsiFile file = context.getFile();
PsiElement element = file.findElementAt(context.getTailOffset());
if (element instanceof PsiWhiteSpace) {
if (!myAllowParametersOnNextLine && element.getText().contains("\n")) {
return null;
}
element = file.findElementAt(element.getTextRange().getEndOffset());
}
return element;
}
示例11: findNextTokenText
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Nullable
private static String findNextTokenText(final InsertionContext context) {
final PsiFile file = context.getFile();
PsiElement element = file.findElementAt(context.getTailOffset());
while (element != null && element.getTextLength() == 0) {
ASTNode next = element.getNode().getTreeNext();
element = next != null ? next.getPsi() : null;
}
return element != null ? element.getText() : null;
}
示例12: handleInsert
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Override
public void handleInsert(InsertionContext context, LookupElement element)
{
Editor editor = context.getEditor();
CaretModel caretModel = editor.getCaretModel();
Document document = context.getEditor().getDocument();
PhpFile file = (PhpFile) context.getFile();
PsiElement currElement = file.findElementAt(editor.getCaretModel().getOffset());
StringBuilder buffer = new StringBuilder();
int newOffset = caretModel.getOffset();
if (insertSpace) {
buffer.append(' ');
newOffset++;
}
PsiElement testElement = currElement;
if (testElement!= null && !(testElement.getNode().getElementType().equals(PhpDocPropertyTagParser.DOC_WHITESPACE))) {
testElement = testElement.getNextSibling();
}
if (testElement != null && !(testElement.getNode().getElementType().equals(PhpDocPropertyTagParser.DOC_RBRACE))) {
buffer.append('}');
}
document.insertString(caretModel.getOffset(), buffer.toString());
caretModel.moveToOffset(newOffset);
}
示例13: findNextToken
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Nullable
protected PsiElement findNextToken(final InsertionContext context)
{
final PsiFile file = context.getFile();
PsiElement element = file.findElementAt(context.getTailOffset());
if(element instanceof PsiWhiteSpace)
{
if(!myAllowParametersOnNextLine && element.getText().contains("\n"))
{
return null;
}
element = file.findElementAt(element.getTextRange().getEndOffset());
}
return element;
}
示例14: isAcceptable
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
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;
}
示例15: findNextToken
import com.intellij.codeInsight.completion.InsertionContext; //导入方法依赖的package包/类
@Nullable
protected PsiElement findNextToken(final InsertionContext context)
{
final PsiFile file = context.getFile();
PsiElement element = file.findElementAt(context.getTailOffset());
if(element instanceof PsiWhiteSpace)
{
if(element.getText().contains("\n"))
{
return null;
}
element = file.findElementAt(element.getTextRange().getEndOffset());
}
return element;
}