Search in sources :

Example 1 with CodeSmellInfo

use of com.intellij.codeInsight.CodeSmellInfo in project intellij-community by JetBrains.

the class CodeSmellDetectorImpl method findCodeSmells.

@NotNull
private List<CodeSmellInfo> findCodeSmells(@NotNull final VirtualFile file, @NotNull final ProgressIndicator progress) {
    final List<CodeSmellInfo> result = Collections.synchronizedList(new ArrayList<CodeSmellInfo>());
    final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(myProject);
    final ProgressIndicator daemonIndicator = new DaemonProgressIndicator();
    ((ProgressIndicatorEx) progress).addStateDelegate(new AbstractProgressIndicatorExBase() {

        @Override
        public void cancel() {
            super.cancel();
            daemonIndicator.cancel();
        }
    });
    ProgressManager.getInstance().runProcess(new Runnable() {

        @Override
        public void run() {
            DumbService.getInstance(myProject).runReadActionInSmartMode(new Runnable() {

                @Override
                public void run() {
                    final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
                    final Document document = FileDocumentManager.getInstance().getDocument(file);
                    if (psiFile == null || document == null) {
                        return;
                    }
                    List<HighlightInfo> infos = codeAnalyzer.runMainPasses(psiFile, document, daemonIndicator);
                    convertErrorsAndWarnings(infos, result, document);
                }
            });
        }
    }, daemonIndicator);
    return result;
}
Also used : CodeSmellInfo(com.intellij.codeInsight.CodeSmellInfo) Document(com.intellij.openapi.editor.Document) AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProgressIndicatorEx(com.intellij.openapi.wm.ex.ProgressIndicatorEx) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CodeSmellInfo

use of com.intellij.codeInsight.CodeSmellInfo in project intellij-community by JetBrains.

the class CodeSmellDetectorImpl method showCodeSmellErrors.

@Override
public void showCodeSmellErrors(@NotNull final List<CodeSmellInfo> smellList) {
    Collections.sort(smellList, new Comparator<CodeSmellInfo>() {

        @Override
        public int compare(final CodeSmellInfo o1, final CodeSmellInfo o2) {
            return o1.getTextRange().getStartOffset() - o2.getTextRange().getStartOffset();
        }
    });
    ApplicationManager.getApplication().invokeLater(new Runnable() {

        @Override
        public void run() {
            if (myProject.isDisposed())
                return;
            if (smellList.isEmpty()) {
                return;
            }
            final VcsErrorViewPanel errorTreeView = new VcsErrorViewPanel(myProject);
            AbstractVcsHelperImpl helper = (AbstractVcsHelperImpl) AbstractVcsHelper.getInstance(myProject);
            helper.openMessagesView(errorTreeView, VcsBundle.message("code.smells.error.messages.tab.name"));
            FileDocumentManager fileManager = FileDocumentManager.getInstance();
            for (CodeSmellInfo smellInfo : smellList) {
                final VirtualFile file = fileManager.getFile(smellInfo.getDocument());
                final OpenFileDescriptor navigatable = new OpenFileDescriptor(myProject, file, smellInfo.getStartLine(), smellInfo.getStartColumn());
                final String exportPrefix = NewErrorTreeViewPanel.createExportPrefix(smellInfo.getStartLine() + 1);
                final String rendererPrefix = NewErrorTreeViewPanel.createRendererPrefix(smellInfo.getStartLine() + 1, smellInfo.getStartColumn() + 1);
                if (smellInfo.getSeverity() == HighlightSeverity.ERROR) {
                    errorTreeView.addMessage(MessageCategory.ERROR, new String[] { smellInfo.getDescription() }, file.getPresentableUrl(), navigatable, exportPrefix, rendererPrefix, null);
                } else {
                    //if (smellInfo.getSeverity() == HighlightSeverity.WARNING) {
                    errorTreeView.addMessage(MessageCategory.WARNING, new String[] { smellInfo.getDescription() }, file.getPresentableUrl(), navigatable, exportPrefix, rendererPrefix, null);
                }
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CodeSmellInfo(com.intellij.codeInsight.CodeSmellInfo) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Aggregations

CodeSmellInfo (com.intellij.codeInsight.CodeSmellInfo)2 Document (com.intellij.openapi.editor.Document)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 AbstractProgressIndicatorExBase (com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ProgressIndicatorEx (com.intellij.openapi.wm.ex.ProgressIndicatorEx)1 PsiFile (com.intellij.psi.PsiFile)1 NotNull (org.jetbrains.annotations.NotNull)1