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


Java DataContext.getData方法代码示例

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


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

示例1: prepareContext

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
@NotNull
private static DataContext prepareContext(@NotNull Component component, @NotNull final Project project) {
  // There is a possible case that formatting is performed from project view and editor is not opened yet. The problem is that
  // its data context doesn't contain information about project then. So, we explicitly support that here (see IDEA-72791).
  final DataContext baseDataContext = DataManager.getInstance().getDataContext(component);
  return new DelegatingDataContext(baseDataContext) {
    @Override
    public Object getData(@NonNls String dataId) {
      Object result = baseDataContext.getData(dataId);
      if (result == null && CommonDataKeys.PROJECT.is(dataId)) {
        result = project;
      }
      return result;
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:CodeFormatterFacade.java

示例2: execute

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
public void execute(@NotNull Editor editor, char charTyped, @NotNull DataContext dataContext) {
  myOriginalHandler.execute(editor, charTyped, dataContext);
  if (isMatchForClosingTag(editor, charTyped)) {
    int offset = editor.getCaretModel().getOffset();
    PsiFile file = dataContext.getData(LangDataKeys.PSI_FILE);
    if (file == null) {
      return;
    }
    PsiElement el = file.findElementAt(offset - 1);
    TagBlockElement block = (TagBlockElement) PsiTreeUtil
        .findFirstParent(el,
            parent -> parent instanceof TagBlockElement && !(parent instanceof SoyChoiceClause));
    if (block == null) {
      return;
    }
    String closingTag = block.getOpeningTag().generateClosingTag();
    insertClosingTag(editor, offset, closingTag);
    if (editor.getProject() != null) {
      PsiDocumentManager.getInstance(editor.getProject()).commitDocument(editor.getDocument());
      CodeStyleManager.getInstance(editor.getProject()).reformat(block);
    }
  }
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:24,代码来源:ClosingTagHandler.java

示例3: update

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
@Override
public void update(AnActionEvent e) {
  final DataContext context = e.getDataContext();

  final DataContext patchedContext = new DataContext() {
    @Override
    public Object getData(@NonNls String dataId) {
      final Object data = context.getData(dataId);
      if (data != null) {
        return data;
      }
      if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        final XmlTag[] tags = getXmlTagsFromExternalContext(context);
        return tags.length == 1 ? tags[0] : null;
      }
      else if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
        return getXmlTagsFromExternalContext(context);
      }
      return null;
    }
  };
  super.update(new AnActionEvent(e.getInputEvent(), patchedContext, e.getPlace(), e.getPresentation(),
                                 e.getActionManager(), e.getModifiers()));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:AndroidBaseXmlRefactoringAction.java

示例4: getFile

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
private static PsiFile getFile(final Editor editor,
                               final DataContext context)
{
    final Project project = (Project) context.getData(DataConstants.PROJECT);
    final Document document = editor.getDocument();
    final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
    final VirtualFile virtualFile = fileDocumentManager.getFile(document);
    final PsiManager psiManager = PsiManager.getInstance(project);
    return psiManager.findFile(virtualFile);
}
 
开发者ID:DaveKriewall,项目名称:Rearranger,代码行数:11,代码来源:LiveRearrangerActionHandler.java

示例5: getSelectedJavaFile

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
/**
 * Gets the javafile that's currently selected in the editor. Returns null if it's not a java file.
 *
 * @param dataContext data context.
 * @return The current javafile. Null if not a javafile.
 */
public static PsiJavaFile getSelectedJavaFile(DataContext dataContext) {
    final PsiFile psiFile = (PsiFile) dataContext.getData("psi.File");

    if (!(psiFile instanceof PsiJavaFile)) {
        return null;
    } else {
        return (PsiJavaFile) psiFile;
    }
}
 
开发者ID:zeng198821,项目名称:CodeGenerate,代码行数:16,代码来源:CodeMakerUtil.java

示例6: update

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
@Override
public void update(
    final Editor editor, final Presentation presentation, final DataContext dataContext
) {
    super.update(editor, presentation, dataContext);
    final VirtualFile file = dataContext.getData(CommonDataKeys.VIRTUAL_FILE);
    final boolean enabled = file != null && file.getName().endsWith(".impex");
    presentation.setEnabledAndVisible(enabled);
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:10,代码来源:AbstractImpexTableFormatAction.java

示例7: update

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
public void update(final AnActionEvent event) {
    log.debug("update");
    super.update(event);

    final Presentation presentation = event.getPresentation();
    final DataContext context = event.getDataContext();
    Module module = (Module) context.getData(LangDataKeys.MODULE.getName());

    log.debug("update: module: " + module);

    final boolean hasModule = module != null;
    presentation.setEnabled(hasModule);
    presentation.setVisible(hasModule);
}
 
开发者ID:internetisalie,项目名称:lua-for-idea,代码行数:15,代码来源:NewLuaActionBase.java

示例8: getFile

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
private static PsiFile getFile(final Editor      editor ,
                               final DataContext context )
{
    final Project             project             = (Project) context.getData(DataConstants.PROJECT);
    final Document            document            = editor.getDocument();
    final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
    final VirtualFile         virtualFile         = fileDocumentManager.getFile(document);
    final PsiManager          psiManager          = PsiManager.getInstance(project);
    return psiManager.findFile(virtualFile);
}
 
开发者ID:DaveKriewall,项目名称:Rearranger,代码行数:11,代码来源:RearrangerActionHandler.java

示例9: RearrangeIt

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
public RearrangeIt(final DataContext dc)
{
    this.dc = dc;
    if (dc != null) {
        this.project = (Project) dc.getData(DataConstants.PROJECT);
    }
    else this.project = null;
}
 
开发者ID:DaveKriewall,项目名称:Rearranger,代码行数:9,代码来源:ProjectTreeActionHandler.java

示例10: execute

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
public final void execute(final Editor editor, final DataContext context)
{
    if (editor == null)
    {
        return;
    }
    final Project project = (Project) context.getData(DataConstants.PROJECT);
    logger.debug("project=" + project);
    logger.debug("editor=" + editor);
    final Document document = editor.getDocument();
    final CaretModel caret = editor.getCaretModel();
    int cursorOffset = caret.getOffset();
    final PsiFile psiFile = getFile(editor, context);
    if (!psiFile.getName().endsWith(".java"))
    {
        logger.debug("not a .java file -- skipping " + psiFile.getName());
        return;
    }
    if (!RearrangerActionHandler.isFileWritable(psiFile))
    {
        logger.debug("not a writable .java file -- skipping " + psiFile.getName());
        return;
    }
    logger.debug("inProgress=" + inProgress);
    if (!useDialog)
    {
        if (inProgress)
        {
            return;
        }
        setInProgress(true);
    }
    buildLiveRearrangerData(project, document, psiFile, cursorOffset);
}
 
开发者ID:DaveKriewall,项目名称:Rearranger,代码行数:35,代码来源:LiveRearrangerActionHandler.java

示例11: execute

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
public final void execute(final Editor editor, final DataContext context)
{
    if (editor == null) {
        return;
    }
    final Project     project     = (Project) context.getData(DataConstants.PROJECT);
    logger.debug("project=" + project);
    logger.debug("editor=" + editor);
    final Document    document    = editor.getDocument();
    final CaretModel  caret = editor.getCaretModel();
    int cursorOffset = caret.getOffset();
    final PsiFile     psiFile     = getFile(editor, context);
    if (!psiFile.getName().endsWith(".java")) {
        logger.debug("not a .java file -- skipping " + psiFile.getName());
        return;
    }
    if (!psiFile.isWritable()) {
        logger.debug("not a writable .java file -- skipping " + psiFile.getName());
        return;
    }
    logger.debug("inProgress=" + inProgress);
    if (inProgress) {
        return;
    }

    setInProgress(true);
    buildLiveRearrangerData(project, document, psiFile, cursorOffset);
}
 
开发者ID:DaveKriewall,项目名称:Rearranger,代码行数:29,代码来源:RearrangementResult31.java

示例12: getProjectAwareDataContext

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
@NotNull
private DataContext getProjectAwareDataContext(@NotNull final DataContext original) {
  if (CommonDataKeys.PROJECT.getData(original) == myProject) return original;

  return new DataContext() {
    @Override
    public Object getData(String dataId) {
      if (CommonDataKeys.PROJECT.is(dataId)) {
        return myProject;
      }
      return original.getData(dataId);
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:bigFile.java

示例13: getCurrentEditorDataContext

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
@NotNull
protected static DataContext getCurrentEditorDataContext() {
  final DataContext defaultContext = DataManager.getInstance().getDataContext();
  return new DataContext() {
    @Override
    @Nullable
    public Object getData(@NonNls String dataId) {
      if (CommonDataKeys.EDITOR.is(dataId)) {
        return getEditor();
      }
      if (CommonDataKeys.PROJECT.is(dataId)) {
        return getProject();
      }
      if (CommonDataKeys.PSI_FILE.is(dataId)) {
        return getFile();
      }
      if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
        PsiFile file = getFile();
        if (file == null) return null;
        Editor editor = getEditor();
        if (editor == null) return null;
        return file.findElementAt(editor.getCaretModel().getOffset());
      }
      return defaultContext.getData(dataId);
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:LightPlatformCodeInsightTestCase.java

示例14: doExecute

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
@Override
protected void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) {
    System.out.println("doExecute called: editor = [" + editor + "], caret = [" + caret + "], " +
            "dataContext = [" + dataContext + "]");
    super.doExecute(editor, caret, dataContext);

    Project project = (Project) dataContext.getData(DataKeys.PROJECT.getName());
    if (project == null) return;

    PsiFile rootPsiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
    if (rootPsiFile == null) return;

    PsiClass sourceClassName = Stream.of(rootPsiFile.getChildren())
            .peek(psiElement -> System.out.println(psiElement.getClass()))
            .filter(psiElement -> psiElement instanceof PsiClass)
            .peek(System.out::println)
            .map(psiElement -> (PsiClass) psiElement)
            .collect(Collectors.toList()).get(0);
    SourceClass sourceClass = new SourceClass(sourceClassName.getName());

    List<Variable> extractedVariables = Stream.of(rootPsiFile.getChildren())
            .filter(psiElement -> psiElement instanceof PsiClassImpl)
            .map(PsiElement::getChildren)
            .flatMap(Arrays::stream)
            .filter(psiElement -> psiElement instanceof PsiVariable)
            .map(psiElement -> (PsiVariable) psiElement)
            .map(psiVariable -> new Variable(
                    new Type(psiVariable.getType().getCanonicalText()),
                    new Variable.Name(psiVariable.getName())))
            .peek(System.out::println)
            .collect(Collectors.toList());
    if (extractedVariables.isEmpty()) return;

    PsiClassImpl sourceJavaPsiClass = getRootClassUnderOperation(rootPsiFile);
    if (sourceJavaPsiClass == null) return;

    GeneratedValueWriter writeActionRunner = new GeneratedValueWriter(
            sourceJavaPsiClass, project, extractedVariables, sourceClass, rootPsiFile
    );
    WriteCommandAction.runWriteCommandAction(project, writeActionRunner);
}
 
开发者ID:Ingwersaft,项目名称:ValueClassGenerator,代码行数:42,代码来源:GenerateValueClassHandler.java

示例15: getProject

import com.intellij.openapi.actionSystem.DataContext; //导入方法依赖的package包/类
public static Project getProject() {
    DataContext dataContext = DataManager.getInstance().getDataContextFromFocus().getResult();

    return (Project) dataContext.getData(CommonDataKeys.PROJECT.getName());
}
 
开发者ID:SlalomConsulting,项目名称:sutr-io,代码行数:6,代码来源:SutrPluginUtil.java


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