com.intellij.openapi.application.Result Java Examples

The following examples show how to use com.intellij.openapi.application.Result. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CrudUtils.java    From crud-intellij-plugin with Apache License 2.0 6 votes vote down vote up
public static void doOptimize(Project project) {
    DumbService.getInstance(project).runWhenSmart((DumbAwareRunnable) () -> new WriteCommandAction(project) {
        @Override
        protected void run(@NotNull Result result) {
            for (VirtualFile virtualFile : virtualFiles) {
                try {
                    PsiJavaFile javaFile = (PsiJavaFile) PsiManager.getInstance(project).findFile(virtualFile);
                    if (javaFile != null) {
                        CodeStyleManager.getInstance(project).reformat(javaFile);
                        JavaCodeStyleManager.getInstance(project).optimizeImports(javaFile);
                        JavaCodeStyleManager.getInstance(project).shortenClassReferences(javaFile);
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            virtualFiles.clear();
        }
    }.execute());
}
 
Example #2
Source File: CodeInsightTestUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void doIntentionTest(@Nonnull final CodeInsightTestFixture fixture, @NonNls final String action,
                                   @Nonnull final String before, @Nonnull final String after) {
  fixture.configureByFile(before);
  List<IntentionAction> availableIntentions = fixture.getAvailableIntentions();
  final IntentionAction intentionAction = findIntentionByText(availableIntentions, action);
  if (intentionAction == null) {
    Assert.fail("Action not found: " + action + " in place: " + fixture.getElementAtCaret() + " among " + availableIntentions);
  }
  new WriteCommandAction(fixture.getProject()) {
    @Override
    protected void run(Result result) throws Throwable {
      fixture.launchAction(intentionAction);
    }
  }.execute();
  fixture.checkResultByFile(after, false);
}
 
Example #3
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected PsiFile addFileToProject(final String rootPath, final String relativePath, final String fileText) {
  return new WriteCommandAction<PsiFile>(getProject()) {
    @Override
    protected void run(Result<PsiFile> result) throws Throwable {
      try {
        if (myTempDirFixture instanceof LightTempDirTestFixtureImpl) {
          final VirtualFile file = myTempDirFixture.createFile(relativePath, fileText);
          result.setResult(PsiManager.getInstance(getProject()).findFile(file));
        }
        else {
          result.setResult(((HeavyIdeaTestFixture)myProjectFixture).addFileToProject(rootPath, relativePath, fileText));
        }
      }
      catch (IOException e) {
        throw new RuntimeException(e);
      }
      finally {
        ((PsiModificationTrackerImpl)PsiManager.getInstance(getProject()).getModificationTracker()).incCounter();
      }
    }
  }.execute().getResultObject();
}
 
Example #4
Source File: MuleMavenProjectBuilderHelper.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
private VirtualFile createLog4JTest(final Project project, final MavenId projectId, final VirtualFile appDirectory)
{
    return new WriteCommandAction<VirtualFile>(project, "Create Log4J Test File", PsiFile.EMPTY_ARRAY)
    {
        @Override
        protected void run(@NotNull Result<VirtualFile> result) throws Throwable
        {

            try
            {
                VirtualFile configFile = appDirectory.findOrCreateChildData(this, "log4j2-test.xml");
                final FileTemplateManager manager = FileTemplateManager.getInstance(project);
                final FileTemplate template = manager.getInternalTemplate(MuleFileTemplateDescriptorManager.LOG4J2_TEST);
                final Properties defaultProperties = manager.getDefaultProperties();
                final String text = template.getText(defaultProperties);
                VfsUtil.saveText(configFile, text);
                result.setResult(configFile);
            }
            catch (IOException e)
            {
                showError(project, e);
            }
        }
    }.execute().getResultObject();
}
 
Example #5
Source File: InplaceVariableIntroducer.java    From consulo with Apache License 2.0 6 votes vote down vote up
public InplaceVariableIntroducer(PsiNamedElement elementToRename,
                                 Editor editor,
                                 Project project,
                                 String title, E[] occurrences, 
                                 @Nullable E expr) {
  super(editor, elementToRename, project);
  myTitle = title;
  myOccurrences = occurrences;
  if (expr != null) {
    final ASTNode node = expr.getNode();
    final ASTNode astNode = LanguageTokenSeparatorGenerators.INSTANCE.forLanguage(expr.getLanguage())
      .generateWhitespaceBetweenTokens(node.getTreePrev(), node);
    if (astNode != null) {
      new WriteCommandAction<Object>(project, "Normalize declaration") {
        @Override
        protected void run(Result<Object> result) throws Throwable {
          node.getTreeParent().addChild(astNode, node);
        }
      }.execute();
    }
    myExpr = expr;
  }
  myExprMarker = myExpr != null && myExpr.isPhysical() ? createMarker(myExpr) : null;
  initOccurrencesMarkers();
}
 
Example #6
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public PsiFile configureByText(final FileType fileType, @NonNls final String text) {
  assertInitialized();
  final String extension = fileType.getDefaultExtension();
  final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
  if (fileTypeManager.getFileTypeByExtension(extension) != fileType) {
    new WriteCommandAction(getProject()) {
      @Override
      protected void run(Result result) throws Exception {
        fileTypeManager.associateExtension(fileType, extension);
      }
    }.execute();
  }
  final String fileName = "aaa." + extension;
  return configureByText(fileName, text);
}
 
Example #7
Source File: PsiTestUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static Module addModule(final Project project, final String name, final VirtualFile root) {
  return new WriteCommandAction<Module>(project) {
    @Override
    protected void run(Result<Module> result) throws Throwable {
      final ModifiableModuleModel moduleModel = ModuleManager.getInstance(project).getModifiableModel();
      String moduleName = moduleModel.newModule(name, root.getPath()).getName();
      moduleModel.commit();

      final Module dep = ModuleManager.getInstance(project).findModuleByName(moduleName);
      final ModifiableRootModel model = ModuleRootManager.getInstance(dep).getModifiableModel();
      final ContentEntry entry = model.addContentEntry(root);
      entry.addFolder(root, ProductionContentFolderTypeProvider.getInstance());

      model.commit();
      result.setResult(dep);
    }
  }.execute().getResultObject();
}
 
Example #8
Source File: OperatorCompletionAction.java    From nosql4idea with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
    final Document document = editor.getDocument();
    CaretModel caretModel = editor.getCaretModel();
    final int offset = caretModel.getOffset();
    new PopupChooserBuilder(QUERY_OPERATOR_LIST)
            .setMovable(false)
            .setCancelKeyEnabled(true)
            .setItemChoosenCallback(new Runnable() {
                public void run() {
                    final String selectedQueryOperator = (String) QUERY_OPERATOR_LIST.getSelectedValue();
                    if (selectedQueryOperator == null) return;

                    new WriteCommandAction(project, MONGO_OPERATOR_COMPLETION) {
                        @Override
                        protected void run(@NotNull Result result) throws Throwable {
                            document.insertString(offset, selectedQueryOperator);
                        }
                    }.execute();
                }
            })
            .createPopup()
            .showInBestPositionFor(editor);
}
 
Example #9
Source File: AbstractVcsTestCase.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static VirtualFile copyFileInCommand(final Project project,
                                            final VirtualFile file,
                                            final VirtualFile newParent,
                                            final String newName) {
  return new WriteCommandAction<VirtualFile>(project) {
    @Override
    protected void run(Result<VirtualFile> result) throws Throwable {
      try {
        result.setResult(file.copy(this, newParent, newName));
      }
      catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
  }.execute().getResultObject();
}
 
Example #10
Source File: Reverter.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void revert() throws IOException {
  try {
    new WriteCommandAction(myProject, getCommandName()) {
      @Override
      protected void run(Result objectResult) throws Throwable {
        myGateway.saveAllUnsavedDocuments();
        doRevert();
        myGateway.saveAllUnsavedDocuments();
      }
    }.execute();
  }
  catch (RuntimeException e) {
    Throwable cause = e.getCause();
    if (cause instanceof IOException) {
      throw (IOException)cause;
    }
    throw e;
  }
}
 
Example #11
Source File: SpringBootModuleBuilder.java    From crud-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
	Selection selection = SelectionContext.copyToSelection();
	if (this.myJdk != null) {
		rootModel.setSdk(this.myJdk);
	} else {
		rootModel.inheritSdk();
	}
	SelectionContext.clearAllSet();
	Project project = rootModel.getProject();
	VirtualFile root = createAndGetContentEntry();
	rootModel.addContentEntry(root);
	CrudUtils.runWhenInitialized(project, () -> new WriteCommandAction<VirtualFile>(project) {
		@Override
		protected void run(@NotNull Result<VirtualFile> result) throws Throwable {
			initProject(project, selection);
		}
	}.execute());
}
 
Example #12
Source File: NewClassCommandAction.java    From json2java4idea with Apache License 2.0 6 votes vote down vote up
@Override
protected void run(@NotNull Result<PsiFile> result) throws Throwable {
    final PsiPackage packageElement = directoryService.getPackage(directory);
    if (packageElement == null) {
        throw new InvalidDirectoryException("Target directory does not provide a package");
    }

    final String fileName = Extensions.append(name, StdFileTypes.JAVA);
    final PsiFile found = directory.findFile(fileName);
    if (found != null) {
        throw new ClassAlreadyExistsException("Class '" + name + "'already exists in " + packageElement.getName());
    }

    final String packageName = packageElement.getQualifiedName();
    final String className = Extensions.remove(this.name, StdFileTypes.JAVA);
    try {
        final String java = converter.convert(packageName, className, json);
        final PsiFile classFile = fileFactory.createFileFromText(fileName, JavaFileType.INSTANCE, java);
        CodeStyleManager.getInstance(classFile.getProject()).reformat(classFile);
        JavaCodeStyleManager.getInstance(classFile.getProject()).optimizeImports(classFile);
        final PsiFile created = (PsiFile) directory.add(classFile);
        result.setResult(created);
    } catch (IOException e) {
        throw new ClassCreationException("Failed to create new class from JSON", e);
    }
}
 
Example #13
Source File: NewBundleControllerAction.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
protected void write(@NotNull final Project project, @NotNull final PhpClass phpClass, @NotNull String className) {

    if(!className.endsWith("Controller")) {
        className += "Controller";
    }

    final String finalClassName = className;
    new WriteCommandAction(project) {
        @Override
        protected void run(@NotNull Result result) throws Throwable {

            PsiElement bundleFile = null;
            try {
                bundleFile = PhpBundleFileFactory.createBundleFile(phpClass, "controller", "Controller\\" + finalClassName, new HashMap<>());
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error:" + e.getMessage());
                return;
            }

            if(bundleFile != null) {
                new OpenFileDescriptor(getProject(), bundleFile.getContainingFile().getVirtualFile(), 0).navigate(true);
            }
        }

        @Override
        public String getGroupID() {
            return "Create Controller";
        }
    }.execute();

}
 
Example #14
Source File: AbstractConvertLineSeparatorsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void changeLineSeparators(@Nonnull final Project project,
                                        @Nonnull final VirtualFile virtualFile,
                                        @Nonnull final String newSeparator) {
  FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
  Document document = fileDocumentManager.getCachedDocument(virtualFile);
  if (document != null) {
    fileDocumentManager.saveDocument(document);
  }

  String currentSeparator = LoadTextUtil.detectLineSeparator(virtualFile, false);
  final String commandText;
  if (StringUtil.isEmpty(currentSeparator)) {
    commandText = "Changed line separators to " + LineSeparator.fromString(newSeparator);
  }
  else {
    commandText = String.format("Changed line separators from %s to %s", LineSeparator.fromString(currentSeparator),
                                LineSeparator.fromString(newSeparator));
  }

  new WriteCommandAction(project, commandText) {
    @Override
    protected void run(@Nonnull Result result) throws Throwable {
      try {
        LoadTextUtil.changeLineSeparators(project, virtualFile, newSeparator, this);
      }
      catch (IOException e) {
        LOG.info(e);
      }
    }
  }.execute();
}
 
Example #15
Source File: VcsTestUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static VirtualFile createFile(@Nonnull Project project, @Nonnull final VirtualFile parent, @Nonnull final String name,
                                     @javax.annotation.Nullable final String content) {
  return new WriteCommandAction<VirtualFile>(project) {
    @Override
    protected void run(@Nonnull Result<VirtualFile> result) throws Throwable {
      VirtualFile file = parent.createChildData(this, name);
      if (content != null) {
        file.setBinaryContent(CharsetToolkit.getUtf8Bytes(content));
      }
      result.setResult(file);
    }
  }.execute().throwException().getResultObject();
}
 
Example #16
Source File: PsiTestUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void addLibrary(final Module module, final String libName, final String libPath, final String... jarArr) {
  new WriteCommandAction(module.getProject()) {
    @Override
    protected void run(Result result) throws Throwable {
      final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
      addLibrary(module, model, libName, libPath, jarArr);
      model.commit();
    }
  }.execute().throwException();
}
 
Example #17
Source File: CodeInsightTestFixtureImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private SelectionAndCaretMarkupLoader(Project project, String fileText, String filePath) {
  this.filePath = filePath;
  final Document document = EditorFactory.getInstance().createDocument(fileText);

  int caretIndex = fileText.indexOf(CARET_MARKER);
  int selStartIndex = fileText.indexOf(SELECTION_START_MARKER);
  int selEndIndex = fileText.indexOf(SELECTION_END_MARKER);
  int blockStartIndex = fileText.indexOf(BLOCK_START_MARKER);
  int blockEndIndex = fileText.indexOf(BLOCK_END_MARKER);

  caretMarker = caretIndex >= 0 ? document.createRangeMarker(caretIndex, caretIndex + CARET_MARKER.length()) : null;
  if (selStartIndex >= 0 || selEndIndex >= 0) {
    blockSelection = false;
    selStartMarker = selStartIndex >= 0 ? document.createRangeMarker(selStartIndex, selStartIndex + SELECTION_START_MARKER.length()) : null;
    selEndMarker = selEndIndex >= 0 ? document.createRangeMarker(selEndIndex, selEndIndex + SELECTION_END_MARKER.length()) : null;
  }
  else {
    selStartMarker = blockStartIndex >= 0 ? document.createRangeMarker(blockStartIndex, blockStartIndex + BLOCK_START_MARKER.length()) : null;
    selEndMarker = blockEndIndex >= 0 ? document.createRangeMarker(blockEndIndex, blockEndIndex + BLOCK_END_MARKER.length()) : null;
    blockSelection = selStartMarker != null || selEndMarker != null;
  }

  new WriteCommandAction(project) {
    @Override
    protected void run(Result result) throws Exception {
      if (caretMarker != null) {
        document.deleteString(caretMarker.getStartOffset(), caretMarker.getEndOffset());
      }
      if (selStartMarker != null) {
        document.deleteString(selStartMarker.getStartOffset(), selStartMarker.getEndOffset());
      }
      if (selEndMarker != null) {
        document.deleteString(selEndMarker.getStartOffset(), selEndMarker.getEndOffset());
      }
    }
  }.execute();

  newFileText = document.getText();
}
 
Example #18
Source File: TemplateExpressionLookupElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
void handleTemplateInsert(List<? extends LookupElement> elements, final char completionChar) {
  final InsertionContext context = createInsertionContext(this, myState.getPsiFile(), elements, myState.getEditor(), completionChar);
  new WriteCommandAction(context.getProject()) {
    @Override
    protected void run(@Nonnull Result result) throws Throwable {
      doHandleInsert(context);
    }
  }.execute();
  Disposer.dispose(context.getOffsetMap());

  if (handleCompletionChar(context) && !myState.isFinished()) {
    myState.calcResults(true);
    myState.considerNextTabOnLookupItemSelected(getDelegate());
  }
}
 
Example #19
Source File: MyPsiUtils.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void replacePsiFileFromText(final Project project, final PsiFile psiFile, String text) {
	final PsiFile newPsiFile = createFile(project, text);
	WriteCommandAction setTextAction = new WriteCommandAction(project) {
		@Override
		protected void run(final Result result) throws Throwable {
			psiFile.deleteChildRange(psiFile.getFirstChild(), psiFile.getLastChild());
			psiFile.addRange(newPsiFile.getFirstChild(), newPsiFile.getLastChild());
		}
	};
	setTextAction.execute();
}
 
Example #20
Source File: UniquifyRuleRefs.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
	PsiElement el = MyActionUtils.getSelectedPsiElement(e);
	if ( el==null ) return;

	final String ruleName = el.getText();

	final PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
	if ( psiFile==null ) return;

	final Project project = e.getProject();

	Editor editor = e.getData(PlatformDataKeys.EDITOR);
	if ( editor==null ) return;
	final Document doc = editor.getDocument();

	String grammarText = psiFile.getText();
	ParsingResult results = ParsingUtils.parseANTLRGrammar(grammarText);
	Parser parser = results.parser;
	ParseTree tree = results.tree;

	// find all parser and lexer rule refs
	final List<TerminalNode> rrefNodes = RefactorUtils.getAllRuleRefNodes(parser, tree, ruleName);
	if ( rrefNodes==null ) return;

	// find rule def
	final TerminalNode ruleDefNameNode = RefactorUtils.getRuleDefNameNode(parser, tree, ruleName);
	if ( ruleDefNameNode==null ) return;

	// alter rule refs and dup rules
	WriteCommandAction setTextAction = new WriteCommandAction(project) {
		@Override
		protected void run(final Result result) throws Throwable {
			// do in a single action so undo works in one go
			dupRuleAndMakeRefsUnique(doc, ruleName, rrefNodes);
		}
	};
	setTextAction.execute();
}
 
Example #21
Source File: AbstractInplaceIntroducer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean performRefactoring() {
  final String newName = getInputName();
  if (getLocalVariable() == null && myExpr == null ||
      newName == null ||
      getLocalVariable() != null && !getLocalVariable().isValid() ||
      myExpr != null && !myExpr.isValid()) {
    super.moveOffsetAfter(false);
    return false;
  }
  if (getLocalVariable() != null) {
    new WriteCommandAction(myProject, getCommandName(), getCommandName()) {
      @Override
      protected void run(Result result) throws Throwable {
        getLocalVariable().setName(myLocalName);
      }
    }.execute();
  }

  if (!isIdentifier(newName, myExpr != null ? myExpr.getLanguage() : getLocalVariable().getLanguage())) return false;
  CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
    @Override
    public void run() {
      performIntroduce();
    }
  }, getCommandName(), getCommandName());

  V variable = getVariable();
  if (variable != null) {
    saveSettings(variable);
  }
  return false;
}
 
Example #22
Source File: NewBundleCompilerPass.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent event) {

    Project project = getEventProject(event);
    if(project == null) {
        this.setStatus(event, false);
        return;
    }

    PsiDirectory bundleDirContext = BundleClassGeneratorUtil.getBundleDirContext(event);
    if(bundleDirContext == null) {
        return;
    }

    final PhpClass phpClass = BundleClassGeneratorUtil.getBundleClassInDirectory(bundleDirContext);
    if(phpClass == null) {
        return;
    }

    new WriteCommandAction(project) {
        @Override
        protected void run(@NotNull Result result) throws Throwable {
            PsiElement psiFile = PhpBundleFileFactory.invokeCreateCompilerPass(phpClass, null);
            if(psiFile != null) {
                new OpenFileDescriptor(getProject(), psiFile.getContainingFile().getVirtualFile(), 0).navigate(true);
            }
        }

        @Override
        public String getGroupID() {
            return "Create CompilerClass";
        }
    }.execute();

}
 
Example #23
Source File: NewBundleFormAction.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
protected void write(@NotNull final Project project, @NotNull final PhpClass phpClass, @NotNull final String className) {
    new WriteCommandAction(project) {
        @Override
        protected void run(@NotNull Result result) throws Throwable {


            String fileTemplate = "form_type_defaults";
            if(PhpElementsUtil.getClassMethod(project, "\\Symfony\\Component\\Form\\AbstractType", "configureOptions") != null) {
                fileTemplate = "form_type_configure";
            }

            PsiElement bundleFile = null;
            try {

                bundleFile = PhpBundleFileFactory.createBundleFile(phpClass, fileTemplate, "Form\\" + className, new HashMap<String, String>() {{
                    put("name", fr.adrienbrault.idea.symfony2plugin.util.StringUtils.underscore(phpClass.getName() + className));
                }});

            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error:" + e.getMessage());
                return;
            }

            if(bundleFile != null) {
                new OpenFileDescriptor(getProject(), bundleFile.getContainingFile().getVirtualFile(), 0).navigate(true);
            }
        }

        @Override
        public String getGroupID() {
            return "Create FormType";
        }
    }.execute();

}
 
Example #24
Source File: SurroundWithHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  new WriteCommandAction(myProject) {
    @Override
    protected void run(@Nonnull Result result) throws Exception {
      doSurround(myProject, myEditor, mySurrounder, myElements);
    }
  }.execute();
}
 
Example #25
Source File: HaxeClassNameCompletionContributor.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private static void addImportForLookupElement(final InsertionContext context, final LookupElement item, final int tailOffset) {
  final PsiReference ref = context.getFile().findReferenceAt(tailOffset);
  if (ref == null || ref.resolve() != null) {
    // no import statement needed
    return;
  }
  new WriteCommandAction(context.getProject(), context.getFile()) {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      final String importPath = (String)item.getObject();
      HaxeAddImportHelper.addImport(importPath, context.getFile());
    }
  }.execute();
}
 
Example #26
Source File: NewBundleCommandAction.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
protected void write(@NotNull final Project project, @NotNull final PhpClass phpClass, @NotNull String className) {

        if(!className.endsWith("Command")) {
            className += "Command";
        }

        final String finalClassName = className;
        new WriteCommandAction(project) {
            @Override
            protected void run(@NotNull Result result) throws Throwable {

                PsiElement bundleFile = null;
                try {

                    bundleFile = PhpBundleFileFactory.createBundleFile(phpClass, "command", "Command\\" + finalClassName, new HashMap<String, String>() {{
                        String name = phpClass.getName();
                        if(name.endsWith("Bundle")) {
                            name = name.substring(0, name.length() - "Bundle".length());
                        }
                        put("name", StringUtils.underscore(name) + ":" + StringUtils.underscore(finalClassName));
                    }});

                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "Error:" + e.getMessage());
                    return;
                }

                new OpenFileDescriptor(getProject(), bundleFile.getContainingFile().getVirtualFile(), 0).navigate(true);
            }

            @Override
            public String getGroupID() {
                return "Create Command";
            }
        }.execute();
    }
 
Example #27
Source File: StringComboboxEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void setItem(Object anObject) {
  if (anObject == null) anObject = "";
  if (anObject.equals(getItem())) return;
  final String s = (String)anObject;
  new WriteCommandAction(myProject) {
    @Override
    protected void run(Result result) throws Throwable {
      getDocument().setText(s);
    }
  }.execute();

  final Editor editor = getEditor();
  if (editor != null) editor.getCaretModel().moveToOffset(s.length());
}
 
Example #28
Source File: HaxeSmartEnterTest.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public void doTest() {
  myFixture.configureByFile(getTestName(false) + ".hx");
  final List<SmartEnterProcessor> processors = SmartEnterProcessors.INSTANCE.forKey(HaxeLanguage.INSTANCE);
  new WriteCommandAction(myFixture.getProject()) {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      final Editor editor = myFixture.getEditor();
      for (SmartEnterProcessor processor : processors) {
        processor.process(myFixture.getProject(), editor, myFixture.getFile());
      }
    }
  }.execute();
  myFixture.checkResultByFile(getTestName(false) + "_after.hx", true);
}
 
Example #29
Source File: HaxeTypeAddImportIntentionAction.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private void doImport(final Editor editor, final PsiElement component) {
  new WriteCommandAction(myType.getProject(), myType.getContainingFile()) {
    @Override
    protected void run(Result result) throws Throwable {
      HaxeAddImportHelper.addImport(((HaxeClass)component).getQualifiedName(), myType.getContainingFile());
    }
  }.execute();
}
 
Example #30
Source File: RenameFileFix.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void applyFix(@Nonnull final Project project, @Nonnull ProblemDescriptor descriptor) {
  final PsiFile file = descriptor.getPsiElement().getContainingFile();
  if (isAvailable(project, null, file)) {
    new WriteCommandAction(project) {
      @Override
      protected void run(Result result) throws Throwable {
        invoke(project, FileEditorManager.getInstance(project).getSelectedTextEditor(), file);
      }
    }.execute();
  }
}