本文整理汇总了Java中com.intellij.ide.util.EditorHelper类的典型用法代码示例。如果您正苦于以下问题:Java EditorHelper类的具体用法?Java EditorHelper怎么用?Java EditorHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EditorHelper类属于com.intellij.ide.util包,在下文中一共展示了EditorHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFromTemplate
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
public static void createFromTemplate(@NotNull Project project,
@NotNull PsiDirectory taskDirectory,
@NotNull String name,
@Nullable IdeView view,
boolean open) {
FileTemplate template = FileTemplateManager.getInstance(project).getInternalTemplate(name);
if (template == null) {
LOG.info("Template " + name + " wasn't found");
return;
}
try {
final PsiElement file = FileTemplateUtil.createFromTemplate(template, name, null, taskDirectory);
if (view != null && open) {
EditorHelper.openInEditor(file, false);
view.selectElement(file);
}
}
catch (Exception e) {
LOG.error(e);
}
}
示例2: configure
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
public void configure(final Project project, final MavenId projectId, final String muleVersion, final VirtualFile root)
{
try
{
//Create mule folders.
final VirtualFile appDirectory = VfsUtil.createDirectories(root.getPath() + "/src/main/domain");
final VirtualFile resources = VfsUtil.createDirectories(root.getPath() + "/src/main/resources");
final VirtualFile muleConfigFile = createMuleConfigFile(project, projectId, appDirectory);
createMuleDeployPropertiesFile(project, projectId, appDirectory);
createPomFile(project, projectId, muleVersion, root);
// execute when current dialog is closed (e.g. Project Structure)
MavenUtil.invokeLater(project, ModalityState.NON_MODAL, () -> EditorHelper.openInEditor(getPsiFile(project, muleConfigFile)));
}
catch (IOException e)
{
e.printStackTrace();
}
}
示例3: selectElement
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
@Override
public void selectElement(final PsiElement element) {
final boolean isDirectory = element instanceof PsiDirectory;
if (!isDirectory) {
EditorHelper.openInEditor(element);
}
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
myBuilder.selectElement(element, PsiUtilCore.getVirtualFile(element));
if (!isDirectory) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (myMoveFocus) {
ToolWindowManager.getInstance(myProject).activateEditorComponent();
}
}
});
}
}
}, ModalityState.NON_MODAL);
}
示例4: selectElement
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
@Override
public void selectElement(final PsiElement element) {
if (element != null) {
selectPsiElement(element, false);
boolean requestFocus = true;
final boolean isDirectory = element instanceof PsiDirectory;
if (!isDirectory) {
Editor editor = EditorHelper.openInEditor(element);
if (editor != null) {
ToolWindowManager.getInstance(myProject).activateEditorComponent();
requestFocus = false;
}
}
if (requestFocus) {
selectPsiElement(element, true);
}
}
}
示例5: startLiveTemplate
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
public static void startLiveTemplate(PsiFile file) {
Project project = file.getProject();
final Editor editor = EditorHelper.openInEditor(file);
if (editor == null) return;
final TemplateImpl template = new TemplateImpl("", file.getText(), "");
template.setInline(true);
int count = template.getSegmentsCount();
if (count == 0) return;
Set<String> variables = new HashSet<String>();
for (int i = 0; i < count; i++) {
variables.add(template.getSegmentName(i));
}
variables.removeAll(TemplateImpl.INTERNAL_VARS_SET);
for (String variable : variables) {
template.addVariable(variable, null, "\"" + variable + "\"", true);
}
WriteCommandAction.runWriteCommandAction(project, new Runnable() {
@Override
public void run() {
editor.getDocument().setText(template.getTemplateText());
}
});
TemplateManager.getInstance(project).startTemplate(editor, template);
}
示例6: selectElement
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
@Override
public void selectElement(PsiElement element) {
selectPsiElement(element, false);
boolean requestFocus = true;
if (element != null) {
final boolean isDirectory = element instanceof PsiDirectory;
if (!isDirectory) {
FileEditor editor = EditorHelper.openInEditor(element, false);
if (editor != null) {
ToolWindowManager.getInstance(myProject).activateEditorComponent();
requestFocus = false;
}
}
}
if (requestFocus) {
selectPsiElement(element, true);
}
}
示例7: selectElement
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
@Override
public void selectElement(final PsiElement element) {
if (element != null) {
final PackageSet packageSet = getCurrentScope().getValue();
final PsiFile psiFile = element.getContainingFile();
if (packageSet == null) return;
final VirtualFile virtualFile = psiFile != null ? psiFile.getVirtualFile() :
(element instanceof PsiDirectory ? ((PsiDirectory)element).getVirtualFile() : null);
if (virtualFile != null) {
final ProjectView projectView = ProjectView.getInstance(myProject);
final NamedScopesHolder holder = NamedScopesHolder.getHolder(myProject, CURRENT_SCOPE_NAME, myDependencyValidationManager);
if (packageSet instanceof PackageSetBase && !((PackageSetBase)packageSet).contains(virtualFile, myProject, holder) ||
psiFile != null && !packageSet.contains(psiFile, holder)) {
projectView.changeView(ProjectViewPane.ID);
}
projectView.select(element, virtualFile, false);
}
Editor editor = EditorHelper.openInEditor(element);
if (editor != null) {
ToolWindowManager.getInstance(myProject).activateEditorComponent();
}
}
}
示例8: createFromTemplateAndOpen
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
private static void createFromTemplateAndOpen(@NotNull final PsiDirectory taskDirectory,
@Nullable final FileTemplate template,
@Nullable IdeView view) {
if (template == null) {
return;
}
try {
final PsiElement file = FileTemplateUtil.createFromTemplate(template, template.getName(), null, taskDirectory);
if (view != null) {
EditorHelper.openInEditor(file, false);
view.selectElement(file);
}
}
catch (Exception e) {
LOG.error(e);
}
}
示例9: startLiveTemplate
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
public static void startLiveTemplate(@Nonnull PsiFile file, @Nonnull Map<String, String> defaultValues) {
Editor editor = EditorHelper.openInEditor(file);
if (editor == null) return;
TemplateImpl template = new TemplateImpl("", file.getText(), "");
template.setInline(true);
int count = template.getSegmentsCount();
if (count == 0) return;
Set<String> variables = new HashSet<>();
for (int i = 0; i < count; i++) {
variables.add(template.getSegmentName(i));
}
variables.removeAll(TemplateImpl.INTERNAL_VARS_SET);
for (String variable : variables) {
String defaultValue = defaultValues.getOrDefault(variable, variable);
template.addVariable(variable, null, '"' + defaultValue + '"', true);
}
Project project = file.getProject();
WriteCommandAction.runWriteCommandAction(project, () -> editor.getDocument().setText(template.getTemplateText()));
editor.getCaretModel().moveToOffset(0); // ensures caret at the start of the template
TemplateManager.getInstance(project).startTemplate(editor, template);
}
示例10: selectElement
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
@Override
public void selectElement(final PsiElement element) {
if (element != null) {
final PackageSet packageSet = getCurrentScope().getValue();
final PsiFile psiFile = element.getContainingFile();
if (packageSet == null) return;
final VirtualFile virtualFile = psiFile != null ? psiFile.getVirtualFile() :
(element instanceof PsiDirectory ? ((PsiDirectory)element).getVirtualFile() : null);
if (virtualFile != null) {
final ProjectView projectView = ProjectView.getInstance(myProject);
final NamedScopesHolder holder = NamedScopesHolder.getHolder(myProject, CURRENT_SCOPE_NAME, myDependencyValidationManager);
if (packageSet instanceof PackageSetBase && !((PackageSetBase)packageSet).contains(virtualFile, holder) ||
psiFile != null && !packageSet.contains(psiFile, holder)) {
projectView.changeView(ProjectViewPane.ID);
}
projectView.select(element, virtualFile, false);
}
Editor editor = EditorHelper.openInEditor(element);
if (editor != null) {
ToolWindowManager.getInstance(myProject).activateEditorComponent();
}
}
}
示例11: configure
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
public void configure(final Project project, final MavenId projectId, final String muleVersion, final VirtualFile root, @Nullable MavenId parentId)
{
try
{
//Create mule folders.
final VirtualFile appDirectory = VfsUtil.createDirectories(root.getPath() + "/src/main/app");
final VirtualFile resources = VfsUtil.createDirectories(root.getPath() + "/src/main/resources");
createLog4J(project, projectId, resources);
final VirtualFile muleConfigFile = createMuleConfigFile(project, projectId, appDirectory);
createMuleDeployPropertiesFile(project, projectId, appDirectory);
createMuleAppPropertiesFiles(project, appDirectory);
VfsUtil.createDirectories(root.getPath() + "/src/main/api");
//MUnit support
VfsUtil.createDirectories(root.getPath() + "/src/test/munit");
final VirtualFile testResources = VfsUtil.createDirectories(root.getPath() + "/src/test/resources");
createLog4JTest(project, projectId, testResources);
if (parentId == null)
createPomFile(project, projectId, muleVersion, root);
else
createModulePomFile(project, projectId, root, parentId);
// execute when current dialog is closed (e.g. Project Structure)
MavenUtil.invokeLater(project, ModalityState.NON_MODAL, () -> EditorHelper.openInEditor(getPsiFile(project, muleConfigFile)));
}
catch (IOException e)
{
e.printStackTrace();
}
}
示例12: selectElement
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
@Override
public void selectElement(PsiElement element) {
PsiFileSystemItem psiFile;
if (element instanceof PsiFileSystemItem) {
psiFile = (PsiFileSystemItem)element;
}
else {
psiFile = element.getContainingFile();
if (psiFile == null) {
return;
}
}
VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile == null) {
return;
}
selectFile(virtualFile, false);
boolean requestFocus = true;
if (psiFile instanceof PsiFile) {
Editor editor = EditorHelper.openInEditor(element);
if (editor != null) {
ToolWindowManager.getInstance(myProject).activateEditorComponent();
requestFocus = false;
}
}
if (requestFocus) {
selectFile(virtualFile, true);
}
}
示例13: selectElement
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
public void selectElement(PsiElement element) {
PsiFileSystemItem psiFile;
if (!(element instanceof PsiFileSystemItem)) {
psiFile = element.getContainingFile();
}
else {
psiFile = (PsiFileSystemItem)element;
}
if (psiFile == null) return;
VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile == null) return;
selectFile(virtualFile, false);
boolean requestFocus = true;
if (psiFile instanceof PsiFile) {
Editor editor = EditorHelper.openInEditor(element);
if (editor != null) {
ToolWindowManager.getInstance(myProject).activateEditorComponent();
requestFocus = false;
}
}
if (requestFocus) {
selectFile(virtualFile, true);
}
}
示例14: doRefactoring
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
private void doRefactoring(UsageInfo[] usages) throws IncorrectOperationException {
myTypeParameterReplacements = buildTypeParameterReplacements();
List<PsiClass> inheritors = new ArrayList<PsiClass>();
CommonRefactoringUtil.sortDepthFirstRightLeftOrder(usages);
// Process usages
for (final UsageInfo usage : usages) {
if (usage instanceof MethodCallUsageInfo) {
processMethodCall((MethodCallUsageInfo)usage);
}
else if (usage instanceof ParameterUsageInfo) {
processParameterUsage((ParameterUsageInfo)usage);
}
else if (usage instanceof ImplementingClassUsageInfo) {
inheritors.add(((ImplementingClassUsageInfo)usage).getPsiClass());
}
}
prepareTypeParameterReplacement();
myTargetParameter.delete();
ChangeContextUtil.encodeContextInfo(myMethod, true);
if (!myTargetClass.isInterface()) {
PsiMethod method = addMethodToClass(myTargetClass);
fixVisibility(method, usages);
EditorHelper.openInEditor(method);
}
else {
final PsiMethod interfaceMethod = addMethodToClass(myTargetClass);
final PsiModifierList modifierList = interfaceMethod.getModifierList();
modifierList.setModifierProperty(PsiModifier.PRIVATE, false);
modifierList.setModifierProperty(PsiModifier.PUBLIC, false);
modifierList.setModifierProperty(PsiModifier.PROTECTED, false);
RefactoringUtil.makeMethodAbstract(myTargetClass, interfaceMethod);
EditorHelper.openInEditor(interfaceMethod);
for (final PsiClass psiClass : inheritors) {
final PsiMethod newMethod = addMethodToClass(psiClass);
PsiUtil.setModifierProperty(newMethod, myNewVisibility != null && !myNewVisibility.equals(VisibilityUtil.ESCALATE_VISIBILITY) ? myNewVisibility
: PsiModifier.PUBLIC, true);
}
}
myMethod.delete();
}
示例15: performRefactoring
import com.intellij.ide.util.EditorHelper; //导入依赖的package包/类
protected void performRefactoring(@NotNull UsageInfo[] usages) {
if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, myTargetClass)) return;
PsiMethod patternMethod = createMethodToAdd();
final List<PsiReference> docRefs = new ArrayList<PsiReference>();
for (UsageInfo usage : usages) {
if (usage instanceof InheritorUsageInfo) {
final PsiClass inheritor = ((InheritorUsageInfo)usage).getInheritor();
addMethodToClass(inheritor, patternMethod, true);
}
else if (usage instanceof MethodCallUsageInfo && !((MethodCallUsageInfo)usage).isInternal()) {
final PsiElement expression = ((MethodCallUsageInfo)usage).getMethodCallExpression();
if (expression instanceof PsiMethodCallExpression) {
correctMethodCall((PsiMethodCallExpression)expression, false);
} else if (expression instanceof PsiMethodReferenceExpression) {
PsiExpression newQualifier = JavaPsiFacade.getInstance(myProject).getElementFactory().createExpressionFromText(myTargetVariable.getType().getCanonicalText(), null);
((PsiMethodReferenceExpression)expression).setQualifierExpression(newQualifier);
}
}
else if (usage instanceof JavadocUsageInfo) {
docRefs.add(usage.getElement().getReference());
}
}
try {
if (myTargetClass.isInterface()) patternMethod.getBody().delete();
final PsiMethod method = addMethodToClass(myTargetClass, patternMethod, false);
myMethod.delete();
for (PsiReference reference : docRefs) {
reference.bindToElement(method);
}
VisibilityUtil.fixVisibility(UsageViewUtil.toElements(usages), method, myNewVisibility);
if (myOpenInEditor) {
EditorHelper.openInEditor(method);
}
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}