本文整理汇总了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;
}
示例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);
}
});
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例14: getCodeStyleSettings
import com.intellij.psi.util.PsiUtilCore; //导入方法依赖的package包/类
public CommonCodeStyleSettings getCodeStyleSettings() {
Language lang = PsiUtilCore.getLanguageAtOffset(getFile(), getTailOffset());
return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(lang);
}
示例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();
}