file path completion on class name (ctrl+alt+space)
[fedora-idea.git] / java / java-impl / src / com / intellij / analysis / BaseClassesAnalysisAction.java
blobcaae231245ff3991dd4702d57823e30e9208f0ce
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.analysis;
18 import com.intellij.openapi.application.ApplicationManager;
19 import com.intellij.openapi.compiler.CompileContext;
20 import com.intellij.openapi.compiler.CompileStatusNotification;
21 import com.intellij.openapi.compiler.CompilerManager;
22 import com.intellij.openapi.fileEditor.FileDocumentManager;
23 import com.intellij.openapi.progress.ProgressIndicator;
24 import com.intellij.openapi.progress.ProgressManager;
25 import com.intellij.openapi.progress.Task;
26 import com.intellij.openapi.project.Project;
27 import com.intellij.openapi.ui.Messages;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
31 /**
32 * @author mike
34 public abstract class BaseClassesAnalysisAction extends BaseAnalysisAction {
35 protected BaseClassesAnalysisAction(String title, String analysisNoon) {
36 super(title, analysisNoon);
39 protected abstract void analyzeClasses(final Project project, final AnalysisScope scope, ProgressIndicator indicator);
41 protected void analyze(@NotNull final Project project, final AnalysisScope scope) {
42 FileDocumentManager.getInstance().saveAllDocuments();
44 ProgressManager.getInstance().run(new Task.Backgroundable(project, AnalysisScopeBundle.message("analyzing.project"), true) {
45 public void run(@NotNull final ProgressIndicator indicator) {
46 indicator.setIndeterminate(true);
47 indicator.setText(AnalysisScopeBundle.message("checking.class.files"));
49 final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
50 final boolean upToDate = compilerManager.isUpToDate(compilerManager.createProjectCompileScope(myProject));
52 ApplicationManager.getApplication().invokeLater(new Runnable() {
53 public void run() {
54 if (!upToDate) {
55 final int i = Messages.showYesNoCancelDialog(getProject(), AnalysisScopeBundle.message("recompile.confirmation.message"),
56 AnalysisScopeBundle.message("project.is.out.of.date"), Messages.getWarningIcon());
58 if (i == 2) return;
60 if (i == 0) {
61 compileAndAnalyze(project, scope);
63 else {
64 doAnalyze(project, scope);
67 else {
68 doAnalyze(project, scope);
71 });
73 });
76 private void doAnalyze(final Project project, final AnalysisScope scope) {
77 ProgressManager.getInstance().run(new Task.Backgroundable(project, AnalysisScopeBundle.message("analyzing.project"), true) {
78 @Nullable
79 public NotificationInfo getNotificationInfo() {
80 return new NotificationInfo("Analysis", "\"" + getTitle() + "\" Analysis Finished", "");
83 public void run(@NotNull final ProgressIndicator indicator) {
84 analyzeClasses(project, scope, indicator);
86 });
89 private void compileAndAnalyze(final Project project, final AnalysisScope scope) {
90 final CompilerManager compilerManager = CompilerManager.getInstance(project);
91 compilerManager.make(compilerManager.createProjectCompileScope(project), new CompileStatusNotification() {
92 public void finished(final boolean aborted, final int errors, final int warnings, final CompileContext compileContext) {
93 if (aborted || errors != 0) return;
94 ApplicationManager.getApplication().invokeLater(new Runnable() {
95 public void run() {
96 doAnalyze(project, scope);
98 });
99 }});