本文整理匯總了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;
}
};
}
示例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);
}
}
}
示例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()));
}
示例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);
}
示例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;
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
};
}
示例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);
}
};
}
示例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);
}
示例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());
}