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


Java PsiUtilCore.getLanguageAtOffset方法代码示例

本文整理汇总了Java中com.intellij.psi.util.PsiUtilCore.getLanguageAtOffset方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtilCore.getLanguageAtOffset方法的具体用法?Java PsiUtilCore.getLanguageAtOffset怎么用?Java PsiUtilCore.getLanguageAtOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.util.PsiUtilCore的用法示例。


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

示例1: getElement

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Nullable
private PsiElement getElement(@Nullable final DataContext context) {
    if (context != null) {
        final Editor editor = CommonDataKeys.EDITOR.getData(context);
        if (editor != null) {
            final int offset = editor.getCaretModel().getOffset();
            final PsiFile file = CommonDataKeys.PSI_FILE.getData(context);
            if (file instanceof XmlFile && MuleConfigUtils.isMuleFile(file)) {
                return file.getViewProvider().findElementAt(offset);
            }
            if (file != null) {
                final Language language = PsiUtilCore.getLanguageAtOffset(file, offset);
                if (language != file.getLanguage()) {
                    final PsiFile psiAtOffset = file.getViewProvider().getPsi(language);
                    if (psiAtOffset instanceof XmlFile && MuleConfigUtils.isMuleFile(psiAtOffset)) {
                        return psiAtOffset.findElementAt(offset);
                    }
                }
            }
        }
    }

    return null;
}
 
开发者ID:machaval,项目名称:mule-intellij-plugins,代码行数:25,代码来源:FlowRenameHandler.java

示例2: invoke

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
  PsiDocumentManager.getInstance(project).commitAllDocuments();

  int offset = editor.getCaretModel().getOffset();
  final Language language = PsiUtilCore.getLanguageAtOffset(file, offset);

  final CodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.GOTO_SUPER.forLanguage(language);
  if (codeInsightActionHandler != null) {
    DumbService.getInstance(project).withAlternativeResolveEnabled(new Runnable() {
      @Override
      public void run() {
        codeInsightActionHandler.invoke(project, editor, file);
      }
    });
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GotoSuperAction.java

示例3: findCommenter

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Nullable
private static Commenter findCommenter(Editor editor, PsiFile file, final int line) {
  final FileType fileType = file.getFileType();
  if (fileType instanceof AbstractFileType) {
    return ((AbstractFileType)fileType).getCommenter();
  }

  Document document = editor.getDocument();
  int lineStartOffset = document.getLineStartOffset(line);
  int lineEndOffset = document.getLineEndOffset(line) - 1;
  final CharSequence charSequence = document.getCharsSequence();
  lineStartOffset = CharArrayUtil.shiftForward(charSequence, lineStartOffset, " \t");
  lineEndOffset = CharArrayUtil.shiftBackward(charSequence, lineEndOffset < 0 ? 0 : lineEndOffset, " \t");
  final Language lineStartLanguage = PsiUtilCore.getLanguageAtOffset(file, lineStartOffset);
  final Language lineEndLanguage = PsiUtilCore.getLanguageAtOffset(file, lineEndOffset);
  return CommentByBlockCommentHandler.getCommenter(file, editor, lineStartLanguage, lineEndLanguage);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:CommentByLineCommentHandler.java

示例4: getValidHandler

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Nullable
private CodeInsightActionHandler getValidHandler(@NotNull Editor editor, @NotNull PsiFile file) {
  Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
  final CodeInsightActionHandler codeInsightActionHandler = getLanguageExtension().forLanguage(language);
  if (codeInsightActionHandler != null) {
    if (codeInsightActionHandler instanceof LanguageCodeInsightActionHandler) {
      if (((LanguageCodeInsightActionHandler)codeInsightActionHandler).isValidFor(editor, file)) {
        return codeInsightActionHandler;
      }
    }
    else {
      return codeInsightActionHandler;
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:PresentableActionHandlerBasedAction.java

示例5: getElement

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Nullable
private static PsiElement getElement(@Nullable final DataContext context) {
  if (context != null) {
    final Editor editor = getEditor(context);
    if (editor != null) {
      final int offset = editor.getCaretModel().getOffset();
      final PsiFile file = CommonDataKeys.PSI_FILE.getData(context);
      if (file instanceof XmlFile) {
        return file.getViewProvider().findElementAt(offset);
      }
      if (file != null) {
        final Language language = PsiUtilCore.getLanguageAtOffset(file, offset);
        if (language != file.getLanguage()) {
          final PsiFile psiAtOffset = file.getViewProvider().getPsi(language);
          if (psiAtOffset instanceof XmlFile) {
            return psiAtOffset.findElementAt(offset);
          }
        }
      }
    }
  }

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

示例6: shouldPreselectFirstSuggestion

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
private static boolean shouldPreselectFirstSuggestion(CompletionParameters parameters) {
  if (!Registry.is("ide.completion.autopopup.choose.by.enter")) {
    return false;
  }

  if (Registry.is("ide.completion.lookup.element.preselect.depends.on.context")) {
    for (CompletionPreselectionBehaviourProvider provider : Extensions.getExtensions(CompletionPreselectionBehaviourProvider.EP_NAME)) {
      if (!provider.shouldPreselectFirstSuggestion(parameters)) {
        return false;
      }
    }
  }

  if (!ApplicationManager.getApplication().isUnitTestMode()) {
    return true;
  }

  switch (CodeInsightSettings.getInstance().AUTOPOPUP_FOCUS_POLICY) {
    case CodeInsightSettings.ALWAYS:
      return true;
    case CodeInsightSettings.NEVER:
      return false;
  }

  final Language language = PsiUtilCore.getLanguageAtOffset(parameters.getPosition().getContainingFile(), parameters.getOffset());
  for (CompletionConfidence confidence : CompletionConfidenceEP.forLanguage(language)) {
    //noinspection deprecation
    final ThreeState result = confidence.shouldFocusLookup(parameters);
    if (result != ThreeState.UNSURE) {
      LOG.debug(confidence + " has returned shouldFocusLookup=" + result);
      return result == ThreeState.YES;
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:CompletionProgressIndicator.java

示例7: invoke

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
    return;
  }

  Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
  final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.IMPLEMENT_METHOD.forLanguage(language);
  if (codeInsightActionHandler != null) {
    codeInsightActionHandler.invoke(project, editor, file);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:ImplementMethodsHandler.java

示例8: isValidForFile

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull final PsiFile file) {
  Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
  final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.DELEGATE_METHODS.forLanguage(language);
  if (codeInsightActionHandler != null) {
    return codeInsightActionHandler.isValidFor(editor, file);
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:DelegateMethodsAction.java

示例9: invoke

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
    return;
  }

  Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
  final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.DELEGATE_METHODS.forLanguage(language);
  if (codeInsightActionHandler != null) {
    codeInsightActionHandler.invoke(project, editor, file);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:DelegateMethodsHandler.java

示例10: invoke

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
  if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return;
  if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){
    return;
  }

  Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
  final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.OVERRIDE_METHOD.forLanguage(language);
  if (codeInsightActionHandler != null) {
    codeInsightActionHandler.invoke(project, editor, file);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:OverrideMethodsHandler.java

示例11: getAllTemplateKeys

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@NotNull
public Set<String> getAllTemplateKeys(PsiFile file, int offset) {
  Set<String> keys = Sets.newHashSet();
  Language language = PsiUtilCore.getLanguageAtOffset(file, offset);
  for (PostfixTemplateProvider provider : LanguagePostfixTemplate.LANG_EP.allForLanguage(language)) {
    keys.addAll(getKeys(provider));
  }
  return keys;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:PostfixLiveTemplate.java

示例12: isApplicable

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
public boolean isApplicable(PsiFile file, int offset, boolean wrapping) {
  PostfixTemplatesSettings settings = PostfixTemplatesSettings.getInstance();
  if (wrapping || file == null || settings == null || !settings.isPostfixTemplatesEnabled()) {
    return false;
  }
  Language language = PsiUtilCore.getLanguageAtOffset(file, offset);
  for (PostfixTemplateProvider provider : LanguagePostfixTemplate.LANG_EP.allForLanguage(language)) {
    if (StringUtil.isNotEmpty(computeTemplateKeyWithoutContextChecking(provider, file.getText(), offset + 1))) {
      return true;
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:PostfixLiveTemplate.java

示例13: getLanguageAtCurrentPositionInEditor

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
private static Language getLanguageAtCurrentPositionInEditor(Caret caret, final PsiFile psiFile) {
  int caretOffset = caret.getOffset();
  int mostProbablyCorrectLanguageOffset = caretOffset == caret.getSelectionStart() ||
                                          caretOffset == caret.getSelectionEnd()
                                          ? caret.getSelectionStart()
                                          : caretOffset;
  if (caret.hasSelection()) {
    return getLanguageAtOffset(psiFile, mostProbablyCorrectLanguageOffset, caret.getSelectionEnd());
  }

  return PsiUtilCore.getLanguageAtOffset(psiFile, mostProbablyCorrectLanguageOffset);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:TextEditorPsiDataProvider.java

示例14: getCodeStyleSettings

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
public CommonCodeStyleSettings getCodeStyleSettings() {
  Language lang = PsiUtilCore.getLanguageAtOffset(getFile(), getTailOffset());
  return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(lang);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:InsertionContext.java

示例15: isValidForFile

import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
@Override
protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull final PsiFile file) {
  Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
  return !ShowExpressionTypeHandler.getHandlers(project, language, file.getViewProvider().getBaseLanguage()).isEmpty();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:6,代码来源:ShowExpressionTypeAction.java


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