Package com.intellij.psi

Examples of com.intellij.psi.PsiImportList


                ImportSorter importSorter = null;
                try {
                    importSorter = new ImportSorter(settings.getImportOrderAsList());
                    importSorter.sortImports(document);
                } catch (Exception e) {
                    final PsiImportList oldImportList = ((PsiJavaFile) psiFile).getImportList();
                    StringBuilder stringBuilder = new StringBuilder();
                    if (oldImportList != null) {
                        PsiImportStatementBase[] allImportStatements = oldImportList.getAllImportStatements();
                        for (PsiImportStatementBase allImportStatement : allImportStatements) {
                            String text = allImportStatement.getText();
                            stringBuilder.append(text);
                        }
                    }
View Full Code Here


    if (FileUtils.isJava(psiFile) && settings.isOptimizeImports() && range.isWholeFile()) {
      FileUtils.optimizeImportsByIntellij(psiFile);
      try {
        getImportSorter().sortImports(document);
      } catch (Exception e) {
        final PsiImportList oldImportList = ((PsiJavaFile) psiFile).getImportList();
        StringBuilder stringBuilder = new StringBuilder();
        if (oldImportList != null) {
          PsiImportStatementBase[] allImportStatements = oldImportList.getAllImportStatements();
          for (PsiImportStatementBase allImportStatement : allImportStatements) {
            String text = allImportStatement.getText();
            stringBuilder.append(text);
          }
        }
View Full Code Here

  }

  public static void optimizeImportsByIntellij(PsiFile psiFile) {

    Project project = psiFile.getProject();
    final PsiImportList newImportList = JavaCodeStyleManager.getInstance(project).prepareOptimizeImportsResult(
        (PsiJavaFile) psiFile);

    try {
      final PsiDocumentManager manager = PsiDocumentManager.getInstance(project);
      final Document document = manager.getDocument(psiFile);
      if (document != null) {
        manager.commitDocument(document);
      }
      final PsiImportList oldImportList = ((PsiJavaFile) psiFile).getImportList();
      assert oldImportList != null;
      if (newImportList != null) {
        oldImportList.replace(newImportList);
      }
      manager.doPostponedOperationsAndUnblockDocument(document);
    } catch (IncorrectOperationException e) {
      LOG.error(e);
    }
View Full Code Here

        if (!settings.isOptimizeImports()) {
            return;
        }

        Project project = psiFile.getProject();
        final PsiImportList newImportList = JavaCodeStyleManager.getInstance(project).prepareOptimizeImportsResult(
                (PsiJavaFile) psiFile);

        try {
            final PsiDocumentManager manager = PsiDocumentManager.getInstance(project);
            final Document document = manager.getDocument(psiFile);
            if (document != null) {
                manager.commitDocument(document);
            }
            final PsiImportList oldImportList = ((PsiJavaFile) psiFile).getImportList();
            assert oldImportList != null;
            if (newImportList != null) {
                oldImportList.replace(newImportList);
            }
            manager.doPostponedOperationsAndUnblockDocument(document);
        } catch (IncorrectOperationException e) {
            LOG.error(e);
        }
View Full Code Here

    if (usage instanceof PsiElementUsage) {
      final PsiElement psiElement = ((PsiElementUsage)usage).getElement();
      final PsiFile containingFile = psiElement.getContainingFile();
      if (containingFile instanceof PsiJavaFile) {
        // check whether the element is in the import list
        final PsiImportList importList = PsiTreeUtil.getParentOfType(psiElement, PsiImportList.class, true);
        return importList == null;
      }
    }
    return true;
  }
View Full Code Here

TOP

Related Classes of com.intellij.psi.PsiImportList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.