mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'master' of git.labs.intellij.net:idea/community
This commit is contained in:
@@ -186,6 +186,9 @@ public class CompileDriver {
|
||||
if (validateCompilerConfiguration(scope, false)) {
|
||||
startup(scope, false, false, callback, null, true, false);
|
||||
}
|
||||
else {
|
||||
callback.finished(true, 0, 0, DummyCompileContext.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUpToDate(CompileScope scope) {
|
||||
@@ -247,6 +250,9 @@ public class CompileDriver {
|
||||
if (validateCompilerConfiguration(scope, false)) {
|
||||
startup(scope, false, true, callback, null, true, trackDependencies);
|
||||
}
|
||||
else {
|
||||
callback.finished(true, 0, 0, DummyCompileContext.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
private static class CompileStatus {
|
||||
@@ -327,6 +333,9 @@ public class CompileDriver {
|
||||
if (validateCompilerConfiguration(compileScope, true)) {
|
||||
startup(compileScope, true, false, callback, message, checkCachesVersion, false);
|
||||
}
|
||||
else {
|
||||
callback.finished(true, 0, 0, DummyCompileContext.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
private CompileScope addAdditionalRoots(CompileScope originalScope, final CompilerFilter filter) {
|
||||
|
||||
+34
-33
@@ -520,29 +520,25 @@ public class BackendCompilerWrapper {
|
||||
final List<File> toRefresh = new ArrayList<File>();
|
||||
final Map<String, Collection<TranslatingCompiler.OutputItem>> results = new HashMap<String, Collection<TranslatingCompiler.OutputItem>>();
|
||||
try {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
final FileTypeManager typeManager = FileTypeManager.getInstance();
|
||||
final String outputDirPath = outputDir.replace(File.separatorChar, '/');
|
||||
try {
|
||||
for (final Module module : chunk.getModules()) {
|
||||
for (final VirtualFile root : chunk.getSourceRoots(module)) {
|
||||
final String packagePrefix = myProjectFileIndex.getPackageNameByDirectory(root);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Building output items for " + root.getPresentableUrl() + "; output dir = " + outputDirPath + "; packagePrefix = \"" + packagePrefix + "\"");
|
||||
}
|
||||
buildOutputItemsList(outputDirPath, module, root, typeManager, root, packagePrefix, toRefresh, results);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (CacheCorruptedException e) {
|
||||
myCompileContext.requestRebuildNextTime(CompilerBundle.message("error.compiler.caches.corrupted"));
|
||||
final FileTypeManager typeManager = FileTypeManager.getInstance();
|
||||
final String outputDirPath = outputDir.replace(File.separatorChar, '/');
|
||||
try {
|
||||
for (final Module module : chunk.getModules()) {
|
||||
for (final VirtualFile root : chunk.getSourceRoots(module)) {
|
||||
final String packagePrefix = myProjectFileIndex.getPackageNameByDirectory(root);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(e);
|
||||
LOG.debug("Building output items for " + root.getPresentableUrl() + "; output dir = " + outputDirPath + "; packagePrefix = \"" + packagePrefix + "\"");
|
||||
}
|
||||
buildOutputItemsList(outputDirPath, module, root, typeManager, root, packagePrefix, toRefresh, results);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (CacheCorruptedException e) {
|
||||
myCompileContext.requestRebuildNextTime(CompilerBundle.message("error.compiler.caches.corrupted"));
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
CompilerUtil.refreshIOFiles(toRefresh);
|
||||
@@ -617,11 +613,11 @@ public class BackendCompilerWrapper {
|
||||
paths.add(new CompiledClass(classQName, relativePathToSource, pathToClass));
|
||||
}
|
||||
|
||||
private void updateOutputItemsList(final String outputDir, VirtualFile srcFile,
|
||||
private void updateOutputItemsList(final String outputDir, final VirtualFile srcFile,
|
||||
VirtualFile sourceRoot,
|
||||
final String packagePrefix, final List<File> filesToRefresh,
|
||||
Map<String, Collection<TranslatingCompiler.OutputItem>> results,
|
||||
GlobalSearchScope srcRootScope) throws CacheCorruptedException {
|
||||
final GlobalSearchScope srcRootScope) throws CacheCorruptedException {
|
||||
final Cache newCache = myCompileContext.getDependencyCache().getNewClassesCache();
|
||||
final Set<CompiledClass> paths = myFileNameToSourceMap.get(srcFile.getName());
|
||||
if (paths == null || paths.isEmpty()) {
|
||||
@@ -638,19 +634,24 @@ public class BackendCompilerWrapper {
|
||||
if (!pathsEquals) {
|
||||
final String qName = myCompileContext.getDependencyCache().resolve(cc.qName);
|
||||
if (qName != null) {
|
||||
final JavaPsiFacade facade = JavaPsiFacade.getInstance(myProject);
|
||||
PsiClass psiClass = facade.findClass(qName, srcRootScope);
|
||||
if (psiClass == null) {
|
||||
final int dollarIndex = qName.indexOf("$");
|
||||
if (dollarIndex >= 0) {
|
||||
final String topLevelClassName = qName.substring(0, dollarIndex);
|
||||
psiClass = facade.findClass(topLevelClassName, srcRootScope);
|
||||
pathsEquals = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
|
||||
public Boolean compute() {
|
||||
final JavaPsiFacade facade = JavaPsiFacade.getInstance(myProject);
|
||||
PsiClass psiClass = facade.findClass(qName, srcRootScope);
|
||||
if (psiClass == null) {
|
||||
final int dollarIndex = qName.indexOf("$");
|
||||
if (dollarIndex >= 0) {
|
||||
final String topLevelClassName = qName.substring(0, dollarIndex);
|
||||
psiClass = facade.findClass(topLevelClassName, srcRootScope);
|
||||
}
|
||||
}
|
||||
if (psiClass != null) {
|
||||
final VirtualFile vFile = psiClass.getContainingFile().getVirtualFile();
|
||||
return vFile != null && vFile.equals(srcFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (psiClass != null) {
|
||||
final VirtualFile vFile = psiClass.getContainingFile().getVirtualFile();
|
||||
pathsEquals = vFile != null && vFile.equals(srcFile);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -589,7 +589,7 @@ public class BreakpointManager implements JDOMExternalizable {
|
||||
|
||||
}
|
||||
}
|
||||
catch (InvalidDataException e) {
|
||||
catch (InvalidDataException ignored) {
|
||||
}
|
||||
|
||||
final Element rulesGroup = parentNode.getChild(RULES_GROUP_NAME);
|
||||
@@ -827,7 +827,7 @@ public class BreakpointManager implements JDOMExternalizable {
|
||||
//interaction with RequestManagerImpl
|
||||
public void disableBreakpoints(final DebugProcessImpl debugProcess) {
|
||||
final List<Breakpoint> breakpoints = getBreakpoints();
|
||||
if (breakpoints.size() > 0) {
|
||||
if (!breakpoints.isEmpty()) {
|
||||
final RequestManagerImpl requestManager = debugProcess.getRequestsManager();
|
||||
for (Breakpoint breakpoint : breakpoints) {
|
||||
breakpoint.markVerified(requestManager.isVerified(breakpoint));
|
||||
@@ -843,7 +843,7 @@ public class BreakpointManager implements JDOMExternalizable {
|
||||
|
||||
public void enableBreakpoints(final DebugProcessImpl debugProcess) {
|
||||
final List<Breakpoint> breakpoints = getBreakpoints();
|
||||
if (breakpoints.size() > 0) {
|
||||
if (!breakpoints.isEmpty()) {
|
||||
for (Breakpoint breakpoint : breakpoints) {
|
||||
breakpoint.markVerified(false); // clean cached state
|
||||
breakpoint.createRequest(debugProcess);
|
||||
|
||||
@@ -615,7 +615,7 @@ public class BreakpointTree extends CheckboxTree {
|
||||
// Fix GTK backround
|
||||
if (UIUtil.isUnderGTKLookAndFeel()){
|
||||
final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
|
||||
setBackground(background);
|
||||
UIUtil.changeBackGround(this, background);
|
||||
}
|
||||
if (value instanceof CheckedTreeNode) {
|
||||
final CheckedTreeNode node = (CheckedTreeNode)value;
|
||||
|
||||
+12
-3
@@ -415,7 +415,8 @@ public abstract class BreakpointWithHighlighter extends Breakpoint {
|
||||
}
|
||||
|
||||
private void setupGutterRenderer() {
|
||||
getHighlighter().setGutterIconRenderer(new MyGutterIconRenderer());
|
||||
MyGutterIconRenderer renderer = new MyGutterIconRenderer(getIcon(), getDescription());
|
||||
getHighlighter().setGutterIconRenderer(renderer);
|
||||
}
|
||||
|
||||
public abstract Key<? extends BreakpointWithHighlighter> getCategory();
|
||||
@@ -623,13 +624,21 @@ public abstract class BreakpointWithHighlighter extends Breakpoint {
|
||||
}
|
||||
|
||||
private class MyGutterIconRenderer extends GutterIconRenderer {
|
||||
private final Icon myIcon;
|
||||
private final String myDescription;
|
||||
|
||||
public MyGutterIconRenderer(Icon icon, String description) {
|
||||
myIcon = icon;
|
||||
myDescription = description;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Icon getIcon() {
|
||||
return BreakpointWithHighlighter.this.getIcon();
|
||||
return myIcon;
|
||||
}
|
||||
|
||||
public String getTooltipText() {
|
||||
return getDescription();
|
||||
return myDescription;
|
||||
}
|
||||
|
||||
public AnAction getClickAction() {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryDownloadDescription;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.ui.CheckBoxList;
|
||||
import com.intellij.ui.CollectionListModel;
|
||||
import com.intellij.util.Function;
|
||||
@@ -68,7 +69,7 @@ public class DownloadingOptionsDialog extends DialogWrapper {
|
||||
FileChooserDescriptorFactory.createSingleFolderDescriptor());
|
||||
|
||||
myCopyDownloadedFilesToLabel.setLabelFor(myDirectoryField);
|
||||
myDirectoryField.setText(settings.getDirectoryForDownloadedLibrariesPath());
|
||||
myDirectoryField.setText(FileUtil.toSystemDependentName(settings.getDirectoryForDownloadedLibrariesPath()));
|
||||
|
||||
myDownloadSourcesCheckBox.setSelected(settings.isDownloadSources());
|
||||
myDownloadJavadocsCheckBox.setSelected(settings.isDownloadJavadocs());
|
||||
@@ -92,7 +93,7 @@ public class DownloadingOptionsDialog extends DialogWrapper {
|
||||
protected void doOKAction() {
|
||||
mySettings.setLibraryName(myNameAndLevelPanel.getLibraryName());
|
||||
mySettings.setLibraryLevel(myNameAndLevelPanel.getLibraryLevel());
|
||||
mySettings.setDirectoryForDownloadedLibrariesPath(myDirectoryField.getText());
|
||||
mySettings.setDirectoryForDownloadedLibrariesPath(FileUtil.toSystemIndependentName(myDirectoryField.getText()));
|
||||
|
||||
List<LibraryDownloadInfo> selected = new ArrayList<LibraryDownloadInfo>();
|
||||
List<LibraryDownloadInfo> downloads = myDownloadDescription.getDownloads();
|
||||
|
||||
+1
-2
@@ -108,9 +108,8 @@ public class LibraryCompositionSettings implements Disposable {
|
||||
@Nullable
|
||||
private Library createLibrary(final ModifiableRootModel rootModel, @Nullable LibrariesContainer additionalContainer) {
|
||||
if (myNewLibraryEditor != null) {
|
||||
VirtualFile[] roots = myNewLibraryEditor.getFiles(OrderRootType.CLASSES);
|
||||
return LibrariesContainerFactory.createLibrary(additionalContainer, LibrariesContainerFactory.createContainer(rootModel),
|
||||
myNewLibraryEditor.getName(), getLibraryLevel(), roots, VirtualFile.EMPTY_ARRAY);
|
||||
myNewLibraryEditor, getLibraryLevel());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.openapi.roots.ui.configuration.libraries.LibraryDownloadDesc
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -31,7 +30,6 @@ import java.util.List;
|
||||
* @author nik
|
||||
*/
|
||||
public class LibraryDownloadSettings {
|
||||
@NonNls private static final String DEFAULT_LIB_FOLDER = "lib";
|
||||
private final LibraryDownloadDescription myDescription;
|
||||
private String myDirectoryForDownloadedLibrariesPath;
|
||||
private String myLibraryName;
|
||||
@@ -42,7 +40,7 @@ public class LibraryDownloadSettings {
|
||||
|
||||
public LibraryDownloadSettings(LibraryDownloadDescription description, String baseDirectoryForDownloadedFiles) {
|
||||
myDescription = description;
|
||||
myDirectoryForDownloadedLibrariesPath = baseDirectoryForDownloadedFiles + "/" + DEFAULT_LIB_FOLDER;
|
||||
myDirectoryForDownloadedLibrariesPath = baseDirectoryForDownloadedFiles + "/lib";
|
||||
myLibraryName = description.getDefaultLibraryName();
|
||||
mySelectedDownloads = description.getDownloads();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -260,7 +259,7 @@ public class LibraryOptionsPanel {
|
||||
final String basePath = mySettings.getBaseDirectoryPath();
|
||||
String path;
|
||||
if (!StringUtil.isEmpty(basePath) && FileUtil.startsWith(downloadPath, basePath)) {
|
||||
path = FileUtil.getRelativePath(basePath, downloadPath, File.separatorChar);
|
||||
path = FileUtil.getRelativePath(basePath, downloadPath, '/');
|
||||
}
|
||||
else {
|
||||
path = PathUtil.getFileName(downloadPath);
|
||||
|
||||
+3
-3
@@ -235,9 +235,9 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
|
||||
final JButton addButton = new JButton(ProjectBundle.message("button.add"));
|
||||
final JButton removeButton = new JButton(ProjectBundle.message("button.remove"));
|
||||
myEditButton = new JButton(ProjectBundle.message("button.edit"));
|
||||
final JButton upButton = new JButton(ProjectBundle.message("button.move.up"));
|
||||
final JButton downButton = new JButton(ProjectBundle.message("button.move.down"));
|
||||
myEditButton = new JButton(ProjectBundle.message("module.classpath.button.edit"));
|
||||
final JButton upButton = new JButton(ProjectBundle.message("module.classpath.button.move.up"));
|
||||
final JButton downButton = new JButton(ProjectBundle.message("module.classpath.button.move.down"));
|
||||
final JButton analyzeButton = isAnalyzeShown ? new JButton(ProjectBundle.message("classpath.panel.analyze")) : null;
|
||||
|
||||
final JPanel panel = new JPanel(new GridBagLayout());
|
||||
|
||||
+4
@@ -17,6 +17,7 @@ package com.intellij.openapi.roots.ui.configuration.libraries.impl;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
|
||||
import com.intellij.openapi.roots.libraries.*;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
|
||||
@@ -124,6 +125,9 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
|
||||
|
||||
@NotNull
|
||||
private static VirtualFile[] getLibraryFiles(@NotNull Library library, @Nullable StructureConfigurableContext context) {
|
||||
if (((LibraryEx)library).isDisposed()) {
|
||||
return VirtualFile.EMPTY_ARRAY;
|
||||
}
|
||||
return context != null ? context.getLibraryFiles(library, OrderRootType.CLASSES) : library.getFiles(OrderRootType.CLASSES);
|
||||
}
|
||||
|
||||
|
||||
+15
@@ -126,6 +126,10 @@ public class NewLibraryEditor implements LibraryEditor {
|
||||
|
||||
public void apply(@NotNull Library.ModifiableModel model) {
|
||||
model.setName(myLibraryName);
|
||||
applyRoots(model);
|
||||
}
|
||||
|
||||
public void applyRoots(Library.ModifiableModel model) {
|
||||
for (OrderRootType type : myRoots.keySet()) {
|
||||
for (LightFilePointer pointer : myRoots.get(type)) {
|
||||
model.addRoot(pointer.getUrl(), type);
|
||||
@@ -135,4 +139,15 @@ public class NewLibraryEditor implements LibraryEditor {
|
||||
model.addJarDirectory(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void copyRoots(ExistingLibraryEditor editor) {
|
||||
for (OrderRootType type : myRoots.keySet()) {
|
||||
for (LightFilePointer pointer : myRoots.get(type)) {
|
||||
editor.addRoot(pointer.getUrl(), type);
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, Boolean> entry : myJarDirectories.entrySet()) {
|
||||
editor.addJarDirectory(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -19,6 +19,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -54,6 +55,8 @@ public interface LibrariesContainer {
|
||||
Library createLibrary(@NotNull @NonNls String name, @NotNull LibraryLevel level,
|
||||
@NotNull VirtualFile[] classRoots, @NotNull VirtualFile[] sourceRoots);
|
||||
|
||||
Library createLibrary(@NotNull NewLibraryEditor libraryEditor, @NotNull LibraryLevel level);
|
||||
|
||||
@NotNull
|
||||
String suggestUniqueLibraryName(@NotNull String baseName);
|
||||
|
||||
|
||||
+34
-26
@@ -25,6 +25,7 @@ import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
@@ -72,27 +73,21 @@ public class LibrariesContainerFactory {
|
||||
}
|
||||
|
||||
public static Library createLibrary(@Nullable LibrariesContainer container1, @NotNull LibrariesContainer container2,
|
||||
@NotNull @NonNls final String name, @NotNull final LibrariesContainer.LibraryLevel level,
|
||||
@NotNull final VirtualFile[] classRoots, @NotNull final VirtualFile[] sourceRoots) {
|
||||
@NotNull @NonNls final NewLibraryEditor editor, @NotNull final LibrariesContainer.LibraryLevel level) {
|
||||
if (container1 != null && container1.canCreateLibrary(level)) {
|
||||
return container1.createLibrary(name, level, classRoots, sourceRoots);
|
||||
return container1.createLibrary(editor, level);
|
||||
}
|
||||
else {
|
||||
return container2.createLibrary(name, level, classRoots, sourceRoots);
|
||||
return container2.createLibrary(editor, level);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Library createLibraryInTable(final @NonNls String name, final VirtualFile[] roots, final VirtualFile[] sources, final LibraryTable table) {
|
||||
private static Library createLibraryInTable(final @NotNull NewLibraryEditor editor, final LibraryTable table) {
|
||||
LibraryTable.ModifiableModel modifiableModel = table.getModifiableModel();
|
||||
Library library = modifiableModel.createLibrary(getUniqueLibraryName(name, modifiableModel));
|
||||
Library library = modifiableModel.createLibrary(getUniqueLibraryName(editor.getName(), modifiableModel));
|
||||
final Library.ModifiableModel model = library.getModifiableModel();
|
||||
for (VirtualFile root : roots) {
|
||||
model.addRoot(root, OrderRootType.CLASSES);
|
||||
}
|
||||
for (VirtualFile root : sources) {
|
||||
model.addRoot(root, OrderRootType.SOURCES);
|
||||
}
|
||||
editor.applyRoots(model);
|
||||
model.commit();
|
||||
modifiableModel.commit();
|
||||
return library;
|
||||
@@ -111,6 +106,22 @@ public class LibrariesContainerFactory {
|
||||
private abstract static class LibrariesContainerBase implements LibrariesContainer {
|
||||
private UniqueNameGenerator myNameGenerator;
|
||||
|
||||
@Override
|
||||
public Library createLibrary(@NotNull @NonNls String name,
|
||||
@NotNull LibraryLevel level,
|
||||
@NotNull VirtualFile[] classRoots,
|
||||
@NotNull VirtualFile[] sourceRoots) {
|
||||
NewLibraryEditor editor = new NewLibraryEditor();
|
||||
editor.setName(name);
|
||||
for (VirtualFile classRoot : classRoots) {
|
||||
editor.addRoot(classRoot, OrderRootType.CLASSES);
|
||||
}
|
||||
for (VirtualFile sourceRoot : sourceRoots) {
|
||||
editor.addRoot(sourceRoot, OrderRootType.SOURCES);
|
||||
}
|
||||
return createLibrary(editor, level);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Library[] getAllLibraries() {
|
||||
Library[] libraries = getLibraries(LibraryLevel.GLOBAL);
|
||||
@@ -204,10 +215,11 @@ public class LibrariesContainerFactory {
|
||||
return level == LibraryLevel.GLOBAL || myProject != null;
|
||||
}
|
||||
|
||||
public Library createLibrary(@NotNull @NonNls final String name, @NotNull final LibraryLevel level,
|
||||
@NotNull final VirtualFile[] classRoots, @NotNull final VirtualFile[] sourceRoots) {
|
||||
@Override
|
||||
public Library createLibrary(@NotNull NewLibraryEditor libraryEditor,
|
||||
@NotNull LibraryLevel level) {
|
||||
if (level == LibraryLevel.MODULE && myRootModel != null) {
|
||||
return createLibraryInTable(name, classRoots, sourceRoots, myRootModel.getModuleLibraryTable());
|
||||
return createLibraryInTable(libraryEditor, myRootModel.getModuleLibraryTable());
|
||||
}
|
||||
|
||||
LibraryTablesRegistrar registrar = LibraryTablesRegistrar.getInstance();
|
||||
@@ -221,7 +233,7 @@ public class LibrariesContainerFactory {
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return createLibraryInTable(name, classRoots, sourceRoots, table);
|
||||
return createLibraryInTable(libraryEditor, table);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -239,22 +251,18 @@ public class LibrariesContainerFactory {
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
public Library createLibrary(@NotNull @NonNls final String name, @NotNull final LibraryLevel level,
|
||||
@NotNull final VirtualFile[] classRoots, @NotNull final VirtualFile[] sourceRoots) {
|
||||
@Override
|
||||
public Library createLibrary(@NotNull NewLibraryEditor libraryEditor,
|
||||
@NotNull LibraryLevel level) {
|
||||
LibraryTableModifiableModelProvider provider = getProvider(level);
|
||||
if (provider == null) {
|
||||
LOG.error("cannot create module library in this context");
|
||||
}
|
||||
|
||||
LibraryTable.ModifiableModel model = provider.getModifiableModel();
|
||||
Library library = model.createLibrary(getUniqueLibraryName(name, model));
|
||||
LibraryEditor libraryEditor = ((LibrariesModifiableModel)model).getLibraryEditor(library);
|
||||
for (VirtualFile root : classRoots) {
|
||||
libraryEditor.addRoot(root, OrderRootType.CLASSES);
|
||||
}
|
||||
for (VirtualFile source : sourceRoots) {
|
||||
libraryEditor.addRoot(source, OrderRootType.SOURCES);
|
||||
}
|
||||
Library library = model.createLibrary(getUniqueLibraryName(libraryEditor.getName(), model));
|
||||
ExistingLibraryEditor createdLibraryEditor = ((LibrariesModifiableModel)model).getLibraryEditor(library);
|
||||
libraryEditor.copyRoots(createdLibraryEditor);
|
||||
return library;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
<orderEntry type="module" module-name="vcs-impl" />
|
||||
<orderEntry type="module" module-name="icons" />
|
||||
<orderEntry type="library" name="jcip" level="project" />
|
||||
<orderEntry type="library" name="Groovy" level="project" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
+11
-5
@@ -31,6 +31,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
@@ -177,7 +178,16 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
final PsiElement lastElement = file.findElementAt(offset - 1);
|
||||
final JavaAwareCompletionData completionData = ApplicationManager.getApplication().runReadAction(new Computable<JavaAwareCompletionData>() {
|
||||
public JavaAwareCompletionData compute() {
|
||||
return getCompletionDataByElementInner(lastElement);
|
||||
if (lastElement != null) {
|
||||
if (!lastElement.isValid()) {
|
||||
throw new ProcessCanceledException();
|
||||
}
|
||||
if (PsiUtil.isLanguageLevel5OrHigher(lastElement)) {
|
||||
return ourJava15CompletionData;
|
||||
}
|
||||
}
|
||||
|
||||
return ourJavaCompletionData;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -351,10 +361,6 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
}
|
||||
|
||||
private static JavaAwareCompletionData getCompletionDataByElementInner(PsiElement element) {
|
||||
return element != null && PsiUtil.isLanguageLevel5OrHigher(element) ? ourJava15CompletionData : ourJavaCompletionData;
|
||||
}
|
||||
|
||||
|
||||
public String advertise(@NotNull final CompletionParameters parameters) {
|
||||
if (!(parameters.getOriginalFile() instanceof PsiJavaFile)) return null;
|
||||
|
||||
+26
-16
@@ -20,6 +20,7 @@ import com.intellij.codeInspection.*;
|
||||
import com.intellij.ide.fileTemplates.FileTemplate;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager;
|
||||
import com.intellij.ide.fileTemplates.JavaTemplateUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -113,26 +114,35 @@ class CatchBodyVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
|
||||
private static LocalQuickFix[] createQuickFix(final PsiCatchSection section) {
|
||||
FileTemplate template = FileTemplateManager.getInstance().getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
|
||||
final Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final PsiParameter parameter = section.getParameter();
|
||||
if (parameter == null) return;
|
||||
PsiCodeBlock catchBlock = section.getCatchBlock();
|
||||
if (catchBlock == null) return;
|
||||
PsiType type = parameter.getType();
|
||||
if (!(type instanceof PsiClassType)) return;
|
||||
final PsiJavaParserFacade elementFactory = JavaPsiFacade.getInstance(section.getProject()).getParserFacade();
|
||||
try {
|
||||
PsiCatchSection sectionTemplate = elementFactory.createCatchSection((PsiClassType)type, parameter.getName(), parameter);
|
||||
section.replace(sectionTemplate);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
ReplaceWithFileTemplateFix replaceWithFileTemplateFix = new ReplaceWithFileTemplateFix() {
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiParameter parameter = section.getParameter();
|
||||
if (parameter == null) return;
|
||||
PsiCodeBlock catchBlock = section.getCatchBlock();
|
||||
if (catchBlock == null) return;
|
||||
PsiType type = parameter.getType();
|
||||
if (!(type instanceof PsiClassType)) return;
|
||||
final PsiJavaParserFacade elementFactory = JavaPsiFacade.getInstance(section.getProject()).getParserFacade();
|
||||
try {
|
||||
PsiCatchSection sectionTemplate = elementFactory.createCatchSection((PsiClassType)type, parameter.getName(), parameter);
|
||||
section.replace(sectionTemplate);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
};
|
||||
LocalQuickFix editFileTemplateFix = DefaultFileTemplateUsageInspection.createEditFileTemplateFix(template, replaceWithFileTemplateFix);
|
||||
LocalQuickFix editFileTemplateFix = DefaultFileTemplateUsageInspection.createEditFileTemplateFix(template, runnable);
|
||||
if (template.isDefault()) {
|
||||
return new LocalQuickFix[]{editFileTemplateFix};
|
||||
}
|
||||
|
||||
+56
-22
@@ -15,14 +15,17 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.defaultFileTemplateUsage;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.ide.fileTemplates.FileTemplate;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager;
|
||||
import com.intellij.ide.fileTemplates.impl.FileTemplateConfigurable;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -119,31 +122,62 @@ public class DefaultFileTemplateUsageInspection extends BaseJavaLocalInspectionT
|
||||
return new InspectionOptions(this).getComponent();
|
||||
}
|
||||
|
||||
public static LocalQuickFix createEditFileTemplateFix(final FileTemplate templateToEdit, final LocalQuickFix replaceTemplateFix) {
|
||||
return new LocalQuickFix() {
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return InspectionsBundle.message("default.file.template.edit.template");
|
||||
}
|
||||
public static LocalQuickFix createEditFileTemplateFix(final FileTemplate templateToEdit, final Runnable replaceTemplateFix) {
|
||||
return new MyLocalQuickFix(templateToEdit, replaceTemplateFix);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return getName();
|
||||
}
|
||||
private static class MyLocalQuickFix implements LocalQuickFix, IntentionAction {
|
||||
private final FileTemplate myTemplateToEdit;
|
||||
private final Runnable myReplaceTemplateFix;
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final FileTemplateConfigurable configurable = new FileTemplateConfigurable();
|
||||
SwingUtilities.invokeLater(new Runnable(){
|
||||
public void run() {
|
||||
configurable.setTemplate(templateToEdit, null);
|
||||
}
|
||||
});
|
||||
boolean ok = ShowSettingsUtil.getInstance().editConfigurable(project, configurable);
|
||||
if (ok) {
|
||||
replaceTemplateFix.applyFix(project, descriptor);
|
||||
FileTemplateManager.getInstance().saveAll();
|
||||
public MyLocalQuickFix(FileTemplate templateToEdit, Runnable replaceTemplateFix) {
|
||||
myTemplateToEdit = templateToEdit;
|
||||
myReplaceTemplateFix = replaceTemplateFix;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return InspectionsBundle.message("default.file.template.edit.template");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
invoke(project, null, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
final FileTemplateConfigurable configurable = new FileTemplateConfigurable();
|
||||
SwingUtilities.invokeLater(new Runnable(){
|
||||
public void run() {
|
||||
configurable.setTemplate(myTemplateToEdit, null);
|
||||
}
|
||||
});
|
||||
boolean ok = ShowSettingsUtil.getInstance().editConfigurable(project, configurable);
|
||||
if (ok) {
|
||||
myReplaceTemplateFix.run();
|
||||
FileTemplateManager.getInstance().saveAll();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+57
-47
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.CodeInsightUtil;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.ide.fileTemplates.FileTemplate;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -82,61 +83,70 @@ public class FileHeaderChecker {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Properties computeProperties(final Matcher matcher, final TIntObjectHashMap<String> offsetToProperty) {
|
||||
Properties properties = new Properties(FileTemplateManager.getInstance().getDefaultProperties());
|
||||
int[] offsets = offsetToProperty.keys();
|
||||
Arrays.sort(offsets);
|
||||
|
||||
for (int i = 0; i < offsets.length; i++) {
|
||||
final int offset = offsets[i];
|
||||
String propName = offsetToProperty.get(offset);
|
||||
int groupNum = i + 2; // first group is whole doc comment
|
||||
String propValue = matcher.group(groupNum);
|
||||
properties.put(propName, propValue);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
private static LocalQuickFix[] createQuickFix(final PsiDocComment element,
|
||||
final Matcher matcher,
|
||||
final TIntObjectHashMap<String> offsetToProperty) {
|
||||
final FileTemplate template = FileTemplateManager.getInstance().getPattern(FileTemplateManager.FILE_HEADER_TEMPLATE_NAME);
|
||||
final ReplaceWithFileTemplateFix replaceTemplateFix = new ReplaceWithFileTemplateFix() {
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
if (!element.isValid()) return;
|
||||
if (!CodeInsightUtil.preparePsiElementsForWrite(element)) return;
|
||||
String newText;
|
||||
try {
|
||||
newText = template.getText(computeProperties(matcher, offsetToProperty));
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error(e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
int offset = element.getTextRange().getStartOffset();
|
||||
PsiFile psiFile = element.getContainingFile();
|
||||
if (psiFile == null) return;
|
||||
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
|
||||
Document document = documentManager.getDocument(psiFile);
|
||||
if (document == null) return;
|
||||
final Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
if (!element.isValid()) return;
|
||||
if (!CodeInsightUtil.preparePsiElementsForWrite(element)) return;
|
||||
String newText;
|
||||
try {
|
||||
newText = template.getText(computeProperties(matcher, offsetToProperty));
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error(e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
int offset = element.getTextRange().getStartOffset();
|
||||
PsiFile psiFile = element.getContainingFile();
|
||||
if (psiFile == null) return;
|
||||
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(psiFile.getProject());
|
||||
Document document = documentManager.getDocument(psiFile);
|
||||
if (document == null) return;
|
||||
|
||||
element.delete();
|
||||
documentManager.doPostponedOperationsAndUnblockDocument(document);
|
||||
documentManager.commitDocument(document);
|
||||
element.delete();
|
||||
documentManager.doPostponedOperationsAndUnblockDocument(document);
|
||||
documentManager.commitDocument(document);
|
||||
|
||||
document.insertString(offset, newText);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
LOG.error("Cannot create doc comment from text: '"+newText+"'",e);
|
||||
}
|
||||
}
|
||||
|
||||
private Properties computeProperties(final Matcher matcher, final TIntObjectHashMap<String> offsetToProperty) {
|
||||
Properties properties = new Properties(FileTemplateManager.getInstance().getDefaultProperties());
|
||||
int[] offsets = offsetToProperty.keys();
|
||||
Arrays.sort(offsets);
|
||||
|
||||
for (int i = 0; i < offsets.length; i++) {
|
||||
final int offset = offsets[i];
|
||||
String propName = offsetToProperty.get(offset);
|
||||
int groupNum = i + 2; // first group is whole doc comment
|
||||
String propValue = matcher.group(groupNum);
|
||||
properties.put(propName, propValue);
|
||||
}
|
||||
|
||||
return properties;
|
||||
document.insertString(offset, newText);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
LOG.error("Cannot create doc comment from text: '" + newText + "'", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
final LocalQuickFix editFileTemplateFix = DefaultFileTemplateUsageInspection.createEditFileTemplateFix(template, replaceTemplateFix);
|
||||
|
||||
final ReplaceWithFileTemplateFix replaceTemplateFix = new ReplaceWithFileTemplateFix() {
|
||||
public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
runnable.run();
|
||||
}
|
||||
};
|
||||
final LocalQuickFix editFileTemplateFix = DefaultFileTemplateUsageInspection.createEditFileTemplateFix(template, runnable);
|
||||
if (template.isDefault()) {
|
||||
return new LocalQuickFix[]{editFileTemplateFix};
|
||||
}
|
||||
|
||||
+32
-22
@@ -23,6 +23,7 @@ import com.intellij.codeInspection.*;
|
||||
import com.intellij.ide.fileTemplates.FileTemplate;
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager;
|
||||
import com.intellij.ide.fileTemplates.JavaTemplateUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
@@ -168,31 +169,40 @@ public class MethodBodyChecker {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ReplaceWithFileTemplateFix replaceWithFileTemplateFix = new ReplaceWithFileTemplateFix() {
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
PsiType returnType = method.getReturnType();
|
||||
if (method.isConstructor() || returnType == null) return;
|
||||
PsiCodeBlock body = method.getBody();
|
||||
if (body == null) return;
|
||||
if (!CodeInsightUtil.preparePsiElementsForWrite(body)) return;
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
if (aClass == null) return;
|
||||
List<HierarchicalMethodSignature> superSignatures = method.getHierarchicalMethodSignature().getSuperSignatures();
|
||||
try {
|
||||
PsiMethod templateMethod = JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createMethod("x", returnType);
|
||||
setupMethodBody(superSignatures, templateMethod, aClass, false);
|
||||
final PsiCodeBlock templateBody = templateMethod.getBody();
|
||||
if (templateBody == null) return;
|
||||
final Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
PsiType returnType = method.getReturnType();
|
||||
if (method.isConstructor() || returnType == null) return;
|
||||
PsiCodeBlock body = method.getBody();
|
||||
if (body == null) return;
|
||||
if (!CodeInsightUtil.preparePsiElementsForWrite(body)) return;
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
if (aClass == null) return;
|
||||
List<HierarchicalMethodSignature> superSignatures = method.getHierarchicalMethodSignature().getSuperSignatures();
|
||||
try {
|
||||
PsiMethod templateMethod = JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createMethod("x", returnType);
|
||||
setupMethodBody(superSignatures, templateMethod, aClass, false);
|
||||
final PsiCodeBlock templateBody = templateMethod.getBody();
|
||||
if (templateBody == null) return;
|
||||
|
||||
PsiElement newBody = body.replace(templateBody);
|
||||
CodeStyleManager.getInstance(project).reformat(newBody);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
PsiElement newBody = body.replace(templateBody);
|
||||
CodeStyleManager.getInstance(aClass.getManager()).reformat(newBody);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
LocalQuickFix editFileTemplateFix = DefaultFileTemplateUsageInspection.createEditFileTemplateFix(template, replaceWithFileTemplateFix);
|
||||
final ReplaceWithFileTemplateFix replaceWithFileTemplateFix = new ReplaceWithFileTemplateFix() {
|
||||
public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
runnable.run();
|
||||
}
|
||||
};
|
||||
LocalQuickFix editFileTemplateFix = DefaultFileTemplateUsageInspection.createEditFileTemplateFix(template, runnable);
|
||||
if (template != null && template.isDefault()) {
|
||||
return new LocalQuickFix[]{editFileTemplateFix};
|
||||
}
|
||||
|
||||
+33
-4
@@ -26,12 +26,19 @@ import com.intellij.codeInspection.BaseJavaLocalInspectionTool;
|
||||
import com.intellij.codeInspection.ex.UnfairLocalInspectionTool;
|
||||
import com.intellij.codeInspection.reference.EntryPoint;
|
||||
import com.intellij.codeInspection.util.SpecialAnnotationsUtil;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.extensions.ExtensionPoint;
|
||||
import com.intellij.openapi.extensions.ExtensionPointListener;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.extensions.PluginDescriptor;
|
||||
import com.intellij.openapi.util.JDOMExternalizableStringList;
|
||||
import com.intellij.profile.codeInspection.InspectionProfileManager;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import com.intellij.psi.util.PropertyUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import gnu.trove.THashSet;
|
||||
import org.intellij.lang.annotations.Pattern;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -49,7 +56,7 @@ import java.util.List;
|
||||
* Date: 17-Feb-2006
|
||||
*/
|
||||
public class UnusedSymbolLocalInspection extends BaseJavaLocalInspectionTool implements UnfairLocalInspectionTool {
|
||||
private static final Collection<String> STANDARD_INJECTION_ANNOS = Collections.unmodifiableCollection(new HashSet<String>(Arrays.asList(
|
||||
private static final Collection<String> STANDARD_INJECTION_ANNOS = Collections.unmodifiableCollection(new THashSet<String>(Arrays.asList(
|
||||
"javax.annotation.Resource",
|
||||
"javax.ejb.EJB",
|
||||
"javax.xml.ws.WebServiceRef",
|
||||
@@ -70,6 +77,28 @@ public class UnusedSymbolLocalInspection extends BaseJavaLocalInspectionTool imp
|
||||
public boolean REPORT_PARAMETER_FOR_PUBLIC_METHODS = true;
|
||||
public JDOMExternalizableStringList INJECTION_ANNOS = new JDOMExternalizableStringList();
|
||||
|
||||
static {
|
||||
final ExtensionPoint<EntryPoint> point = Extensions.getRootArea().getExtensionPoint(ExtensionPoints.DEAD_CODE_TOOL);
|
||||
point.addExtensionPointListener(new ExtensionPointListener<EntryPoint>() {
|
||||
@Override
|
||||
public void extensionAdded(@NotNull EntryPoint extension, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
extensionRemoved(extension, pluginDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extensionRemoved(@NotNull EntryPoint extension, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
ANNOTATIONS = null;
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (ApplicationManager.getApplication().isDisposed()) return;
|
||||
InspectionProfileManager.getInstance().fireProfileChanged(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getGroupDisplayName() {
|
||||
return GroupNames.DECLARATION_REDUNDANCY;
|
||||
@@ -113,7 +142,6 @@ public class UnusedSymbolLocalInspection extends BaseJavaLocalInspectionTool imp
|
||||
private JPanel myPanel;
|
||||
|
||||
public OptionsPanel() {
|
||||
|
||||
myCheckLocalVariablesCheckBox.setSelected(LOCAL_VARIABLE);
|
||||
myCheckClassesCheckBox.setSelected(CLASS);
|
||||
myCheckFieldsCheckBox.setSelected(FIELD);
|
||||
@@ -169,8 +197,9 @@ public class UnusedSymbolLocalInspection extends BaseJavaLocalInspectionTool imp
|
||||
List<String> annotations = ANNOTATIONS;
|
||||
if (annotations == null) {
|
||||
annotations = new ArrayList<String>();
|
||||
for (Object extension : Extensions.getExtensions(ExtensionPoints.DEAD_CODE_TOOL)) {
|
||||
final String[] ignoredAnnotations = ((EntryPoint)extension).getIgnoreAnnotations();
|
||||
EntryPoint[] extensions = Extensions.getExtensions(ExtensionPoints.DEAD_CODE_TOOL, null);
|
||||
for (EntryPoint extension : extensions) {
|
||||
final String[] ignoredAnnotations = extension.getIgnoreAnnotations();
|
||||
if (ignoredAnnotations != null) {
|
||||
ContainerUtil.addAll(annotations, ignoredAnnotations);
|
||||
}
|
||||
|
||||
@@ -602,7 +602,7 @@ public class JavaFindUsagesHandler extends FindUsagesHandler{
|
||||
final PsiClass parentClass = method.getContainingClass();
|
||||
|
||||
if (parentClass != null) {
|
||||
MethodReferencesSearch.search(new MethodReferencesSearch.SearchParameters(method, searchScope, !((JavaMethodFindUsagesOptions)options).isIncludeOverloadUsages, options.fastTrack)).forEach(new ReadActionProcessor<PsiReference>() {
|
||||
MethodReferencesSearch.search(new MethodReferencesSearch.SearchParameters(method, searchScope, options instanceof JavaMethodFindUsagesOptions ? !((JavaMethodFindUsagesOptions)options).isIncludeOverloadUsages : true, options.fastTrack)).forEach(new ReadActionProcessor<PsiReference>() {
|
||||
public boolean processInReadAction(final PsiReference ref) {
|
||||
return addResult(result, ref, options);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,9 @@ package com.intellij.ide;
|
||||
import com.intellij.lang.StdLanguages;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.DataKeys;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
import com.intellij.openapi.ide.CopyPasteManager;
|
||||
@@ -47,8 +48,10 @@ public class JavaFilePasteProvider implements PasteProvider {
|
||||
if (classes.length != 1) return;
|
||||
final PsiDirectory targetDir = ideView.getOrChooseDirectory();
|
||||
if (targetDir == null) return;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
|
||||
new WriteCommandAction(project, "Paste class '" + classes[0].getName() + "'") {
|
||||
@Override
|
||||
protected void run(Result result) throws Throwable {
|
||||
PsiFile file;
|
||||
try {
|
||||
file = targetDir.createFile(classes[0].getName() + ".java");
|
||||
@@ -64,7 +67,7 @@ public class JavaFilePasteProvider implements PasteProvider {
|
||||
}
|
||||
new OpenFileDescriptor(project, file.getVirtualFile()).navigate(true);
|
||||
}
|
||||
});
|
||||
}.execute();
|
||||
}
|
||||
|
||||
private static void updatePackageStatement(final PsiJavaFile javaFile, final PsiDirectory targetDir) {
|
||||
|
||||
@@ -51,10 +51,12 @@ public class JavaFileElementType extends IStubFileElementType<PsiJavaFileStub> {
|
||||
super("java.FILE", StdLanguages.JAVA);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StubBuilder getBuilder() {
|
||||
return new JavaFileStubBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStubVersion() {
|
||||
return STUB_VERSION;
|
||||
}
|
||||
@@ -65,6 +67,7 @@ public class JavaFileElementType extends IStubFileElementType<PsiJavaFileStub> {
|
||||
return dir == null || dir.getUserData(LanguageLevel.KEY) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ASTNode parseContents(final ASTNode chameleon) {
|
||||
if (JavaParserDefinition.USE_NEW_PARSER) {
|
||||
final PsiBuilder builder = JavaParserUtil.createBuilder(chameleon);
|
||||
@@ -84,22 +87,26 @@ public class JavaFileElementType extends IStubFileElementType<PsiJavaFileStub> {
|
||||
return FileTextParsing.parseFileText(manager, lexer, seq, 0, seq.length(), node.getCharTable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExternalId() {
|
||||
return "java.FILE";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(final PsiJavaFileStub stub, final StubOutputStream dataStream)
|
||||
throws IOException {
|
||||
dataStream.writeBoolean(stub.isCompiled());
|
||||
dataStream.writeName(stub.getPackageName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiJavaFileStub deserialize(final StubInputStream dataStream, final StubElement parentStub) throws IOException {
|
||||
boolean compiled = dataStream.readBoolean();
|
||||
StringRef packName = dataStream.readName();
|
||||
return new PsiJavaFileStubImpl(packName, compiled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indexStub(final PsiJavaFileStub stub, final IndexSink sink) {
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -47,11 +47,11 @@ public class JavaConcatenationInjectorManager implements ModificationTracker {
|
||||
public JavaConcatenationInjectorManager(Project project, PsiManagerEx psiManagerEx) {
|
||||
final ExtensionPoint<ConcatenationAwareInjector> concatPoint = Extensions.getArea(project).getExtensionPoint(CONCATENATION_INJECTOR_EP_NAME);
|
||||
concatPoint.addExtensionPointListener(new ExtensionPointListener<ConcatenationAwareInjector>() {
|
||||
public void extensionAdded(ConcatenationAwareInjector injector, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
public void extensionAdded(@NotNull ConcatenationAwareInjector injector, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
registerConcatenationInjector(injector);
|
||||
}
|
||||
|
||||
public void extensionRemoved(ConcatenationAwareInjector injector, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
public void extensionRemoved(@NotNull ConcatenationAwareInjector injector, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
unregisterConcatenationInjector(injector);
|
||||
}
|
||||
});
|
||||
|
||||
+3
-1
@@ -366,7 +366,9 @@ public class PsiReferenceExpressionImpl extends ExpressionPsiElement implements
|
||||
public void processVariants(PsiScopeProcessor processor) {
|
||||
OrFilter filter = new OrFilter();
|
||||
filter.addFilter(ElementClassFilter.CLASS);
|
||||
filter.addFilter(ElementClassFilter.PACKAGE_FILTER);
|
||||
if (isQualified()) {
|
||||
filter.addFilter(ElementClassFilter.PACKAGE_FILTER);
|
||||
}
|
||||
filter.addFilter(new AndFilter(ElementClassFilter.METHOD, new NotFilter(new ConstructorFilter())));
|
||||
filter.addFilter(ElementClassFilter.VARIABLE);
|
||||
|
||||
|
||||
+9
-1
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.refactoring.changeSignature;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightUtilBase;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
@@ -23,11 +24,14 @@ import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.PsiSearchHelper;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.util.CanonicalTypes;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -65,7 +69,11 @@ public class JavaChangeSignatureDetector implements LanguageChangeSignatureDetec
|
||||
}
|
||||
final MyJavaChangeInfo fromMethod = new MyJavaChangeInfo(newVisibility, method, newReturnType, parameterInfos, null, method.getName());
|
||||
if (changeInfo == null) { //before replacement
|
||||
fromMethod.setSuperMethod(method.findDeepestSuperMethod());
|
||||
final PsiMethod deepestSuperMethod = method.findDeepestSuperMethod();
|
||||
if (deepestSuperMethod != null) {
|
||||
if (!deepestSuperMethod.getManager().isInProject(deepestSuperMethod)) return null;
|
||||
}
|
||||
fromMethod.setSuperMethod(deepestSuperMethod);
|
||||
return fromMethod;
|
||||
} else {
|
||||
final MyJavaChangeInfo info = (MyJavaChangeInfo)changeInfo;
|
||||
|
||||
+5
@@ -24,6 +24,7 @@ import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiCachedValue;
|
||||
import com.intellij.psi.impl.file.JavaDirectoryServiceImpl;
|
||||
import com.intellij.psi.impl.source.jsp.jspJava.JspClass;
|
||||
import com.intellij.refactoring.JavaRefactoringSettings;
|
||||
@@ -307,6 +308,10 @@ public class MoveClassesOrPackagesHandlerBase extends MoveHandlerDelegate {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (target instanceof PsiDirectory && source instanceof PsiDirectory) {
|
||||
final PsiPackage aPackage = JavaDirectoryServiceImpl.getInstance().getPackage((PsiDirectory)source);
|
||||
if (aPackage != null && !MoveClassesOrPackagesImpl.checkNesting(target.getProject(), aPackage, target, false)) return true;
|
||||
}
|
||||
return super.isMoveRedundant(source, target);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-6
@@ -98,13 +98,13 @@ public class MoveClassesOrPackagesImpl {
|
||||
CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("move.title"), message, HelpID.getMoveHelpID(element), project);
|
||||
return null;
|
||||
}
|
||||
if (!checkNesting(project, aPackage, targetElement)) return null;
|
||||
if (!checkNesting(project, aPackage, targetElement, true)) return null;
|
||||
if (!checkMovePackage(project, aPackage)) return null;
|
||||
element = aPackage;
|
||||
}
|
||||
else if (element instanceof PsiPackage) {
|
||||
final PsiPackage psiPackage = (PsiPackage)element;
|
||||
if (!checkNesting(project, psiPackage, targetElement)) return null;
|
||||
if (!checkNesting(project, psiPackage, targetElement, true)) return null;
|
||||
if (!checkMovePackage(project, psiPackage)) return null;
|
||||
}
|
||||
else if (element instanceof PsiClass) {
|
||||
@@ -166,16 +166,18 @@ public class MoveClassesOrPackagesImpl {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean checkNesting(final Project project, final PsiPackage srcPackage, final PsiElement targetElement) {
|
||||
static boolean checkNesting(final Project project, final PsiPackage srcPackage, final PsiElement targetElement, boolean showError) {
|
||||
final PsiPackage targetPackage = targetElement instanceof PsiPackage
|
||||
? (PsiPackage)targetElement
|
||||
: targetElement instanceof PsiDirectory ? JavaDirectoryService.getInstance()
|
||||
.getPackage((PsiDirectory)targetElement) : null;
|
||||
for (PsiPackage curPackage = targetPackage; curPackage != null; curPackage = curPackage.getParentPackage()) {
|
||||
if (curPackage.equals(srcPackage)) {
|
||||
CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("move.title"),
|
||||
RefactoringBundle.message("cannot.move.package.into.itself"),
|
||||
HelpID.getMoveHelpID(srcPackage), project);
|
||||
if (showError) {
|
||||
CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("move.title"),
|
||||
RefactoringBundle.message("cannot.move.package.into.itself"),
|
||||
HelpID.getMoveHelpID(srcPackage), project);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
|
||||
public class <warning descr="Class 'WithMain' is never used">WithMain</warning> {
|
||||
@MyAnno
|
||||
public void <warning descr="Method 'myTestMethod()' is never used">myTestMethod</warning>(){}
|
||||
}
|
||||
|
||||
@interface MyAnno {
|
||||
|
||||
}
|
||||
+17
@@ -33,6 +33,23 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
assertEmpty(myItems);
|
||||
}
|
||||
|
||||
public void testNoPackagesInExpressionCodeFragment() throws Throwable {
|
||||
final String text = "jav<caret>";
|
||||
PsiFile file = getJavaFacade().getElementFactory().createExpressionCodeFragment(text, null, null, true);
|
||||
myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
|
||||
complete();
|
||||
myFixture.checkResult(text);
|
||||
assertEmpty(myItems);
|
||||
}
|
||||
|
||||
public void testSubPackagesInExpressionCodeFragment() throws Throwable {
|
||||
PsiFile file = getJavaFacade().getElementFactory().createExpressionCodeFragment("java.la<caret>", null, null, true);
|
||||
myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
|
||||
complete();
|
||||
myFixture.checkResult("java.lang.<caret>");
|
||||
assertNull(myItems);
|
||||
}
|
||||
|
||||
private JavaPsiFacade getJavaFacade() {
|
||||
return JavaPsiFacade.getInstance(getProject());
|
||||
}
|
||||
|
||||
+86
-1
@@ -1,6 +1,21 @@
|
||||
package com.intellij.codeInsight.daemon;
|
||||
|
||||
import com.intellij.ExtensionPoints;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
|
||||
import com.intellij.codeInspection.reference.EntryPoint;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.extensions.ExtensionPoint;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is for "lightweight" tests only, i.e. those which can run inside default light project set up
|
||||
@@ -13,12 +28,17 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
|
||||
doTest(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, checkInfos);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
return new LocalInspectionTool[]{new UnusedSymbolLocalInspection()};
|
||||
}
|
||||
|
||||
public void testDuplicateAnnotations() throws Exception {
|
||||
doTest(false, false);
|
||||
}
|
||||
|
||||
public void testSwitchByString() throws Exception {
|
||||
doTest(true, false);
|
||||
doTest(false, false);
|
||||
}
|
||||
|
||||
public void testDiamondPos1() throws Exception {
|
||||
@@ -56,4 +76,69 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testDiamondNeg5() throws Exception {
|
||||
doTest(false, false);
|
||||
}
|
||||
|
||||
public void testDynamicallyAddIgnoredAnnotations() throws Exception {
|
||||
ExtensionPoint<EntryPoint> point = Extensions.getRootArea().getExtensionPoint(ExtensionPoints.DEAD_CODE_TOOL);
|
||||
EntryPoint extension = new EntryPoint() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "duh";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEntryPoint(RefElement refElement, PsiElement psiElement) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEntryPoint(PsiElement psiElement) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(boolean selected) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(Element element) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getIgnoreAnnotations() {
|
||||
return new String[]{"MyAnno"};
|
||||
}
|
||||
};
|
||||
|
||||
UnusedDeclarationInspection deadCodeInspection = new UnusedDeclarationInspection();
|
||||
enableInspectionTool(deadCodeInspection);
|
||||
|
||||
doTest(true, false);
|
||||
List<HighlightInfo> infos = DaemonAnalyzerTestCase.filter(doHighlighting(), HighlightSeverity.WARNING);
|
||||
assertEquals(2, infos.size()); // unused class and unused method
|
||||
|
||||
try {
|
||||
point.registerExtension(extension);
|
||||
|
||||
infos = DaemonAnalyzerTestCase.filter(doHighlighting(), HighlightSeverity.WARNING);
|
||||
HighlightInfo info = assertOneElement(infos);
|
||||
assertEquals("Class 'WithMain' is never used", info.description);
|
||||
}
|
||||
finally {
|
||||
point.unregisterExtension(extension);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-2
@@ -3,10 +3,10 @@ package com.intellij.codeInsight.daemon;
|
||||
import com.intellij.ExtensionPoints;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.accessStaticViaInstance.AccessStaticViaInstance;
|
||||
import com.intellij.codeInspection.reference.EntryPoint;
|
||||
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
|
||||
import com.intellij.codeInspection.deprecation.DeprecationInspection;
|
||||
import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection;
|
||||
import com.intellij.codeInspection.reference.EntryPoint;
|
||||
import com.intellij.codeInspection.reference.RefElement;
|
||||
import com.intellij.codeInspection.sillyAssignment.SillyAssignmentInspection;
|
||||
import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection;
|
||||
@@ -56,7 +56,6 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
setLanguageLevel(LanguageLevel.JDK_1_4);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
myUnusedSymbolLocalInspection = new UnusedSymbolLocalInspection();
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package com.intellij.openapi.extensions;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface ExtensionPointListener<T> {
|
||||
void extensionAdded(T extension, @Nullable final PluginDescriptor pluginDescriptor);
|
||||
void extensionRemoved(T extension, @Nullable final PluginDescriptor pluginDescriptor);
|
||||
void extensionAdded(@NotNull T extension, @Nullable final PluginDescriptor pluginDescriptor);
|
||||
void extensionRemoved(@NotNull T extension, @Nullable final PluginDescriptor pluginDescriptor);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public abstract class SmartExtensionPoint<Extension,V> implements ExtensionPoint
|
||||
}
|
||||
}
|
||||
|
||||
public final void extensionAdded(final Extension extension, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
public final void extensionAdded(@NotNull final Extension extension, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
dropCache();
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public abstract class SmartExtensionPoint<Extension,V> implements ExtensionPoint
|
||||
}
|
||||
}
|
||||
|
||||
public final void extensionRemoved(final Extension extension, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
public final void extensionRemoved(@NotNull final Extension extension, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
dropCache();
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -250,7 +250,7 @@ public class ExtensionsAreaImpl implements ExtensionsArea {
|
||||
|
||||
getExtensionPoint(EPAvailabilityListenerExtension.EXTENSION_POINT_NAME).addExtensionPointListener(new ExtensionPointListener() {
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public void extensionRemoved(Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
public void extensionRemoved(@NotNull Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
EPAvailabilityListenerExtension epListenerExtension = (EPAvailabilityListenerExtension) extension;
|
||||
Collection<ExtensionPointAvailabilityListener> listeners = myAvailabilityListeners.get(epListenerExtension.getExtensionPointName());
|
||||
for (Iterator<ExtensionPointAvailabilityListener> iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
@@ -263,7 +263,7 @@ public class ExtensionsAreaImpl implements ExtensionsArea {
|
||||
myLogger.warn("Failed to find EP availability listener: " + epListenerExtension.getListenerClass());
|
||||
}
|
||||
|
||||
public void extensionAdded(Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
public void extensionAdded(@NotNull Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
EPAvailabilityListenerExtension epListenerExtension = (EPAvailabilityListenerExtension) extension;
|
||||
try {
|
||||
String epName = epListenerExtension.getExtensionPointName();
|
||||
|
||||
+5
-4
@@ -17,6 +17,7 @@ package com.intellij.openapi.extensions.impl;
|
||||
|
||||
import com.intellij.openapi.extensions.*;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.picocontainer.defaults.DefaultPicoContainer;
|
||||
|
||||
/**
|
||||
@@ -101,12 +102,12 @@ public class ExtensionPointImplTest extends TestCase {
|
||||
final boolean removed[] = new boolean[1];
|
||||
extensionPoint.addExtensionPointListener(new ExtensionPointListener() {
|
||||
@Override
|
||||
public void extensionAdded(Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
public void extensionAdded(@NotNull Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
added[0] = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extensionRemoved(Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
public void extensionRemoved(@NotNull Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
removed[0] = true;
|
||||
}
|
||||
});
|
||||
@@ -128,12 +129,12 @@ public class ExtensionPointImplTest extends TestCase {
|
||||
assertFalse(added[0]);
|
||||
extensionPoint.addExtensionPointListener(new ExtensionPointListener() {
|
||||
@Override
|
||||
public void extensionAdded(Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
public void extensionAdded(@NotNull Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
added[0] = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extensionRemoved(Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
public void extensionRemoved(@NotNull Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
}
|
||||
});
|
||||
assertTrue(added[0]);
|
||||
|
||||
+3
-2
@@ -17,6 +17,7 @@ package com.intellij.openapi.extensions.impl;
|
||||
|
||||
import com.intellij.openapi.extensions.*;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.picocontainer.MutablePicoContainer;
|
||||
import org.picocontainer.defaults.DefaultPicoContainer;
|
||||
|
||||
@@ -56,11 +57,11 @@ public class ExtensionsImplTest extends TestCase {
|
||||
removed[0] = false;
|
||||
extensionsArea.getExtensionPoint(EXTENSION_POINT_NAME_1).addExtensionPointListener(new ExtensionPointListener() {
|
||||
@Override
|
||||
public void extensionAdded(Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
public void extensionAdded(@NotNull Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extensionRemoved(Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
public void extensionRemoved(@NotNull Object extension, final PluginDescriptor pluginDescriptor) {
|
||||
removed[0] = true;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class EntryPoint implements JDOMExternalizable , Cloneable {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String [] getIgnoreAnnotations() {
|
||||
public String[] getIgnoreAnnotations() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007 Bas Leijdekkers
|
||||
* Copyright 2007-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.ui;
|
||||
|
||||
import com.intellij.codeInspection.ui.ListWrappingTableModel;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.JTableHeader;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableModel;
|
||||
import java.awt.*;
|
||||
@@ -30,7 +30,20 @@ public class ListTable extends JBTable {
|
||||
setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
|
||||
setRowSelectionAllowed(true);
|
||||
setDragEnabled(false);
|
||||
getTableHeader().setReorderingAllowed(false);
|
||||
final JTableHeader header = getTableHeader();
|
||||
header.setReorderingAllowed(false);
|
||||
final TableCellRenderer delegate = header.getDefaultRenderer();
|
||||
final TableCellRenderer newRenderer = new TableCellRenderer() {
|
||||
|
||||
@Override
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
final Component component = delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
// to display the table header in disabled state when the table is disabled.
|
||||
component.setEnabled(table.isEnabled());
|
||||
return component;
|
||||
}
|
||||
};
|
||||
header.setDefaultRenderer(newRenderer);
|
||||
setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.lang;
|
||||
|
||||
|
||||
public interface LighterASTTokenNode extends LighterASTNode {
|
||||
/**
|
||||
* <b>Note</b>: a text returned may be linked back to file content text and therefore should be internalized
|
||||
* through {@linkplain com.intellij.util.CharTable} if referenced as is.
|
||||
* @return text of a token
|
||||
*/
|
||||
CharSequence getText();
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class SerializationManagerImpl extends SerializationManager implements Ap
|
||||
private final Map<StubSerializer<? extends StubElement>, Integer> mySerializerToId = new HashMap<StubSerializer<? extends StubElement>, Integer>();
|
||||
private final List<StubSerializer<? extends StubElement>> myAllSerializers = new ArrayList<StubSerializer<? extends StubElement>>();
|
||||
private final AtomicBoolean myNameStorageCrashed = new AtomicBoolean(false);
|
||||
private final File myFile = new File(PathManager.getSystemPath() + "/index/rep.names");
|
||||
private final File myFile = new File(PathManager.getIndexRoot(), "rep.names");
|
||||
private boolean mySerializersLoaded = false;
|
||||
|
||||
public SerializationManagerImpl() {
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
<orderEntry type="module" module-name="vcs-impl" />
|
||||
<orderEntry type="module" module-name="platform-impl" exported="" />
|
||||
<orderEntry type="module" module-name="usageView" exported="" />
|
||||
<orderEntry type="library" name="Groovy" level="project" />
|
||||
<orderEntry type="library" name="Guava" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
+10
-1
@@ -67,6 +67,15 @@ public class ColorAndFontDescriptionPanel extends JPanel {
|
||||
|
||||
add(settingsPanel, BorderLayout.CENTER);
|
||||
setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 4));
|
||||
|
||||
myEffectsCombo.setRenderer(new DefaultListCellRenderer() {
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
if (value == null) value = "Invalid";
|
||||
return super.getListCellRendererComponent(list, value, index, isSelected,
|
||||
cellHasFocus);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private JPanel createSettingsPanel() {
|
||||
@@ -366,7 +375,7 @@ public class ColorAndFontDescriptionPanel extends JPanel {
|
||||
myEffectsCombo.setSelectedItem(BOLD_DOTTED_LINE_EFFECT);
|
||||
}
|
||||
else {
|
||||
LOG.assertTrue(false);
|
||||
myEffectsCombo.setSelectedItem(null);
|
||||
}
|
||||
updatingEffects = false;
|
||||
}
|
||||
|
||||
@@ -109,6 +109,8 @@ public class CodeInsightSettings implements PersistentStateComponent<Element>, C
|
||||
public static final int INDENT_EACH_LINE = 3;
|
||||
public static final int REFORMAT_BLOCK = 4;
|
||||
|
||||
public boolean INDENT_TO_CARET_ON_PASTE = false;
|
||||
|
||||
public int ADD_IMPORTS_ON_PASTE = ASK; // YES, NO or ASK
|
||||
public static final int YES = 1;
|
||||
public static final int NO = 2;
|
||||
|
||||
+119
-97
@@ -48,6 +48,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -90,7 +91,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
public final void invoke(final Project project, final Editor editor) {
|
||||
invoke(project, editor, PsiUtilBase.getPsiFileInEditor(editor, project));
|
||||
}
|
||||
|
||||
|
||||
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile psiFile) {
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
assert !ApplicationManager.getApplication().isWriteAccessAllowed() : "Please don't invoke completion inside write action";
|
||||
@@ -115,7 +116,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
}
|
||||
|
||||
psiFile.putUserData(PsiFileEx.BATCH_REFERENCE_PROCESSING, Boolean.TRUE);
|
||||
|
||||
|
||||
final CompletionProgressIndicator indicator = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
|
||||
if (indicator != null) {
|
||||
if (indicator.isRepeatedInvocation(myCompletionType, editor)) {
|
||||
@@ -143,62 +144,76 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
final CompletionInitializationContext initializationContext = new WriteCommandAction<CompletionInitializationContext>(project) {
|
||||
protected void run(Result<CompletionInitializationContext> result) throws Throwable {
|
||||
CommandProcessor.getInstance().setCurrentCommandGroupId(null);
|
||||
final CompletionInitializationContext[] initializationContext = {null};
|
||||
|
||||
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
|
||||
|
||||
EditorUtil.fillVirtualSpaceUntilCaret(editor);
|
||||
documentManager.commitAllDocuments();
|
||||
final CompletionInitializationContext initializationContext = new CompletionInitializationContext(editor, psiFile, myCompletionType);
|
||||
result.setResult(initializationContext);
|
||||
Runnable initCmd = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
for (final CompletionContributor contributor : CompletionContributor.forLanguage(PsiUtilBase.getLanguageInEditor(editor, project))) {
|
||||
if (DumbService.getInstance(project).isDumb() && !DumbService.isDumbAware(contributor)) {
|
||||
continue;
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
|
||||
|
||||
EditorUtil.fillVirtualSpaceUntilCaret(editor);
|
||||
documentManager.commitAllDocuments();
|
||||
initializationContext[0] = new CompletionInitializationContext(editor, psiFile, myCompletionType);
|
||||
for (final CompletionContributor contributor : CompletionContributor.forLanguage(PsiUtilBase.getLanguageInEditor(editor, project))) {
|
||||
if (DumbService.getInstance(project).isDumb() && !DumbService.isDumbAware(contributor)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
contributor.beforeCompletion(initializationContext[0]);
|
||||
assert !documentManager.isUncommited(document) : "Contributor " + contributor + " left the document uncommitted";
|
||||
}
|
||||
}
|
||||
|
||||
contributor.beforeCompletion(initializationContext);
|
||||
assert !documentManager.isUncommited(document) : "Contributor " + contributor + " left the document uncommitted";
|
||||
}
|
||||
};
|
||||
ApplicationManager.getApplication().runWriteAction(runnable);
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
};
|
||||
if (!focusLookup) {
|
||||
CommandProcessor.getInstance().runUndoTransparentAction(initCmd);
|
||||
} else {
|
||||
CommandProcessor.getInstance().executeCommand(project, initCmd, null, null);
|
||||
}
|
||||
|
||||
final int offset1 = initializationContext[0].getStartOffset();
|
||||
final int offset2 = initializationContext[0].getSelectionEndOffset();
|
||||
final CompletionContext context = new CompletionContext(project, editor, psiFile, initializationContext[0].getOffsetMap());
|
||||
|
||||
final int offset1 = initializationContext.getStartOffset();
|
||||
final int offset2 = initializationContext.getSelectionEndOffset();
|
||||
final CompletionContext context = new CompletionContext(project, editor, psiFile, initializationContext.getOffsetMap());
|
||||
|
||||
doComplete(offset1, offset2, context, initializationContext.getFileCopyPatcher(), editor, time);
|
||||
doComplete(offset1, offset2, context, initializationContext[0].getFileCopyPatcher(), editor, time);
|
||||
}
|
||||
|
||||
protected void doComplete(final int offset1,
|
||||
final int offset2,
|
||||
final CompletionContext context,
|
||||
final FileCopyPatcher patcher, final Editor editor, final int invocationCount) {
|
||||
final Pair<CompletionContext, PsiElement> insertedInfo = new WriteCommandAction<Pair<CompletionContext, PsiElement>>(context.project) {
|
||||
protected void run(Result<Pair<CompletionContext, PsiElement>> result) throws Throwable {
|
||||
result.setResult(insertDummyIdentifier(context, patcher));
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
|
||||
final PsiElement insertedElement = insertedInfo.getSecond();
|
||||
final CompletionContext newContext = insertedInfo.getFirst();
|
||||
insertedElement.putUserData(CompletionContext.COMPLETION_CONTEXT_KEY, newContext);
|
||||
|
||||
PsiFile originalFile = newContext.file;
|
||||
final PsiFile rightLanguagedOriginal = originalFile.getViewProvider().getPsi(insertedElement.getContainingFile().getLanguage());
|
||||
if (rightLanguagedOriginal != null) {
|
||||
originalFile = rightLanguagedOriginal;
|
||||
}
|
||||
|
||||
final CompletionParameters parameters = new CompletionParameters(insertedElement, originalFile, myCompletionType, newContext.getStartOffset(), invocationCount);
|
||||
final CompletionParameters parameters = createCompletionParameters(context, patcher, invocationCount);
|
||||
|
||||
final Semaphore freezeSemaphore = new Semaphore();
|
||||
freezeSemaphore.down();
|
||||
final CompletionProgressIndicator indicator = new CompletionProgressIndicator(editor, parameters, this, context, freezeSemaphore);
|
||||
final CompletionProgressIndicator indicator = new CompletionProgressIndicator(editor, parameters, this, freezeSemaphore, context.getOffsetMap());
|
||||
|
||||
final AtomicReference<LookupElement[]> data = startCompletionThread(parameters, indicator);
|
||||
|
||||
if (!invokedExplicitly) {
|
||||
indicator.notifyBackgrounded();
|
||||
return;
|
||||
}
|
||||
|
||||
if (freezeSemaphore.waitFor(2000)) {
|
||||
final LookupElement[] allItems = data.get();
|
||||
if (allItems != null) { // the completion is really finished, now we may auto-insert or show lookup
|
||||
completionFinished(offset1, offset2, indicator, allItems);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
indicator.notifyBackgrounded();
|
||||
indicator.showLookup();
|
||||
}
|
||||
|
||||
private AtomicReference<LookupElement[]> startCompletionThread(final CompletionParameters parameters, final CompletionProgressIndicator indicator) {
|
||||
final AtomicReference<LookupElement[]> data = new AtomicReference<LookupElement[]>(null);
|
||||
final Semaphore startSemaphore = new Semaphore();
|
||||
startSemaphore.down();
|
||||
@@ -231,27 +246,33 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
}
|
||||
|
||||
startSemaphore.waitFor();
|
||||
|
||||
if (!invokedExplicitly) {
|
||||
indicator.notifyBackgrounded();
|
||||
return;
|
||||
}
|
||||
|
||||
if (freezeSemaphore.waitFor(2000)) {
|
||||
final LookupElement[] allItems = data.get();
|
||||
if (allItems != null) { // the completion is really finished, now we may auto-insert or show lookup
|
||||
completionFinished(offset1, offset2, context, indicator, allItems);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
indicator.notifyBackgrounded();
|
||||
indicator.showLookup();
|
||||
return data;
|
||||
}
|
||||
|
||||
private AutoCompletionDecision shouldAutoComplete(final CompletionContext context,
|
||||
final CompletionProgressIndicator indicator,
|
||||
final LookupElement[] items) {
|
||||
private CompletionParameters createCompletionParameters(final CompletionContext context, final FileCopyPatcher patcher, int invocationCount) {
|
||||
final Ref<Pair<CompletionContext, PsiElement>> ref = Ref.create(null);
|
||||
CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ref.set(insertDummyIdentifier(context, patcher, context.file, context.editor));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
final PsiElement insertedElement = ref.get().getSecond();
|
||||
final CompletionContext newContext = ref.get().getFirst();
|
||||
insertedElement.putUserData(CompletionContext.COMPLETION_CONTEXT_KEY, newContext);
|
||||
|
||||
return new CompletionParameters(insertedElement, newContext.file, myCompletionType, newContext.getStartOffset(), invocationCount);
|
||||
}
|
||||
|
||||
private AutoCompletionDecision shouldAutoComplete(
|
||||
final CompletionProgressIndicator indicator,
|
||||
final LookupElement[] items) {
|
||||
if (!invokedExplicitly) {
|
||||
return AutoCompletionDecision.SHOW_LOOKUP;
|
||||
}
|
||||
@@ -265,7 +286,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
if (!isAutocompleteOnInvocation(parameters.getCompletionType())) {
|
||||
return AutoCompletionDecision.SHOW_LOOKUP;
|
||||
}
|
||||
if (isInsideIdentifier(context.getOffsetMap())) {
|
||||
if (isInsideIdentifier(indicator.getOffsetMap())) {
|
||||
return AutoCompletionDecision.SHOW_LOOKUP;
|
||||
}
|
||||
if (items.length == 1 && getAutocompletionPolicy(item) == AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE) {
|
||||
@@ -273,7 +294,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
}
|
||||
|
||||
for (final CompletionContributor contributor : CompletionContributor.forParameters(parameters)) {
|
||||
final AutoCompletionDecision decision = contributor.handleAutoCompletionPossibility(new AutoCompletionContext(parameters, items, context.getOffsetMap()));
|
||||
final AutoCompletionDecision decision = contributor.handleAutoCompletionPossibility(new AutoCompletionContext(parameters, items, indicator.getOffsetMap()));
|
||||
if (decision != null) {
|
||||
return decision;
|
||||
}
|
||||
@@ -302,15 +323,17 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
}
|
||||
|
||||
|
||||
protected void completionFinished(final int offset1, final int offset2, final CompletionContext context, final CompletionProgressIndicator indicator,
|
||||
protected void completionFinished(final int offset1,
|
||||
final int offset2,
|
||||
final CompletionProgressIndicator indicator,
|
||||
final LookupElement[] items) {
|
||||
if (items.length == 0) {
|
||||
LookupManager.getInstance(context.project).hideActiveLookup();
|
||||
handleEmptyLookup(context.project, context.editor, indicator.getParameters(), indicator);
|
||||
LookupManager.getInstance(indicator.getProject()).hideActiveLookup();
|
||||
handleEmptyLookup(indicator.getProject(), indicator.getEditor(), indicator.getParameters(), indicator);
|
||||
return;
|
||||
}
|
||||
|
||||
final AutoCompletionDecision decision = shouldAutoComplete(context, indicator, items);
|
||||
final AutoCompletionDecision decision = shouldAutoComplete(indicator, items);
|
||||
if (decision == AutoCompletionDecision.SHOW_LOOKUP) {
|
||||
indicator.showLookup();
|
||||
if (isAutocompleteCommonPrefixOnInvocation() && items.length > 1) {
|
||||
@@ -320,8 +343,8 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
final LookupElement item = ((AutoCompletionDecision.InsertItem)decision).getElement();
|
||||
indicator.closeAndFinish();
|
||||
indicator.rememberDocumentState();
|
||||
context.setStartOffset(offset1 - item.getPrefixMatcher().getPrefix().length());
|
||||
handleSingleItem(offset2, context, items, item.getLookupString(), item);
|
||||
indicator.getOffsetMap().addOffset(CompletionInitializationContext.START_OFFSET, (offset1 - item.getPrefixMatcher().getPrefix().length()));
|
||||
handleSingleItem(offset2, indicator, items, item.getLookupString(), item);
|
||||
|
||||
// the insert handler may have started a live template with completion
|
||||
if (CompletionService.getCompletionService() == null) {
|
||||
@@ -330,14 +353,13 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
protected static void handleSingleItem(final int offset2, final CompletionContext context, final LookupElement[] items, final String _uniqueText, final LookupElement item) {
|
||||
|
||||
new WriteCommandAction(context.project) {
|
||||
protected static void handleSingleItem(final int offset2, final CompletionProgressIndicator context, final LookupElement[] items, final String _uniqueText, final LookupElement item) {
|
||||
new WriteCommandAction(context.getProject()) {
|
||||
protected void run(Result result) throws Throwable {
|
||||
String uniqueText = _uniqueText;
|
||||
|
||||
if (item.getObject() instanceof DeferredUserLookupValue && item.as(LookupItem.class) != null) {
|
||||
if (!((DeferredUserLookupValue)item.getObject()).handleUserSelection(item.as(LookupItem.class), context.project)) {
|
||||
if (!((DeferredUserLookupValue)item.getObject()).handleUserSelection(item.as(LookupItem.class), context.getProject())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -348,36 +370,37 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_CAMEL_HUMPS);
|
||||
}
|
||||
|
||||
insertLookupString(context, offset2, uniqueText);
|
||||
context.editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
insertLookupString(offset2, uniqueText, context.getEditor(), context.getOffsetMap());
|
||||
context.getEditor().getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
|
||||
lookupItemSelected(context, item, Lookup.AUTO_INSERT_SELECT_CHAR, Arrays.asList(items));
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
private static void insertLookupString(final CompletionContext context, final int currentOffset, final String newText) {
|
||||
Editor editor = context.editor;
|
||||
editor.getDocument().replaceString(context.getStartOffset(), currentOffset, newText);
|
||||
editor.getCaretModel().moveToOffset(context.getStartOffset() + newText.length());
|
||||
private static void insertLookupString(final int currentOffset, final String newText, final Editor editor, final OffsetMap offsetMap) {
|
||||
editor.getDocument().replaceString(offsetMap.getOffset(CompletionInitializationContext.START_OFFSET), currentOffset, newText);
|
||||
editor.getCaretModel().moveToOffset(offsetMap.getOffset(CompletionInitializationContext.START_OFFSET) + newText.length());
|
||||
editor.getSelectionModel().removeSelection();
|
||||
}
|
||||
|
||||
protected static void selectLookupItem(final LookupElement item, final char completionChar, final CompletionContext context, final List<LookupElement> items) {
|
||||
final int caretOffset = context.editor.getCaretModel().getOffset();
|
||||
protected static void selectLookupItem(final LookupElement item, final char completionChar, final CompletionProgressIndicator context, final List<LookupElement> items) {
|
||||
final int caretOffset = context.getEditor().getCaretModel().getOffset();
|
||||
|
||||
context.setSelectionEndOffset(caretOffset);
|
||||
final int idEnd = context.getOffsetMap().getOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET);
|
||||
context.getOffsetMap().addOffset(CompletionInitializationContext.SELECTION_END_OFFSET, caretOffset);
|
||||
final int idEnd = context.getIdentifierEndOffset();
|
||||
final int identifierEndOffset =
|
||||
CompletionUtil.isOverwrite(item, completionChar) && context.getSelectionEndOffset() == idEnd ?
|
||||
caretOffset :
|
||||
Math.max(caretOffset, idEnd);
|
||||
CompletionUtil.isOverwrite(item, completionChar) && context.getSelectionEndOffset() == idEnd ?
|
||||
caretOffset :
|
||||
Math.max(caretOffset, idEnd);
|
||||
context.getOffsetMap().addOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET, identifierEndOffset);
|
||||
lookupItemSelected(context, item, completionChar, items);
|
||||
}
|
||||
|
||||
private Pair<CompletionContext, PsiElement> insertDummyIdentifier(final CompletionContext context, final FileCopyPatcher patcher) {
|
||||
PsiFile oldFileCopy = createFileCopy(context.file);
|
||||
private Pair<CompletionContext, PsiElement> insertDummyIdentifier(final CompletionContext context,
|
||||
final FileCopyPatcher patcher,
|
||||
final PsiFile file, final Editor originalEditor) {
|
||||
PsiFile oldFileCopy = createFileCopy(file);
|
||||
PsiFile hostFile = InjectedLanguageUtil.getTopLevelFile(oldFileCopy);
|
||||
boolean wasInjected = hostFile != oldFileCopy;
|
||||
Project project = hostFile.getProject();
|
||||
@@ -402,7 +425,6 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
|
||||
if (oldFileCopy != fileCopy && !wasInjected) {
|
||||
// newly inserted identifier can well end up in the injected language region
|
||||
Editor oldEditor = context.editor;
|
||||
Editor editor = EditorFactory.getInstance().createEditor(document, project);
|
||||
Editor newEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, hostFile, context.getStartOffset());
|
||||
if (newEditor instanceof EditorWindow) {
|
||||
@@ -411,9 +433,9 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
final OffsetMap map = new OffsetMap(newEditor.getDocument());
|
||||
final OffsetMap oldMap = context.getOffsetMap();
|
||||
for (final OffsetKey key : oldMap.keySet()) {
|
||||
map.addOffset(key, injectedEditor.logicalPositionToOffset(injectedEditor.hostToInjected(oldEditor.offsetToLogicalPosition(oldMap.getOffset(key)))));
|
||||
map.addOffset(key, injectedEditor.logicalPositionToOffset(injectedEditor.hostToInjected(originalEditor.offsetToLogicalPosition(oldMap.getOffset(key)))));
|
||||
}
|
||||
CompletionContext newContext = new CompletionContext(context.project, injectedEditor, injectedFile, map);
|
||||
CompletionContext newContext = new CompletionContext(file.getProject(), injectedEditor, injectedFile, map);
|
||||
int injectedOffset = newContext.getStartOffset();
|
||||
PsiElement element = findElementAt(injectedFile, injectedOffset);
|
||||
|
||||
@@ -480,21 +502,21 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private static void lookupItemSelected(final CompletionContext context, @NotNull final LookupElement item, final char completionChar,
|
||||
private static void lookupItemSelected(final CompletionProgressIndicator context, @NotNull final LookupElement item, final char completionChar,
|
||||
final List<LookupElement> items) {
|
||||
final Editor editor = context.editor;
|
||||
final PsiFile file = context.file;
|
||||
final Editor editor = context.getEditor();
|
||||
final PsiFile file = context.getParameters().getOriginalFile();
|
||||
final InsertionContext context1 = new InsertionContext(context.getOffsetMap(), completionChar, items.toArray(new LookupElement[items.size()]), file, editor);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final int idEndOffset = context.getOffsetMap().getOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET);
|
||||
final int idEndOffset = context.getIdentifierEndOffset();
|
||||
if (idEndOffset != context.getSelectionEndOffset() && CompletionUtil.isOverwrite(item, completionChar)) {
|
||||
editor.getDocument().deleteString(context.getSelectionEndOffset(), idEndOffset);
|
||||
}
|
||||
|
||||
PsiDocumentManager.getInstance(context.project).commitAllDocuments();
|
||||
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments();
|
||||
item.handleInsert(context1);
|
||||
PostprocessReformattingAspect.getInstance(context.project).doPostponedFormatting();
|
||||
PostprocessReformattingAspect.getInstance(context.getProject()).doPostponedFormatting();
|
||||
|
||||
if (context1.shouldAddCompletionChar() &&
|
||||
completionChar != Lookup.AUTO_INSERT_SELECT_CHAR && completionChar != Lookup.REPLACE_SELECT_CHAR &&
|
||||
@@ -592,7 +614,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
case SMART:
|
||||
return settings.AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION;
|
||||
case BASIC:
|
||||
default:
|
||||
default:
|
||||
return settings.AUTOCOMPLETE_ON_CODE_COMPLETION;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,16 +44,12 @@ public class CompletionContext {
|
||||
getOffsetMap().addOffset(CompletionInitializationContext.START_OFFSET, newStartOffset);
|
||||
}
|
||||
|
||||
public int getSelectionEndOffset() {
|
||||
return getOffsetMap().getOffset(CompletionInitializationContext.SELECTION_END_OFFSET);
|
||||
}
|
||||
|
||||
public void setSelectionEndOffset(final int selectionEndOffset) {
|
||||
getOffsetMap().addOffset(CompletionInitializationContext.SELECTION_END_OFFSET, selectionEndOffset);
|
||||
}
|
||||
|
||||
public OffsetMap getOffsetMap() {
|
||||
return myOffsetMap;
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return project;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+30
-13
@@ -35,6 +35,7 @@ import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.editor.event.*;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.util.ProgressIndicatorBase;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -76,7 +77,6 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
}
|
||||
};
|
||||
private LightweightHint myHint;
|
||||
private final CompletionContext myContextOriginal;
|
||||
private final Semaphore myFreezeSemaphore;
|
||||
|
||||
private boolean myModifiersReleased;
|
||||
@@ -86,14 +86,15 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
private int myOldStart;
|
||||
private int myOldEnd;
|
||||
private boolean myBackgrounded = true;
|
||||
private OffsetMap myOffsetMap;
|
||||
|
||||
public CompletionProgressIndicator(final Editor editor, CompletionParameters parameters, CodeCompletionHandlerBase handler,
|
||||
final CompletionContext contextOriginal, Semaphore freezeSemaphore) {
|
||||
public CompletionProgressIndicator(final Editor editor, CompletionParameters parameters, CodeCompletionHandlerBase handler, Semaphore freezeSemaphore,
|
||||
final OffsetMap offsetMap) {
|
||||
myEditor = editor;
|
||||
myParameters = parameters;
|
||||
myHandler = handler;
|
||||
myContextOriginal = contextOriginal;
|
||||
myFreezeSemaphore = freezeSemaphore;
|
||||
myOffsetMap = offsetMap;
|
||||
|
||||
myLookup = (LookupImpl)LookupManager.getInstance(editor.getProject()).createLookup(editor, LookupElement.EMPTY_ARRAY, "", new CompletionLookupArranger(parameters));
|
||||
if (editor.isOneLineMode()) {
|
||||
@@ -114,8 +115,8 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
|
||||
setMergeCommand();
|
||||
|
||||
contextOriginal.setStartOffset(myEditor.getCaretModel().getOffset() - item.getLookupString().length());
|
||||
CodeCompletionHandlerBase.selectLookupItem(item, event.getCompletionChar(), contextOriginal, myLookup.getItems());
|
||||
myOffsetMap.addOffset(CompletionInitializationContext.START_OFFSET, myEditor.getCaretModel().getOffset() - item.getLookupString().length());
|
||||
CodeCompletionHandlerBase.selectLookupItem(item, event.getCompletionChar(), CompletionProgressIndicator.this, myLookup.getItems());
|
||||
}
|
||||
|
||||
|
||||
@@ -137,6 +138,14 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
trackModifiers();
|
||||
}
|
||||
|
||||
public OffsetMap getOffsetMap() {
|
||||
return myOffsetMap;
|
||||
}
|
||||
|
||||
public int getSelectionEndOffset() {
|
||||
return getOffsetMap().getOffset(CompletionInitializationContext.SELECTION_END_OFFSET);
|
||||
}
|
||||
|
||||
void notifyBackgrounded() {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
myBackgrounded = true;
|
||||
@@ -315,8 +324,12 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
return myCount;
|
||||
}
|
||||
|
||||
private boolean isInsideIdentifier() {
|
||||
return myContextOriginal.getOffsetMap().getOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET) != myContextOriginal.getSelectionEndOffset();
|
||||
final boolean isInsideIdentifier() {
|
||||
return getIdentifierEndOffset() != getSelectionEndOffset();
|
||||
}
|
||||
|
||||
public int getIdentifierEndOffset() {
|
||||
return myOffsetMap.getOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET);
|
||||
}
|
||||
|
||||
|
||||
@@ -353,7 +366,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
if (myHint != null) {
|
||||
myHint.hide();
|
||||
}
|
||||
LookupManager.getInstance(myEditor.getProject()).hideActiveLookup();
|
||||
LookupManager.getInstance(getProject()).hideActiveLookup();
|
||||
}
|
||||
|
||||
private void lookupClosed() {
|
||||
@@ -413,11 +426,11 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
}
|
||||
|
||||
if (myCount == 0) {
|
||||
LookupManager.getInstance(myContextOriginal.project).hideActiveLookup();
|
||||
LookupManager.getInstance(getProject()).hideActiveLookup();
|
||||
assert CompletionServiceImpl.getCompletionService().getCurrentCompletion() == null;
|
||||
|
||||
if (!isAutopopupCompletion() ) {
|
||||
myHandler.handleEmptyLookup(myContextOriginal.project, myEditor, myParameters, CompletionProgressIndicator.this);
|
||||
myHandler.handleEmptyLookup(getProject(), myEditor, myParameters, CompletionProgressIndicator.this);
|
||||
}
|
||||
} else {
|
||||
updateLookup();
|
||||
@@ -433,7 +446,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
lookup.refreshUi();
|
||||
final List<LookupElement> items = lookup.getItems();
|
||||
if (items.size() == 0 || items.size() == 1 && (items.get(0).getPrefixMatcher().getPrefix() + lookup.getAdditionalPrefix()).equals(items.get(0).getLookupString())) {
|
||||
lookup.hide();
|
||||
lookup.hideLookup(false);
|
||||
assert CompletionServiceImpl.getCompletionService().getCurrentCompletion() == null;
|
||||
return true;
|
||||
}
|
||||
@@ -489,7 +502,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
return false;
|
||||
}
|
||||
|
||||
final Boolean aBoolean = new WriteCommandAction<Boolean>(myEditor.getProject()) {
|
||||
final Boolean aBoolean = new WriteCommandAction<Boolean>(getProject()) {
|
||||
protected void run(Result<Boolean> result) throws Throwable {
|
||||
if (!explicit) {
|
||||
setMergeCommand();
|
||||
@@ -546,4 +559,8 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
public boolean isAutopopupCompletion() {
|
||||
return !myLookup.isFocused();
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return myEditor.getProject();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +188,6 @@ class DaemonListeners implements Disposable {
|
||||
});
|
||||
|
||||
connection.subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() {
|
||||
|
||||
public void enteredDumbMode() {
|
||||
stopDaemon(true);
|
||||
}
|
||||
@@ -312,7 +311,7 @@ class DaemonListeners implements Disposable {
|
||||
if (vcsIsThinking) return Result.UNCHANGED; // do not modify file which is in the process of updating
|
||||
|
||||
FileStatus status = FileStatusManager.getInstance(project).getStatus(virtualFile);
|
||||
|
||||
if (status == FileStatus.UNKNOWN) return Result.NOT_SURE;
|
||||
return status == FileStatus.MODIFIED || status == FileStatus.ADDED ? Result.CHANGED : Result.UNCHANGED;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -111,8 +111,8 @@ public class DaemonTooltipRendererProvider implements ErrorStripTooltipRendererP
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrafficTooltipRenderer createTrafficTooltipRenderer(Runnable onHide) {
|
||||
return new TrafficTooltipRendererImpl(onHide);
|
||||
public TrafficTooltipRenderer createTrafficTooltipRenderer(Runnable onHide, Editor editor) {
|
||||
return new TrafficTooltipRendererImpl(onHide, editor);
|
||||
}
|
||||
|
||||
private static class MyRenderer extends LineTooltipRenderer {
|
||||
|
||||
+104
-23
@@ -21,17 +21,20 @@ import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.VerticalFlowLayout;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.ui.HintHint;
|
||||
import com.intellij.uiDesigner.core.GridConstraints;
|
||||
import com.intellij.uiDesigner.core.GridLayoutManager;
|
||||
import com.intellij.ui.components.panels.NonOpaquePanel;
|
||||
import com.intellij.ui.components.panels.VerticalBox;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.containers.hash.LinkedHashMap;
|
||||
import com.intellij.util.ui.AwtVisitor;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.LineBorder;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -39,18 +42,34 @@ import java.util.Map;
|
||||
* User: cdr
|
||||
*/
|
||||
public class TrafficProgressPanel extends JPanel {
|
||||
|
||||
private static final int MAX = 100;
|
||||
private static final String MAX_TEXT = "100%";
|
||||
private static final String MIN_TEXT = "0%";
|
||||
|
||||
private final JLabel statistics = new JLabel();
|
||||
private final Map<ProgressableTextEditorHighlightingPass, Pair<JProgressBar, JLabel>> passes = new LinkedHashMap<ProgressableTextEditorHighlightingPass, Pair<JProgressBar, JLabel>>();
|
||||
private Map<JProgressBar, JLabel> myProgressToText = new HashMap<JProgressBar, JLabel>();
|
||||
|
||||
private final JLabel statusLabel = new JLabel();
|
||||
private final TrafficLightRenderer myTrafficLightRenderer;
|
||||
private final JPanel passStatuses = new JPanel();
|
||||
private HintHint myHintHint;
|
||||
|
||||
public TrafficProgressPanel(TrafficLightRenderer trafficLightRenderer, Editor editor, HintHint hintHint) {
|
||||
super(new VerticalFlowLayout());
|
||||
myHintHint = hintHint;
|
||||
myTrafficLightRenderer = trafficLightRenderer;
|
||||
|
||||
|
||||
add(statusLabel);
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
VerticalBox center = new VerticalBox();
|
||||
add(center, BorderLayout.NORTH);
|
||||
|
||||
center.add(statusLabel);
|
||||
center.add(new Separator());
|
||||
center.add(Box.createVerticalStrut(6));
|
||||
|
||||
TrafficLightRenderer.DaemonCodeAnalyzerStatus fakeStatusLargeEnough = new TrafficLightRenderer.DaemonCodeAnalyzerStatus();
|
||||
fakeStatusLargeEnough.errorCount = new int[]{1,1,1,1};
|
||||
Project project = trafficLightRenderer.getProject();
|
||||
@@ -70,63 +89,103 @@ public class TrafficProgressPanel extends JPanel {
|
||||
rebuildPassesPanel(fakeStatusLargeEnough);
|
||||
for (Pair<JProgressBar, JLabel> pair : passes.values()) {
|
||||
JProgressBar bar = pair.first;
|
||||
bar.setMaximum(100);
|
||||
bar.setMaximum(MAX);
|
||||
JLabel label = pair.second;
|
||||
label.setText("100%");
|
||||
label.setText(MAX_TEXT);
|
||||
}
|
||||
add(passStatuses);
|
||||
center.add(passStatuses);
|
||||
|
||||
add(statistics);
|
||||
add(statistics, BorderLayout.SOUTH);
|
||||
updatePanel(fakeStatusLargeEnough);
|
||||
|
||||
hintHint.initStyle(this, true);
|
||||
}
|
||||
|
||||
private class Separator extends NonOpaquePanel {
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
Insets insets = getInsets();
|
||||
if (insets == null) {
|
||||
insets = new Insets(0, 0, 0, 0);
|
||||
}
|
||||
g.setColor(myHintHint.getTextForeground());
|
||||
g.drawLine(insets.left, insets.top, getWidth() - insets.left - insets.right, insets.top);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getMinimumSize() {
|
||||
return new Dimension(1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void rebuildPassesPanel(TrafficLightRenderer.DaemonCodeAnalyzerStatus status) {
|
||||
passStatuses.removeAll();
|
||||
passStatuses.setLayout(new GridLayoutManager(Math.max(status.passStati.size(),1), 3));
|
||||
passStatuses.setLayout(new GridBagLayout());
|
||||
passes.clear();
|
||||
GridConstraints constraints = new GridConstraints();
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.gridy = 0;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
for (ProgressableTextEditorHighlightingPass pass : status.passStati) {
|
||||
JLabel label = new JLabel(pass.getPresentableName() + ":");
|
||||
JProgressBar progressBar = new JProgressBar(0,100);
|
||||
JLabel label = new JLabel(pass.getPresentableName() + ": ");
|
||||
label.setHorizontalTextPosition(JLabel.RIGHT);
|
||||
|
||||
JProgressBar progressBar = new JProgressBar(0, MAX);
|
||||
progressBar.putClientProperty("JComponent.sizeVariant", "mini");
|
||||
JLabel percLabel = new JLabel();
|
||||
passes.put(pass, Pair.create(progressBar, percLabel));
|
||||
constraints.setColumn(0); passStatuses.add(label, constraints);
|
||||
constraints.setColumn(1); passStatuses.add(progressBar, constraints);
|
||||
constraints.setColumn(2); passStatuses.add(percLabel, constraints);
|
||||
constraints.setRow(constraints.getRow()+1);
|
||||
myProgressToText.put(progressBar, percLabel);
|
||||
c.gridx = 0;
|
||||
passStatuses.add(label, c);
|
||||
c.gridx = 1;
|
||||
passStatuses.add(progressBar, c);
|
||||
c.gridx = 2;
|
||||
c.weightx = 1;
|
||||
passStatuses.add(percLabel, c);
|
||||
|
||||
c.gridy++;
|
||||
}
|
||||
|
||||
myHintHint.initStyle(passStatuses, true);
|
||||
statusLabel.setFont(statusLabel.getFont().deriveFont(Font.BOLD));
|
||||
}
|
||||
|
||||
public void updatePanel(TrafficLightRenderer.DaemonCodeAnalyzerStatus status) {
|
||||
if (status == null) return;
|
||||
if (PowerSaveMode.isEnabled()) {
|
||||
statusLabel.setText("Code analysis is disabled in power save mode.");
|
||||
statusLabel.setText("Code analysis is disabled in power save mode");
|
||||
passStatuses.setVisible(false);
|
||||
statistics.setText("");
|
||||
return;
|
||||
}
|
||||
if (!status.enabled) {
|
||||
statusLabel.setText("Code analysis has been suspended.");
|
||||
passStatuses.setVisible(false);
|
||||
statusLabel.setText("Code analysis has been suspended");
|
||||
passStatuses.setVisible(true);
|
||||
setPassesEnabled(false, Boolean.FALSE);
|
||||
statistics.setText("");
|
||||
return;
|
||||
}
|
||||
if (status.noHighlightingRoots != null && status.noHighlightingRoots.length == status.rootsNumber) {
|
||||
statusLabel.setText(DaemonBundle.message("analysis.hasnot.been.run"));
|
||||
passStatuses.setVisible(false);
|
||||
passStatuses.setVisible(true);
|
||||
setPassesEnabled(false, Boolean.FALSE);
|
||||
statistics.setText("");
|
||||
return;
|
||||
}
|
||||
|
||||
if (status.errorAnalyzingFinished) {
|
||||
statusLabel.setText(DaemonBundle.message("analysis.completed"));
|
||||
passStatuses.setVisible(false);
|
||||
passStatuses.setVisible(true);
|
||||
setPassesEnabled(false, Boolean.TRUE);
|
||||
}
|
||||
else {
|
||||
statusLabel.setText(DaemonBundle.message("performing.code.analysis"));
|
||||
passStatuses.setVisible(true);
|
||||
setPassesEnabled(true, null);
|
||||
|
||||
if (!status.passStati.equals(new ArrayList<ProgressableTextEditorHighlightingPass>(passes.keySet()))) {
|
||||
// passes set has changed
|
||||
@@ -137,7 +196,7 @@ public class TrafficProgressPanel extends JPanel {
|
||||
double progress = pass.getProgress();
|
||||
Pair<JProgressBar, JLabel> pair = passes.get(pass);
|
||||
JProgressBar progressBar = pair.first;
|
||||
int percent = (int)Math.round(progress * 100);
|
||||
int percent = (int)Math.round(progress * MAX);
|
||||
progressBar.setValue(percent);
|
||||
JLabel percentage = pair.second;
|
||||
percentage.setText(percent + "%");
|
||||
@@ -164,4 +223,26 @@ public class TrafficProgressPanel extends JPanel {
|
||||
}
|
||||
statistics.setText(text);
|
||||
}
|
||||
|
||||
private void setPassesEnabled(final boolean enabled, final Boolean completed) {
|
||||
new AwtVisitor(passStatuses) {
|
||||
@Override
|
||||
public boolean visit(Component component) {
|
||||
if (component instanceof JProgressBar) {
|
||||
JProgressBar progress = (JProgressBar)component;
|
||||
progress.setEnabled(enabled);
|
||||
if (completed != null) {
|
||||
if (completed) {
|
||||
progress.setValue(MAX);
|
||||
myProgressToText.get(progress).setText(MAX_TEXT);
|
||||
} else {
|
||||
progress.setValue(0);
|
||||
myProgressToText.get(progress).setText(MIN_TEXT);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+4
-7
@@ -24,18 +24,20 @@ import com.intellij.openapi.editor.impl.EditorMarkupModelImpl;
|
||||
import com.intellij.openapi.editor.impl.TrafficTooltipRenderer;
|
||||
import com.intellij.ui.HintHint;
|
||||
import com.intellij.ui.LightweightHint;
|
||||
import com.intellij.util.ui.update.ComparableObject;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* User: cdr
|
||||
*/
|
||||
public class TrafficTooltipRendererImpl implements TrafficTooltipRenderer {
|
||||
public class TrafficTooltipRendererImpl extends ComparableObject.Impl implements TrafficTooltipRenderer {
|
||||
private TrafficProgressPanel myPanel;
|
||||
private final Runnable onHide;
|
||||
private TrafficLightRenderer myTrafficLightRenderer;
|
||||
|
||||
public TrafficTooltipRendererImpl(Runnable onHide) {
|
||||
public TrafficTooltipRendererImpl(Runnable onHide, Editor editor) {
|
||||
super(editor);
|
||||
this.onHide = onHide;
|
||||
}
|
||||
|
||||
@@ -69,9 +71,4 @@ public class TrafficTooltipRendererImpl implements TrafficTooltipRenderer {
|
||||
repaintTooltipWindow();
|
||||
return hint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj.getClass() == getClass() && myTrafficLightRenderer == ((TrafficTooltipRendererImpl)obj).myTrafficLightRenderer;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -111,11 +111,11 @@ public class DefaultHighlightVisitor implements HighlightVisitor, DumbAware {
|
||||
|
||||
static {
|
||||
LanguageAnnotators.INSTANCE.addListener(new ExtensionPointListener<Annotator>() {
|
||||
public void extensionAdded(Annotator extension, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
public void extensionAdded(@NotNull Annotator extension, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
cachedAnnotators.clear();
|
||||
}
|
||||
|
||||
public void extensionRemoved(Annotator extension, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
public void extensionRemoved(@NotNull Annotator extension, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
cachedAnnotators.clear();
|
||||
}
|
||||
});
|
||||
|
||||
+59
-29
@@ -25,6 +25,7 @@ import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupAdapter;
|
||||
import com.intellij.codeInsight.lookup.LookupEvent;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.event.DocumentAdapter;
|
||||
import com.intellij.openapi.editor.event.DocumentEvent;
|
||||
@@ -35,6 +36,8 @@ import com.intellij.openapi.fileEditor.FileEditorManagerAdapter;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
@@ -44,7 +47,11 @@ import com.intellij.util.messages.MessageBusConnection;
|
||||
*/
|
||||
public class CompletionAutoPopupHandler extends TypedHandlerDelegate {
|
||||
private Editor myEditor;
|
||||
private int myLastOffset;
|
||||
|
||||
//todo store this in some less nasty place
|
||||
public static int ourLastOffset;
|
||||
|
||||
private static final Key<Object> COMPLETION_AUTO_POPUP_HANDLER = Key.create("CompletionAutoPopupHandler");
|
||||
|
||||
@Override
|
||||
public Result checkAutoPopup(char charTyped, final Project project, final Editor editor, final PsiFile file) {
|
||||
@@ -56,10 +63,13 @@ public class CompletionAutoPopupHandler extends TypedHandlerDelegate {
|
||||
}
|
||||
|
||||
if (myEditor != null) {
|
||||
if (editor != myEditor || editor.getCaretModel().getOffset() != myLastOffset + 1) {
|
||||
if (editor != myEditor || editor.getCaretModel().getOffset() != ourLastOffset + 1) {
|
||||
finishAutopopupCompletion();
|
||||
return Result.CONTINUE;
|
||||
} else {
|
||||
//noinspection AssignmentToStaticFieldFromInstanceMethod
|
||||
ourLastOffset = editor.getCaretModel().getOffset();
|
||||
}
|
||||
return Result.CONTINUE;
|
||||
} else {
|
||||
if (LookupManager.getActiveLookup(editor) != null) {
|
||||
return Result.CONTINUE;
|
||||
@@ -67,8 +77,43 @@ public class CompletionAutoPopupHandler extends TypedHandlerDelegate {
|
||||
}
|
||||
|
||||
myEditor = editor;
|
||||
myLastOffset = editor.getCaretModel().getOffset();
|
||||
//noinspection AssignmentToStaticFieldFromInstanceMethod
|
||||
ourLastOffset = editor.getCaretModel().getOffset();
|
||||
|
||||
trackProjectClosing(project);
|
||||
trackUserActivity(project, editor);
|
||||
|
||||
final boolean isMainEditor = FileEditorManager.getInstance(project).getSelectedTextEditor() == editor;
|
||||
|
||||
AutoPopupController.getInstance(project).invokeAutoPopupRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (project.isDisposed() || !file.isValid()) return;
|
||||
if (editor.isDisposed() || isMainEditor && FileEditorManager.getInstance(project).getSelectedTextEditor() != editor) return;
|
||||
|
||||
new CodeCompletionHandlerBase(CompletionType.BASIC, false, false).invoke(project, editor);
|
||||
final Lookup lookup = LookupManager.getActiveLookup(editor);
|
||||
if (lookup != null) {
|
||||
lookup.addLookupListener(new LookupAdapter() {
|
||||
@Override
|
||||
public void itemSelected(LookupEvent event) {
|
||||
myEditor = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lookupCanceled(LookupEvent event) {
|
||||
if (event.isCanceledExplicitly()) {
|
||||
myEditor = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}, CodeInsightSettings.getInstance().AUTO_LOOKUP_DELAY);
|
||||
return Result.STOP;
|
||||
}
|
||||
|
||||
private void trackUserActivity(Project project, final Editor editor) {
|
||||
final MessageBusConnection connection = project.getMessageBus().connect();
|
||||
connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() {
|
||||
@Override
|
||||
@@ -95,33 +140,18 @@ public class CompletionAutoPopupHandler extends TypedHandlerDelegate {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final boolean isMainEditor = FileEditorManager.getInstance(project).getSelectedTextEditor() == editor;
|
||||
|
||||
AutoPopupController.getInstance(project).invokeAutoPopupRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (project.isDisposed() || !file.isValid()) return;
|
||||
if (editor.isDisposed() || isMainEditor && FileEditorManager.getInstance(project).getSelectedTextEditor() != editor) return;
|
||||
|
||||
new CodeCompletionHandlerBase(CompletionType.BASIC, false, false).invoke(project, editor);
|
||||
final Lookup lookup = LookupManager.getActiveLookup(editor);
|
||||
if (lookup != null) {
|
||||
lookup.addLookupListener(new LookupAdapter() {
|
||||
@Override
|
||||
public void itemSelected(LookupEvent event) {
|
||||
myEditor = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lookupCanceled(LookupEvent event) {
|
||||
myEditor = null;
|
||||
}
|
||||
});
|
||||
private void trackProjectClosing(Project project) {
|
||||
if (project.getUserData(COMPLETION_AUTO_POPUP_HANDLER) == null) {
|
||||
project.putUserData(COMPLETION_AUTO_POPUP_HANDLER, new Object());
|
||||
Disposer.register(project, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
myEditor = null;
|
||||
}
|
||||
}
|
||||
}, CodeInsightSettings.getInstance().AUTO_LOOKUP_DELAY);
|
||||
return Result.STOP;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void finishAutopopupCompletion() {
|
||||
|
||||
+4
@@ -1,5 +1,6 @@
|
||||
package com.intellij.codeInsight.editorActions;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeStyle.CodeStyleFacade;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
@@ -115,6 +116,9 @@ public class CopyPasteIndentProcessor implements CopyPastePostProcessor<IndentTr
|
||||
final int caretColumn,
|
||||
final Ref<Boolean> indented,
|
||||
final IndentTransferableData value) {
|
||||
if (!CodeInsightSettings.getInstance().INDENT_TO_CARET_ON_PASTE) {
|
||||
return;
|
||||
}
|
||||
final Document document = editor.getDocument();
|
||||
final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
|
||||
if (psiFile == null || !acceptFileType(psiFile.getFileType())) {
|
||||
|
||||
+2
-2
@@ -64,11 +64,11 @@ public class IntentionManagerImpl extends IntentionManager {
|
||||
final ExtensionPoint<IntentionActionBean> point = Extensions.getArea(null).getExtensionPoint(EP_INTENTION_ACTIONS);
|
||||
|
||||
point.addExtensionPointListener(new ExtensionPointListener<IntentionActionBean>() {
|
||||
public void extensionAdded(final IntentionActionBean extension, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
public void extensionAdded(@NotNull final IntentionActionBean extension, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
registerIntentionFromBean(extension);
|
||||
}
|
||||
|
||||
public void extensionRemoved(final IntentionActionBean extension, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
public void extensionRemoved(@NotNull final IntentionActionBean extension, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ public abstract class IntentionSettingsTree {
|
||||
SimpleTextAttributes attributes = node.getUserObject() instanceof IntentionActionMetaData ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES;
|
||||
final String text = getNodeText(node);
|
||||
final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
|
||||
setBackground(background);
|
||||
UIUtil.changeBackGround(this, background);
|
||||
if (text != null) {
|
||||
SearchUtil.appendFragments(myFilter != null ? myFilter.getFilter() : null,
|
||||
text,
|
||||
|
||||
@@ -25,16 +25,22 @@ public class LookupEvent extends EventObject {
|
||||
private final Lookup myLookup;
|
||||
private final LookupElement myItem;
|
||||
private final char myCompletionChar;
|
||||
private final boolean myCanceledExplicitly;
|
||||
|
||||
public LookupEvent(Lookup lookup, LookupElement item){
|
||||
this(lookup, item, (char)0);
|
||||
public LookupEvent(Lookup lookup, boolean canceledExplicitly){
|
||||
super(lookup);
|
||||
myLookup = lookup;
|
||||
myItem = null;
|
||||
myCompletionChar = 0;
|
||||
myCanceledExplicitly = canceledExplicitly;
|
||||
}
|
||||
|
||||
public LookupEvent(Lookup lookup, LookupElement item, char completionChar){
|
||||
public LookupEvent(Lookup lookup, LookupElement item, char completionChar) {
|
||||
super(lookup);
|
||||
myLookup = lookup;
|
||||
myItem = item;
|
||||
myCompletionChar = completionChar;
|
||||
myCanceledExplicitly = false;
|
||||
}
|
||||
|
||||
public Lookup getLookup(){
|
||||
@@ -49,4 +55,8 @@ public class LookupEvent extends EventObject {
|
||||
public char getCompletionChar(){
|
||||
return myCompletionChar;
|
||||
}
|
||||
|
||||
public boolean isCanceledExplicitly() {
|
||||
return myCanceledExplicitly;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.event.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
@@ -497,7 +496,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
|
||||
}
|
||||
|
||||
final LookupElement item = (LookupElement)myList.getSelectedValue();
|
||||
doHide(false);
|
||||
doHide(false, true);
|
||||
if (item == null ||
|
||||
item instanceof EmptyLookupItem ||
|
||||
item.getObject() instanceof DeferredUserLookupValue &&
|
||||
@@ -736,9 +735,9 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
private void fireLookupCanceled(){
|
||||
private void fireLookupCanceled(final boolean explicitly) {
|
||||
if (!myListeners.isEmpty()){
|
||||
LookupEvent event = new LookupEvent(this, null);
|
||||
LookupEvent event = new LookupEvent(this, explicitly);
|
||||
LookupListener[] listeners = myListeners.toArray(new LookupListener[myListeners.size()]);
|
||||
for (LookupListener listener : listeners) {
|
||||
try {
|
||||
@@ -753,7 +752,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
|
||||
|
||||
private void fireCurrentItemChanged(LookupElement item){
|
||||
if (!myListeners.isEmpty()){
|
||||
LookupEvent event = new LookupEvent(this, item);
|
||||
LookupEvent event = new LookupEvent(this, item, (char)0);
|
||||
LookupListener[] listeners = myListeners.toArray(new LookupListener[myListeners.size()]);
|
||||
for (LookupListener listener : listeners) {
|
||||
listener.currentItemChanged(event);
|
||||
@@ -895,16 +894,18 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
|
||||
}
|
||||
|
||||
public void hide(){
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
hideLookup(true);
|
||||
}
|
||||
|
||||
//if (IdeEventQueue.getInstance().getPopupManager().closeAllPopups()) return;
|
||||
public void hideLookup(boolean explicitly) {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
|
||||
if (myDisposed) return;
|
||||
|
||||
doHide(true);
|
||||
doHide(true, explicitly);
|
||||
}
|
||||
|
||||
private void doHide(final boolean fireCanceled) {
|
||||
private void doHide(final boolean fireCanceled, final boolean explicitly) {
|
||||
assert !myDisposed;
|
||||
myHidden = true;
|
||||
|
||||
@@ -913,7 +914,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
|
||||
Disposer.dispose(this);
|
||||
|
||||
if (fireCanceled) {
|
||||
fireLookupCanceled();
|
||||
fireLookupCanceled(explicitly);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.completion.CodeCompletionFeatures;
|
||||
import com.intellij.codeInsight.completion.CompletionProgressIndicator;
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher;
|
||||
import com.intellij.codeInsight.editorActions.AutoHardWrapHandler;
|
||||
import com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler;
|
||||
import com.intellij.codeInsight.lookup.CharFilter;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
@@ -67,6 +68,8 @@ public class TypedHandler implements TypedActionHandler {
|
||||
}, "", editor.getDocument());
|
||||
|
||||
if (result == CharFilter.Result.ADD_TO_PREFIX){
|
||||
//noinspection AssignmentToStaticFieldFromInstanceMethod
|
||||
CompletionAutoPopupHandler.ourLastOffset = editor.getCaretModel().getOffset() - 1;
|
||||
CompletionProgressIndicator.hideAutopopupIfMeaningless(lookup);
|
||||
return;
|
||||
}
|
||||
|
||||
+7
-8
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.template;
|
||||
|
||||
import com.intellij.codeInsight.template.impl.TemplateContext;
|
||||
import com.intellij.codeInsight.template.impl.TemplateImpl;
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
|
||||
import com.intellij.codeInsight.template.impl.TemplateSettings;
|
||||
@@ -76,31 +75,31 @@ public class CustomTemplateCallback {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TemplateImpl findApplicableTemplate(@NotNull String key, TemplateContextType... contextTypes) {
|
||||
List<TemplateImpl> templates = findApplicableTemplates(key, contextTypes);
|
||||
public TemplateImpl findApplicableTemplate(@NotNull String key) {
|
||||
List<TemplateImpl> templates = findApplicableTemplates(key);
|
||||
return templates.size() > 0 ? templates.get(0) : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<TemplateImpl> findApplicableTemplates(String key, TemplateContextType... contextTypes) {
|
||||
public List<TemplateImpl> findApplicableTemplates(String key) {
|
||||
List<TemplateImpl> templates = getMatchingTemplates(key);
|
||||
templates = filterApplicableCandidates(templates, contextTypes);
|
||||
templates = filterApplicableCandidates(templates);
|
||||
return templates;
|
||||
}
|
||||
|
||||
private List<TemplateImpl> filterApplicableCandidates(Collection<TemplateImpl> candidates, TemplateContextType... contextTypes) {
|
||||
private List<TemplateImpl> filterApplicableCandidates(Collection<TemplateImpl> candidates) {
|
||||
List<TemplateImpl> result = new ArrayList<TemplateImpl>();
|
||||
for (TemplateImpl candidate : candidates) {
|
||||
if (TemplateManagerImpl.isApplicable(myFile, myOffset > 0 ? myOffset - 1 : myOffset, candidate)) {
|
||||
result.add(candidate);
|
||||
}
|
||||
TemplateContext context = candidate.getTemplateContext();
|
||||
/*TemplateContext context = candidate.getTemplateContext();
|
||||
for (TemplateContextType contextType : contextTypes) {
|
||||
if (context.isEnabled(contextType)) {
|
||||
result.add(candidate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+1
-1
@@ -631,7 +631,7 @@ class TemplateListPanel extends JPanel {
|
||||
// Fix GTK backround
|
||||
if (UIUtil.isUnderGTKLookAndFeel()){
|
||||
final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
|
||||
setBackground(background);
|
||||
UIUtil.changeBackGround(this, background);
|
||||
}
|
||||
|
||||
if (value instanceof TemplateImpl) {
|
||||
|
||||
+10
-7
@@ -18,6 +18,7 @@ package com.intellij.execution.actions;
|
||||
|
||||
import com.intellij.execution.*;
|
||||
import com.intellij.execution.configurations.ConfigurationType;
|
||||
import com.intellij.execution.configurations.UnknownConfigurationType;
|
||||
import com.intellij.execution.executors.DefaultRunExecutor;
|
||||
import com.intellij.execution.impl.EditConfigurationsDialog;
|
||||
import com.intellij.execution.impl.RunDialog;
|
||||
@@ -452,14 +453,16 @@ public class ChooseRunConfigurationAction extends AnAction {
|
||||
final Map<RunnerAndConfigurationSettings, ItemWrapper> wrappedExisting = new LinkedHashMap<RunnerAndConfigurationSettings, ItemWrapper>();
|
||||
final ConfigurationType[] factories = manager.getConfigurationFactories();
|
||||
for (final ConfigurationType factory : factories) {
|
||||
final RunnerAndConfigurationSettings[] configurations = manager.getConfigurationSettings(factory);
|
||||
for (final RunnerAndConfigurationSettings configuration : configurations) {
|
||||
final ItemWrapper wrapped = ItemWrapper.wrap(project, configuration);
|
||||
if (configuration == selectedConfiguration) {
|
||||
wrapped.setMnemonic(1);
|
||||
}
|
||||
if (!(factory instanceof UnknownConfigurationType)) {
|
||||
final RunnerAndConfigurationSettings[] configurations = manager.getConfigurationSettings(factory);
|
||||
for (final RunnerAndConfigurationSettings configuration : configurations) {
|
||||
final ItemWrapper wrapped = ItemWrapper.wrap(project, configuration);
|
||||
if (configuration == selectedConfiguration) {
|
||||
wrapped.setMnemonic(1);
|
||||
}
|
||||
|
||||
wrappedExisting.put(configuration, wrapped);
|
||||
wrappedExisting.put(configuration, wrapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -314,7 +314,7 @@ public abstract class BaseExecuteBeforeRunDialog<T extends BeforeRunTask> extend
|
||||
|
||||
myCheckbox.setBackground(UIUtil.getTreeTextBackground());
|
||||
setBackground(selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground());
|
||||
Color foreground = selected ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeTextForeground();
|
||||
final Color foreground = selected ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeTextForeground();
|
||||
setForeground(foreground);
|
||||
myCheckbox.setForeground(foreground);
|
||||
myLabel.setForeground(foreground);
|
||||
|
||||
@@ -1385,6 +1385,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
|
||||
return next(1, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private OccurenceInfo next(final int delta, boolean doMove) {
|
||||
List<RangeHighlighter> ranges = new ArrayList<RangeHighlighter>(myHyperlinks.getRanges().keySet());
|
||||
for (Iterator<RangeHighlighter> iterator = ranges.iterator(); iterator.hasNext();) {
|
||||
@@ -1412,7 +1413,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
|
||||
scrollTo(next.getStartOffset());
|
||||
}
|
||||
final HyperlinkInfo hyperlinkInfo = myHyperlinks.getRanges().get(next);
|
||||
return new OccurenceInfo(new Navigatable.Adapter() {
|
||||
return hyperlinkInfo == null ? null : new OccurenceInfo(new Navigatable.Adapter() {
|
||||
public void navigate(final boolean requestFocus) {
|
||||
hyperlinkInfo.navigate(myProject);
|
||||
linkFollowed(hyperlinkInfo);
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.extensions.ExtensionPoint;
|
||||
import com.intellij.openapi.extensions.ExtensionPointListener;
|
||||
import com.intellij.openapi.extensions.PluginDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -87,11 +88,11 @@ public class FacetTypeRegistryImpl extends FacetTypeRegistry {
|
||||
myExtensionsLoaded = true;
|
||||
final ExtensionPoint<FacetType> extensionPoint = Extensions.getArea(null).getExtensionPoint(FacetType.EP_NAME);
|
||||
extensionPoint.addExtensionPointListener(new ExtensionPointListener<FacetType>() {
|
||||
public void extensionAdded(final FacetType extension, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
public void extensionAdded(@NotNull final FacetType extension, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
registerFacetType(extension);
|
||||
}
|
||||
|
||||
public void extensionRemoved(final FacetType extension, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
public void extensionRemoved(@NotNull final FacetType extension, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
unregisterFacetType(extension);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -301,7 +301,8 @@ public class FormatterImpl extends FormatterEx
|
||||
final int defaultOffset = offset - whiteSpace.getLength() + newWS.length();
|
||||
|
||||
if (wsContainsCaret) {
|
||||
final int ws = whiteSpace.getStartOffset() + CharArrayUtil.shiftForward(newWS, lineStartOffset - whiteSpace.getStartOffset(), " \t");
|
||||
final int ws = whiteSpace.getStartOffset()
|
||||
+ CharArrayUtil.shiftForward(newWS, Math.max(0, lineStartOffset - whiteSpace.getStartOffset()), " \t");
|
||||
return Math.max(defaultOffset, ws);
|
||||
} else {
|
||||
return defaultOffset;
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.intellij.ide.hierarchy;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.OccurenceNavigator;
|
||||
import com.intellij.ide.OccurenceNavigatorSupport;
|
||||
import com.intellij.ide.PsiCopyPasteManager;
|
||||
import com.intellij.ide.dnd.DnDAction;
|
||||
import com.intellij.ide.dnd.DnDDragStartBean;
|
||||
import com.intellij.ide.dnd.DnDManager;
|
||||
@@ -54,6 +55,7 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
@@ -216,6 +218,11 @@ public abstract class HierarchyBrowserBaseEx extends HierarchyBrowserBase implem
|
||||
public PsiElement[] getPsiElements() {
|
||||
return getSelectedElements();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<File> asFileList() {
|
||||
return PsiCopyPasteManager.asFileList(getPsiElements());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+121
-104
@@ -22,8 +22,8 @@ package com.intellij.ide.projectView.impl;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.PsiCopyPasteManager;
|
||||
import com.intellij.ide.SelectInTarget;
|
||||
import com.intellij.ide.dnd.*;
|
||||
import com.intellij.ide.dnd.aware.DnDAwareTree;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesTreeViewPanel;
|
||||
import com.intellij.ide.projectView.BaseProjectTreeBuilder;
|
||||
import com.intellij.ide.projectView.ProjectView;
|
||||
import com.intellij.ide.projectView.impl.nodes.AbstractModuleNode;
|
||||
@@ -61,9 +61,11 @@ import javax.swing.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.dnd.*;
|
||||
import java.awt.dnd.DnDConstants;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -84,6 +86,10 @@ public abstract class AbstractProjectViewPane implements DataProvider, Disposabl
|
||||
@NonNls private static final String ELEMENT_SUBPANE = "subPane";
|
||||
@NonNls private static final String ATTRIBUTE_SUBID = "subId";
|
||||
|
||||
private DnDTarget myDropTarget;
|
||||
private DnDSource myDragSource;
|
||||
private DnDManager myDndManager;
|
||||
|
||||
protected AbstractProjectViewPane(Project project) {
|
||||
myProject = project;
|
||||
}
|
||||
@@ -148,6 +154,17 @@ public abstract class AbstractProjectViewPane implements DataProvider, Disposabl
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if (myDndManager != null) {
|
||||
if (myDropTarget != null) {
|
||||
myDndManager.unregisterTarget(myDropTarget, myTree);
|
||||
myDropTarget = null;
|
||||
}
|
||||
if (myDragSource != null) {
|
||||
myDndManager.unregisterSource(myDragSource, myTree);
|
||||
myDragSource = null;
|
||||
}
|
||||
myDndManager = null;
|
||||
}
|
||||
setTreeBuilder(null);
|
||||
myTree = null;
|
||||
myTreeStructure = null;
|
||||
@@ -465,36 +482,50 @@ public abstract class AbstractProjectViewPane implements DataProvider, Disposabl
|
||||
|
||||
// Drag'n'Drop stuff
|
||||
|
||||
public static final DataFlavor[] FLAVORS;
|
||||
private static final Logger LOG = Logger.getInstance("com.intellij.ide.projectView.ProjectViewImpl");
|
||||
private final MyDragSourceListener myDragSourceListener = new MyDragSourceListener();
|
||||
|
||||
static {
|
||||
DataFlavor[] flavors;
|
||||
|
||||
|
||||
@Nullable
|
||||
public static PsiElement[] getTransferedPsiElements(Transferable transferable) {
|
||||
try {
|
||||
final Class aClass = MyTransferable.class;
|
||||
flavors = new DataFlavor[]{new DataFlavor(
|
||||
DataFlavor.javaJVMLocalObjectMimeType + ";class=" + aClass.getName(),
|
||||
FavoritesTreeViewPanel.ABSTRACT_TREE_NODE_TRANSFERABLE,
|
||||
aClass.getClassLoader()
|
||||
)};
|
||||
final Object transferData = transferable.getTransferData(DnDEventImpl.ourDataFlavor);
|
||||
if (transferData instanceof TransferableWrapper) {
|
||||
return ((TransferableWrapper)transferData).getPsiElements();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
LOG.error(e); // should not happen
|
||||
flavors = new DataFlavor[0];
|
||||
catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static TreeNode[] getTransferedTreeNodes(Transferable transferable) {
|
||||
try {
|
||||
final Object transferData = transferable.getTransferData(DnDEventImpl.ourDataFlavor);
|
||||
if (transferData instanceof TransferableWrapper) {
|
||||
return ((TransferableWrapper)transferData).getTreeNodes();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
FLAVORS = flavors;
|
||||
}
|
||||
|
||||
protected void enableDnD() {
|
||||
if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
|
||||
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(myTree, DnDConstants.ACTION_COPY_OR_MOVE, new MyDragGestureListener());
|
||||
new DropTarget(myTree, new MoveDropTargetListener(new PsiRetriever() {
|
||||
@Nullable
|
||||
public PsiElement getPsiElement(@Nullable final TreeNode node) {
|
||||
myDropTarget = new ProjectViewDropTarget(myTree, new PsiRetriever(){
|
||||
@Override
|
||||
public PsiElement getPsiElement(@Nullable TreeNode node) {
|
||||
return getPSIElement(getElement(node));
|
||||
}
|
||||
}, myTree, myProject, FLAVORS[0]));
|
||||
}, myProject);
|
||||
myDragSource = new MyDragSource();
|
||||
myDndManager = DnDManager.getInstance();
|
||||
myDndManager.registerSource(myDragSource, myTree);
|
||||
myDndManager.registerTarget(myDropTarget, myTree);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,99 +538,85 @@ public abstract class AbstractProjectViewPane implements DataProvider, Disposabl
|
||||
myTreeBuilder = treeBuilder;
|
||||
}
|
||||
|
||||
private static class MyTransferable implements Transferable {
|
||||
private final Object myTransferable;
|
||||
|
||||
public MyTransferable(Object transferable) {
|
||||
myTransferable = transferable;
|
||||
}
|
||||
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
DataFlavor[] flavors = new DataFlavor[2];
|
||||
flavors [0] = FLAVORS [0];
|
||||
flavors [1] = DataFlavor.javaFileListFlavor;
|
||||
return flavors;
|
||||
}
|
||||
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
DataFlavor[] flavors = getTransferDataFlavors();
|
||||
return ArrayUtil.find(flavors, flavor) != -1;
|
||||
}
|
||||
|
||||
public Object getTransferData(DataFlavor flavor) {
|
||||
if (flavor == DataFlavor.javaFileListFlavor) {
|
||||
TransferableWrapper wrapper = (TransferableWrapper) myTransferable;
|
||||
return PsiCopyPasteManager.asFileList(wrapper.getPsiElements());
|
||||
}
|
||||
return myTransferable;
|
||||
}
|
||||
}
|
||||
|
||||
public interface TransferableWrapper {
|
||||
public interface TransferableWrapper extends DnDEventImpl.FileFlavorProvider{
|
||||
TreeNode[] getTreeNodes();
|
||||
@Nullable PsiElement[] getPsiElements();
|
||||
}
|
||||
|
||||
private class MyDragGestureListener implements DragGestureListener {
|
||||
public void dragGestureRecognized(DragGestureEvent dge) {
|
||||
if ((dge.getDragAction() & DnDConstants.ACTION_COPY_OR_MOVE) == 0) return;
|
||||
DataContext dataContext = DataManager.getInstance().getDataContext();
|
||||
ProjectView projectView = ProjectViewImpl.DATA_KEY.getData(dataContext);
|
||||
if (projectView == null) return;
|
||||
|
||||
final AbstractProjectViewPane currentPane = projectView.getCurrentProjectViewPane();
|
||||
final TreeNode[] nodes = currentPane.getSelectedTreeNodes();
|
||||
if (nodes != null) {
|
||||
final Object[] elements = currentPane.getSelectedElements();
|
||||
final PsiElement[] psiElements = currentPane.getSelectedPSIElements();
|
||||
try {
|
||||
Object transferableWrapper = new TransferableWrapper() {
|
||||
public TreeNode[] getTreeNodes() {
|
||||
return nodes;
|
||||
}
|
||||
public PsiElement[] getPsiElements() {
|
||||
return psiElements;
|
||||
}
|
||||
};
|
||||
|
||||
//FavoritesManager.getInstance(myProject).getCurrentTreeViewPanel().setDraggableObject(draggableObject.getClass(), draggableObject.getValue());
|
||||
if ((psiElements != null && psiElements.length > 0) || canDragElements(elements, dataContext, dge.getDragAction())) {
|
||||
dge.startDrag(DragSource.DefaultMoveNoDrop, new MyTransferable(transferableWrapper), myDragSourceListener);
|
||||
}
|
||||
}
|
||||
catch (InvalidDnDOperationException idoe) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
private class MyDragSource implements DnDSource {
|
||||
@Override
|
||||
public boolean canStartDragging(DnDAction action, Point dragOrigin) {
|
||||
if ((action.getActionId() & DnDConstants.ACTION_COPY_OR_MOVE) == 0) return false;
|
||||
final Object[] elements = getSelectedElements();
|
||||
final PsiElement[] psiElements = getSelectedPSIElements();
|
||||
DataContext dataContext = DataManager.getInstance().getDataContext(myTree);
|
||||
return (psiElements.length > 0) || canDragElements(elements, dataContext, action.getActionId());
|
||||
}
|
||||
|
||||
private boolean canDragElements(Object[] elements, DataContext dataContext, int dragAction) {
|
||||
for (Object element : elements) {
|
||||
if (element instanceof Module) {
|
||||
return true;
|
||||
@Override
|
||||
public DnDDragStartBean startDragging(DnDAction action, Point dragOrigin) {
|
||||
final PsiElement[] psiElements = getSelectedPSIElements();
|
||||
final TreeNode[] nodes = getSelectedTreeNodes();
|
||||
return new DnDDragStartBean(new TransferableWrapper(){
|
||||
|
||||
@Override
|
||||
public List<File> asFileList() {
|
||||
return PsiCopyPasteManager.asFileList(psiElements);
|
||||
}
|
||||
}
|
||||
if (dragAction == DnDConstants.ACTION_MOVE) {
|
||||
return MoveHandler.canMove(dataContext);
|
||||
}
|
||||
return false;
|
||||
|
||||
@Override
|
||||
public TreeNode[] getTreeNodes() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement[] getPsiElements() {
|
||||
return psiElements;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<Image, Point> createDraggedImage(DnDAction action, Point dragOrigin) {
|
||||
final TreePath[] paths = getSelectionPaths();
|
||||
if (paths == null) return null;
|
||||
|
||||
final int count = paths.length;
|
||||
|
||||
final JLabel label = new JLabel(String.format("%s item%s", count, count == 1 ? "" : "s"));
|
||||
label.setOpaque(true);
|
||||
label.setForeground(myTree.getForeground());
|
||||
label.setBackground(myTree.getBackground());
|
||||
label.setFont(myTree.getFont());
|
||||
label.setSize(label.getPreferredSize());
|
||||
final BufferedImage image = new BufferedImage(label.getWidth(), label.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
Graphics2D g2 = (Graphics2D)image.getGraphics();
|
||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
|
||||
label.paint(g2);
|
||||
g2.dispose();
|
||||
|
||||
return new Pair<Image, Point>(image, new Point(-image.getWidth(null), -image.getHeight(null)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dragDropEnd() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropActionChanged(int gestureModifiers) {
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyDragSourceListener implements DragSourceListener {
|
||||
|
||||
public void dragEnter(DragSourceDragEvent dsde) {
|
||||
dsde.getDragSourceContext().setCursor(null);
|
||||
private static boolean canDragElements(Object[] elements, DataContext dataContext, int dragAction) {
|
||||
for (Object element : elements) {
|
||||
if (element instanceof Module) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void dragOver(DragSourceDragEvent dsde) {}
|
||||
|
||||
public void dropActionChanged(DragSourceDragEvent dsde) {
|
||||
dsde.getDragSourceContext().setCursor(null);
|
||||
if (dragAction == DnDConstants.ACTION_MOVE) {
|
||||
return MoveHandler.canMove(dataContext);
|
||||
}
|
||||
|
||||
public void dragDropEnd(DragSourceDropEvent dsde) { }
|
||||
|
||||
public void dragExit(DragSourceEvent dse) { }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+71
-101
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,10 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.ide.projectView.impl;
|
||||
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.dnd.DnDEvent;
|
||||
import com.intellij.ide.dnd.DnDNativeTarget;
|
||||
import com.intellij.ide.projectView.impl.nodes.DropTargetNode;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
@@ -29,6 +30,7 @@ import com.intellij.refactoring.RefactoringActionHandlerFactory;
|
||||
import com.intellij.refactoring.actions.BaseRefactoringAction;
|
||||
import com.intellij.refactoring.copy.CopyHandler;
|
||||
import com.intellij.refactoring.move.MoveHandler;
|
||||
import com.intellij.ui.awt.RelativeRectangle;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -39,116 +41,92 @@ import javax.swing.tree.TreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.dnd.*;
|
||||
import java.awt.dnd.DnDConstants;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author vladk
|
||||
*/
|
||||
class MoveDropTargetListener implements DropTargetListener {
|
||||
final private DataFlavor dataFlavor;
|
||||
final private Project myProject;
|
||||
final private JTree myTree;
|
||||
final private PsiRetriever myPsiRetriever;
|
||||
* User: anna
|
||||
* Date: 10/7/10
|
||||
*/
|
||||
class ProjectViewDropTarget implements DnDNativeTarget {
|
||||
|
||||
public interface ModifierSource {
|
||||
int getModifiers();
|
||||
}
|
||||
private JTree myTree;
|
||||
private final PsiRetriever myPsiRetriever;
|
||||
private final Project myProject;
|
||||
|
||||
public MoveDropTargetListener(final PsiRetriever psiRetriever, final JTree tree, final Project project, final DataFlavor flavor) {
|
||||
ProjectViewDropTarget(JTree tree, PsiRetriever psiRetriever, Project project) {
|
||||
myTree = tree;
|
||||
myPsiRetriever = psiRetriever;
|
||||
myProject = project;
|
||||
myTree = tree;
|
||||
dataFlavor = flavor;
|
||||
}
|
||||
|
||||
public void dragEnter(DropTargetDragEvent dtde) {
|
||||
final DropHandler dropHandler = getDropHandler(dtde.getDropAction());
|
||||
final TreeNode[] sourceNodes = getSourceNodes(dtde.getTransferable());
|
||||
if (sourceNodes != null && dropHandler.isValidSource(sourceNodes)) {
|
||||
dtde.acceptDrag(dtde.getDropAction());
|
||||
@Override
|
||||
public boolean update(DnDEvent aEvent) {
|
||||
final Object attached = aEvent.getAttachedObject();
|
||||
aEvent.setDropPossible(false, "");
|
||||
final int dropAction = aEvent.getAction().getActionId();
|
||||
final DropHandler dropHandler = getDropHandler(dropAction);
|
||||
final TreeNode[] sourceNodes = getSourceNodes(attached);
|
||||
final Point point = aEvent.getPoint();
|
||||
final TreeNode targetNode = getTargetNode(point);
|
||||
|
||||
if (targetNode == null || (dropAction & DnDConstants.ACTION_COPY_OR_MOVE) == 0 ) {
|
||||
return false;
|
||||
}
|
||||
else if (dtde.getTransferable().isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
|
||||
dtde.acceptDrag(dtde.getDropAction());
|
||||
else if (sourceNodes == null && !aEvent.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
dtde.rejectDrag();
|
||||
else if (sourceNodes != null && !dropHandler.isValidSource(sourceNodes, targetNode)) {
|
||||
return false;
|
||||
}
|
||||
final Rectangle pathBounds = myTree.getPathBounds(myTree.getPathForLocation(point.x, point.y));
|
||||
aEvent.setHighlighting(new RelativeRectangle(myTree, pathBounds), DnDEvent.DropTargetHighlightingType.RECTANGLE );
|
||||
aEvent.setDropPossible(true, null);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void dragOver(DropTargetDragEvent dtde) {
|
||||
final TreeNode[] sourceNodes = getSourceNodes(dtde.getTransferable());
|
||||
final TreeNode targetNode = getTargetNode(dtde.getLocation());
|
||||
final int dropAction = dtde.getDropAction();
|
||||
if (sourceNodes != null && targetNode != null && canDrop(sourceNodes, targetNode, dropAction)) {
|
||||
dtde.acceptDrag(dropAction);
|
||||
}
|
||||
else if (targetNode != null && dtde.getTransferable().isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
|
||||
dtde.acceptDrag(dropAction);
|
||||
}
|
||||
else {
|
||||
dtde.rejectDrag();
|
||||
}
|
||||
}
|
||||
|
||||
public void dropActionChanged(DropTargetDragEvent dtde) {
|
||||
}
|
||||
|
||||
public void dragExit(DropTargetEvent dte) {
|
||||
}
|
||||
|
||||
public void drop(DropTargetDropEvent dtde) {
|
||||
final TreeNode[] sourceNodes = getSourceNodes(dtde.getTransferable());
|
||||
final TreeNode targetNode = getTargetNode(dtde.getLocation());
|
||||
final int dropAction = dtde.getDropAction();
|
||||
if (targetNode == null || (dropAction & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
|
||||
dtde.rejectDrop();
|
||||
}
|
||||
else if (sourceNodes == null) {
|
||||
if (dtde.getTransferable().isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
|
||||
dtde.acceptDrop(dropAction);
|
||||
List<File> fileList;
|
||||
@Override
|
||||
public void drop(DnDEvent aEvent) {
|
||||
Object attached = aEvent.getAttachedObject();
|
||||
final TreeNode[] sourceNodes = getSourceNodes(attached);
|
||||
final TreeNode targetNode = getTargetNode(aEvent.getPoint());
|
||||
assert targetNode != null;
|
||||
final int dropAction = aEvent.getAction().getActionId();
|
||||
if (sourceNodes == null) {
|
||||
if (aEvent.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
|
||||
Object fileList;
|
||||
try {
|
||||
fileList = (List<File>)dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
|
||||
fileList = ((EventInfo)attached).getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
|
||||
}
|
||||
catch (Exception e) {
|
||||
dtde.rejectDrop();
|
||||
return;
|
||||
}
|
||||
getDropHandler(dropAction).doDropFiles(fileList, targetNode);
|
||||
}
|
||||
else {
|
||||
dtde.rejectDrop();
|
||||
if (fileList instanceof List) {
|
||||
getDropHandler(dropAction).doDropFiles((List<File>)fileList, targetNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!doDrop(sourceNodes, targetNode, dropAction, dtde)) {
|
||||
dtde.rejectDrop();
|
||||
else {
|
||||
doDrop(sourceNodes, targetNode, dropAction);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUpOnLeave() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDraggedImage(Image image, Point dropPoint, Point imageOffset) {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private TreeNode[] getSourceNodes(final Transferable transferable) {
|
||||
if (!transferable.isDataFlavorSupported(dataFlavor)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Object transferData = transferable.getTransferData(dataFlavor);
|
||||
if (transferData instanceof AbstractProjectViewPSIPane.TransferableWrapper) {
|
||||
return ((AbstractProjectViewPSIPane.TransferableWrapper)transferData).getTreeNodes();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (UnsupportedFlavorException e) {
|
||||
return null;
|
||||
}
|
||||
catch (IOException e) {
|
||||
return null;
|
||||
private static TreeNode[] getSourceNodes(final Object transferData) {
|
||||
if (transferData instanceof AbstractProjectViewPSIPane.TransferableWrapper) {
|
||||
return ((AbstractProjectViewPSIPane.TransferableWrapper)transferData).getTreeNodes();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -157,22 +135,14 @@ class MoveDropTargetListener implements DropTargetListener {
|
||||
return path == null ? null : (TreeNode)path.getLastPathComponent();
|
||||
}
|
||||
|
||||
private boolean canDrop(@NotNull final TreeNode[] sourceNodes, @NotNull final TreeNode targetNode, final int dropAction) {
|
||||
return doDrop(sourceNodes, targetNode, dropAction, null);
|
||||
}
|
||||
|
||||
private boolean doDrop(@NotNull final TreeNode[] sourceNodes,
|
||||
@NotNull final TreeNode targetNode,
|
||||
final int dropAction,
|
||||
@Nullable final DropTargetDropEvent dtde) {
|
||||
final int dropAction) {
|
||||
TreeNode validTargetNode = getValidTargetNode(sourceNodes, targetNode, dropAction);
|
||||
if (validTargetNode != null) {
|
||||
final TreeNode[] filteredSourceNodes = removeRedundantSourceNodes(sourceNodes, validTargetNode, dropAction);
|
||||
if (filteredSourceNodes.length != 0) {
|
||||
if (dtde != null) {
|
||||
dtde.dropComplete(true);
|
||||
getDropHandler(dropAction).doDrop(filteredSourceNodes, validTargetNode);
|
||||
}
|
||||
getDropHandler(dropAction).doDrop(filteredSourceNodes, validTargetNode);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -209,7 +179,7 @@ class MoveDropTargetListener implements DropTargetListener {
|
||||
}
|
||||
|
||||
private interface DropHandler {
|
||||
boolean isValidSource(@NotNull TreeNode[] sourceNodes);
|
||||
boolean isValidSource(@NotNull TreeNode[] sourceNodes, TreeNode targetNode);
|
||||
|
||||
boolean isValidTarget(@NotNull TreeNode[] sourceNodes, @NotNull TreeNode targetNode);
|
||||
|
||||
@@ -224,8 +194,8 @@ class MoveDropTargetListener implements DropTargetListener {
|
||||
|
||||
public abstract class MoveCopyDropHandler implements DropHandler {
|
||||
|
||||
public boolean isValidSource(@NotNull final TreeNode[] sourceNodes) {
|
||||
return canDrop(sourceNodes, null);
|
||||
public boolean isValidSource(@NotNull final TreeNode[] sourceNodes, TreeNode targetNode) {
|
||||
return canDrop(sourceNodes, targetNode);
|
||||
}
|
||||
|
||||
public boolean isValidTarget(@NotNull final TreeNode[] sourceNodes, final @NotNull TreeNode targetNode) {
|
||||
@@ -234,11 +204,11 @@ class MoveDropTargetListener implements DropTargetListener {
|
||||
|
||||
protected abstract boolean canDrop(@NotNull TreeNode[] sourceNodes, @Nullable TreeNode targetNode);
|
||||
|
||||
@Nullable
|
||||
protected PsiElement getPsiElement(@Nullable final TreeNode treeNode) {
|
||||
return myPsiRetriever.getPsiElement(treeNode);
|
||||
}
|
||||
|
||||
|
||||
@NotNull protected PsiElement[] getPsiElements(@NotNull TreeNode[] nodes) {
|
||||
List<PsiElement> psiElements = new ArrayList<PsiElement>(nodes.length);
|
||||
for (TreeNode node : nodes) {
|
||||
@@ -307,7 +277,7 @@ class MoveDropTargetListener implements DropTargetListener {
|
||||
final PsiElement targetElement = getPsiElement(targetNode);
|
||||
if (targetElement == null) return;
|
||||
final DataContext dataContext = DataManager.getInstance().getDataContext(myTree);
|
||||
getActionHandler(dataContext).invoke(myProject, sourceElements, new DataContext() {
|
||||
getActionHandler().invoke(myProject, sourceElements, new DataContext() {
|
||||
@Nullable
|
||||
public Object getData(@NonNls String dataId) {
|
||||
if (LangDataKeys.TARGET_PSI_ELEMENT.is(dataId)) {
|
||||
@@ -320,7 +290,7 @@ class MoveDropTargetListener implements DropTargetListener {
|
||||
});
|
||||
}
|
||||
|
||||
private RefactoringActionHandler getActionHandler(final DataContext dataContext) {
|
||||
private RefactoringActionHandler getActionHandler() {
|
||||
return RefactoringActionHandlerFactory.getInstance().createMoveHandler();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import com.intellij.history.LocalHistory;
|
||||
import com.intellij.history.LocalHistoryAction;
|
||||
import com.intellij.ide.*;
|
||||
import com.intellij.ide.FileEditorProvider;
|
||||
import com.intellij.ide.dnd.DnDManager;
|
||||
import com.intellij.ide.dnd.DnDTarget;
|
||||
import com.intellij.ide.impl.ProjectViewSelectInTarget;
|
||||
import com.intellij.ide.projectView.HelpID;
|
||||
import com.intellij.ide.projectView.ProjectView;
|
||||
|
||||
@@ -402,7 +402,7 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
|
||||
return pre;
|
||||
}
|
||||
|
||||
private static class Token extends Node {
|
||||
private static abstract class Token extends Node {
|
||||
public PsiBuilderImpl myBuilder;
|
||||
public IElementType myTokenType;
|
||||
public int myTokenStart;
|
||||
@@ -461,6 +461,9 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private static class TokenNode extends Token implements LighterASTTokenNode {
|
||||
}
|
||||
|
||||
private static class LazyParseableToken extends Token implements LighterLazyParseableNode {
|
||||
private MyTreeStructure myParent;
|
||||
private FlyweightCapableTreeStructure<LighterASTNode> myParsed;
|
||||
@@ -1169,7 +1172,7 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
|
||||
}
|
||||
|
||||
public Token create() {
|
||||
return new Token();
|
||||
return new TokenNode();
|
||||
}
|
||||
});
|
||||
myLazyPool = new LimitedPool<LazyParseableToken>(200, new LimitedPool.ObjectFactory<LazyParseableToken>() {
|
||||
@@ -1229,7 +1232,7 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
|
||||
ProductionMarker prevChild = null;
|
||||
int lexIndex = marker.myLexemeIndex;
|
||||
while (child != null) {
|
||||
lexIndex = insertLeafs(lexIndex, child.myLexemeIndex, into, marker.myBuilder);
|
||||
lexIndex = insertLeaves(lexIndex, child.myLexemeIndex, into, marker.myBuilder);
|
||||
|
||||
if (child instanceof StartMarker && ((StartMarker)child).myDoneMarker.myCollapse) {
|
||||
final int start = marker.myBuilder.myLexStarts[child.myLexemeIndex];
|
||||
@@ -1251,7 +1254,8 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
|
||||
}
|
||||
child = child.next;
|
||||
}
|
||||
insertLeafs(lexIndex, marker.myDoneMarker.myLexemeIndex, into, marker.myBuilder);
|
||||
|
||||
insertLeaves(lexIndex, marker.myDoneMarker.myLexemeIndex, into, marker.myBuilder);
|
||||
|
||||
return count;
|
||||
}
|
||||
@@ -1269,7 +1273,7 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private int insertLeafs(int curToken, int lastIdx, Ref<LighterASTNode[]> into, PsiBuilderImpl builder) {
|
||||
private int insertLeaves(int curToken, int lastIdx, Ref<LighterASTNode[]> into, PsiBuilderImpl builder) {
|
||||
lastIdx = Math.min(lastIdx, builder.myLexemeCount);
|
||||
while (curToken < lastIdx) {
|
||||
final int start = builder.myLexStarts[curToken];
|
||||
@@ -1284,7 +1288,7 @@ public class PsiBuilderImpl extends UserDataHolderBase implements PsiBuilder {
|
||||
}
|
||||
|
||||
private void insertLeaf(Ref<LighterASTNode[]> into, int start, int end, IElementType type, PsiBuilderImpl builder) {
|
||||
Token lexeme;
|
||||
final Token lexeme;
|
||||
if (type instanceof ILightLazyParseableElementType) {
|
||||
lexeme = myLazyPool.alloc();
|
||||
((LazyParseableToken)lexeme).myParent = this;
|
||||
|
||||
@@ -628,7 +628,7 @@ public class ProjectRootManagerImpl extends ProjectRootManagerEx implements Proj
|
||||
}
|
||||
|
||||
private void addRootsToWatch() {
|
||||
final Set<String> rootPaths = getAllRoots();
|
||||
final Set<String> rootPaths = getAllRoots(false);
|
||||
if (rootPaths == null) return;
|
||||
|
||||
final Set<LocalFileSystem.WatchRequest> newRootsToWatch = LocalFileSystem.getInstance().addRootsToWatch(rootPaths, true);
|
||||
@@ -639,7 +639,7 @@ public class ProjectRootManagerImpl extends ProjectRootManagerEx implements Proj
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Set<String> getAllRoots() {
|
||||
private Set<String> getAllRoots(boolean includeSourceRoots) {
|
||||
if (myProject.isDefault()) return null;
|
||||
|
||||
final Set<String> rootPaths = new HashSet<String>();
|
||||
@@ -648,6 +648,10 @@ public class ProjectRootManagerImpl extends ProjectRootManagerEx implements Proj
|
||||
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
|
||||
final String[] contentRootUrls = moduleRootManager.getContentRootUrls();
|
||||
rootPaths.addAll(getRootsToTrack(contentRootUrls));
|
||||
if (includeSourceRoots) {
|
||||
final String[] sourceRootUrls = moduleRootManager.getSourceRootUrls();
|
||||
rootPaths.addAll(getRootsToTrack(sourceRootUrls));
|
||||
}
|
||||
rootPaths.add(module.getModuleFilePath());
|
||||
}
|
||||
|
||||
@@ -775,7 +779,7 @@ public class ProjectRootManagerImpl extends ProjectRootManagerEx implements Proj
|
||||
}
|
||||
|
||||
private boolean affectsRoots(VirtualFilePointer[] pointers) {
|
||||
Set<String> roots = getAllRoots();
|
||||
Set<String> roots = getAllRoots(true);
|
||||
if (roots == null) return false;
|
||||
|
||||
for (VirtualFilePointer pointer : pointers) {
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@
|
||||
<properties/>
|
||||
<border type="none" title=""/>
|
||||
<children>
|
||||
<component id="e9af6" class="javax.swing.JLabel">
|
||||
<component id="e9af6" class="javax.swing.JLabel" binding="myTitleLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
@@ -16,7 +16,7 @@
|
||||
<text resource-bundle="messages/IdeBundle" key="encodings.dialog.caption"/>
|
||||
</properties>
|
||||
</component>
|
||||
<scrollpane class="com.intellij.ui.components.JBScrollPane" id="fe0c3" binding="myTreePanel" custom-create="true">
|
||||
<scrollpane id="fe0c3" class="com.intellij.ui.components.JBScrollPane" binding="myTreePanel" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
|
||||
+7
-1
@@ -21,7 +21,11 @@ import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.options.*;
|
||||
import com.intellij.openapi.application.ApplicationNamesInfo;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.NonDefaultProjectConfigurable;
|
||||
import com.intellij.openapi.options.OptionalConfigurable;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
@@ -51,10 +55,12 @@ public class FileEncodingConfigurable implements SearchableConfigurable, NonDefa
|
||||
private JPanel myPropertiesFilesEncodingCombo;
|
||||
private Charset mySelectedCharsetForPropertiesFiles;
|
||||
private JComboBox myIdeEncodingsCombo;
|
||||
private JLabel myTitleLabel;
|
||||
private ChooseFileEncodingAction myAction;
|
||||
|
||||
public FileEncodingConfigurable(Project project) {
|
||||
myProject = project;
|
||||
myTitleLabel.setText(myTitleLabel.getText().replace("$productName", ApplicationNamesInfo.getInstance().getFullProductName()));
|
||||
}
|
||||
|
||||
@Nls
|
||||
|
||||
+2
-3
@@ -60,7 +60,6 @@ import java.util.Set;
|
||||
public class InspectionProjectProfileManager extends DefaultProjectProfileManager implements SeverityProvider, ProjectComponent, PersistentStateComponent<Element> {
|
||||
private final Map<String, InspectionProfileWrapper> myName2Profile = new HashMap<String, InspectionProfileWrapper>();
|
||||
private final SeverityRegistrar mySeverityRegistrar;
|
||||
private StatusBarEx myStatusBar;
|
||||
private TogglePopupHintsPanel myTogglePopupHintsPanel;
|
||||
|
||||
public InspectionProjectProfileManager(final Project project, InspectionProfileManager inspectionProfileManager, DependencyValidationManager holder) {
|
||||
@@ -147,9 +146,9 @@ public class InspectionProjectProfileManager extends DefaultProjectProfileManage
|
||||
}
|
||||
|
||||
public void projectOpened() {
|
||||
myStatusBar = (StatusBarEx)WindowManager.getInstance().getStatusBar(myProject);
|
||||
StatusBarEx statusBar = (StatusBarEx)WindowManager.getInstance().getStatusBar(myProject);
|
||||
myTogglePopupHintsPanel = new TogglePopupHintsPanel(myProject);
|
||||
myStatusBar.addWidget(myTogglePopupHintsPanel, myProject);
|
||||
statusBar.addWidget(myTogglePopupHintsPanel, myProject);
|
||||
StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() {
|
||||
public void run() {
|
||||
final Set<Profile> profiles = new HashSet<Profile>();
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ abstract class InspectionsConfigTreeRenderer extends CheckboxTree.CheckboxTreeCe
|
||||
Object object = node.getUserObject();
|
||||
|
||||
final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
|
||||
setBackground(background);
|
||||
UIUtil.changeBackGround(this, background);
|
||||
Color foreground =
|
||||
selected ? UIUtil.getTreeSelectionForeground() : node.isProperSetting ? Color.BLUE : UIUtil.getTreeTextForeground();
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.intellij.psi.impl;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.LighterASTNode;
|
||||
import com.intellij.lang.LighterLazyParseableNode;
|
||||
import com.intellij.lang.LighterASTTokenNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
@@ -136,26 +136,18 @@ public class DebugUtil {
|
||||
}
|
||||
|
||||
public static String lightTreeToString(@NotNull final FlyweightCapableTreeStructure<LighterASTNode> tree,
|
||||
@NotNull final String source,
|
||||
final boolean skipWhitespaces) {
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
lightTreeToBuffer(tree, source, buffer, tree.getRoot(), 0, skipWhitespaces, 0);
|
||||
lightTreeToBuffer(tree, tree.getRoot(), buffer, 0, skipWhitespaces);
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static void lightTreeToBuffer(@NotNull final FlyweightCapableTreeStructure<LighterASTNode> tree,
|
||||
@NotNull final String source,
|
||||
@NotNull final StringBuilder buffer,
|
||||
@NotNull final LighterASTNode root,
|
||||
final int indent,
|
||||
final boolean skipWhiteSpaces,
|
||||
final int chameleonShift) {
|
||||
final IElementType tokenType = root.getTokenType();
|
||||
public static void lightTreeToBuffer(@NotNull final FlyweightCapableTreeStructure<LighterASTNode> tree, @NotNull final LighterASTNode node,
|
||||
@NotNull final StringBuilder buffer, final int indent, final boolean skipWhiteSpaces) {
|
||||
final IElementType tokenType = node.getTokenType();
|
||||
if (skipWhiteSpaces && tokenType == TokenType.WHITE_SPACE) return;
|
||||
|
||||
final Ref<LighterASTNode[]> kids = new Ref<LighterASTNode[]>();
|
||||
final int numKids = tree.getChildren(tree.prepareForGetChildren(root), kids);
|
||||
final boolean composite = numKids > 0 || root.getStartOffset() == root.getEndOffset();
|
||||
final boolean isLeaf = (node instanceof LighterASTTokenNode);
|
||||
|
||||
StringUtil.repeatSymbol(buffer, ' ', indent);
|
||||
if (tokenType == TokenType.ERROR_ELEMENT) {
|
||||
@@ -165,24 +157,25 @@ public class DebugUtil {
|
||||
buffer.append("PsiWhiteSpace");
|
||||
}
|
||||
else {
|
||||
buffer.append(composite ? "Element" : "PsiElement").append('(').append(tokenType).append(')');
|
||||
buffer.append(isLeaf ? "PsiElement" : "Element").append('(').append(tokenType).append(')');
|
||||
}
|
||||
|
||||
if (!composite) {
|
||||
final String text = source.substring(chameleonShift + root.getStartOffset(), chameleonShift + root.getEndOffset());
|
||||
if (isLeaf) {
|
||||
final String text = ((LighterASTTokenNode)node).getText().toString();
|
||||
buffer.append("('").append(fixWhiteSpaces(text)).append("')");
|
||||
}
|
||||
buffer.append('\n');
|
||||
|
||||
if (composite) {
|
||||
if (!isLeaf) {
|
||||
final Ref<LighterASTNode[]> kids = new Ref<LighterASTNode[]>();
|
||||
final int numKids = tree.getChildren(tree.prepareForGetChildren(node), kids);
|
||||
if (numKids == 0) {
|
||||
StringUtil.repeatSymbol(buffer, ' ', indent + 2);
|
||||
buffer.append("<empty list>\n");
|
||||
}
|
||||
else {
|
||||
final int shift = root instanceof LighterLazyParseableNode ? root.getStartOffset() : 0;
|
||||
for (int i = 0; i < numKids; i++) {
|
||||
lightTreeToBuffer(tree, source, buffer, kids.get()[i], indent + 2, skipWhiteSpaces, chameleonShift + shift);
|
||||
lightTreeToBuffer(tree, kids.get()[i], buffer, indent + 2, skipWhiteSpaces);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -66,20 +66,20 @@ public class InjectedLanguageManagerImpl extends InjectedLanguageManager {
|
||||
|
||||
final ExtensionPoint<MultiHostInjector> multiPoint = Extensions.getArea(project).getExtensionPoint(MultiHostInjector.MULTIHOST_INJECTOR_EP_NAME);
|
||||
multiPoint.addExtensionPointListener(new ExtensionPointListener<MultiHostInjector>() {
|
||||
public void extensionAdded(MultiHostInjector injector, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
public void extensionAdded(@NotNull MultiHostInjector injector, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
registerMultiHostInjector(injector);
|
||||
}
|
||||
|
||||
public void extensionRemoved(MultiHostInjector injector, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
public void extensionRemoved(@NotNull MultiHostInjector injector, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
unregisterMultiHostInjector(injector);
|
||||
}
|
||||
});
|
||||
final ExtensionPointListener<LanguageInjector> myListener = new ExtensionPointListener<LanguageInjector>() {
|
||||
public void extensionAdded(LanguageInjector extension, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
public void extensionAdded(@NotNull LanguageInjector extension, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
psiManagerInjectorsChanged();
|
||||
}
|
||||
|
||||
public void extensionRemoved(LanguageInjector extension, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
public void extensionRemoved(@NotNull LanguageInjector extension, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
psiManagerInjectorsChanged();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -19,19 +19,22 @@
|
||||
*/
|
||||
package com.intellij.psi.stubs;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SerializedStubTree {
|
||||
private final byte[] myBytes;
|
||||
private final StubElement myStub;
|
||||
|
||||
public SerializedStubTree(final byte[] bytes) {
|
||||
public SerializedStubTree(final byte[] bytes, @Nullable StubElement stub) {
|
||||
myBytes = bytes;
|
||||
myStub = stub;
|
||||
}
|
||||
|
||||
public StubElement getStub() {
|
||||
return SerializationManager.getInstance().deserialize(new ByteArrayInputStream(myBytes));
|
||||
return myStub == null ? SerializationManager.getInstance().deserialize(new ByteArrayInputStream(myBytes)) : myStub;
|
||||
}
|
||||
|
||||
public boolean equals(final Object that) {
|
||||
|
||||
@@ -63,7 +63,7 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi
|
||||
int len = in.readInt();
|
||||
byte[] result = new byte[len];
|
||||
in.readFully(result);
|
||||
return new SerializedStubTree(result);
|
||||
return new SerializedStubTree(result, null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -118,7 +118,7 @@ public class StubUpdatingIndex extends CustomImplementationFileBasedIndexExtensi
|
||||
SerializationManager.getInstance().serialize(rootStub, bytes);
|
||||
|
||||
final int key = Math.abs(FileBasedIndex.getFileId(inputData.getFile()));
|
||||
result.put(key, new SerializedStubTree(bytes.toByteArray()));
|
||||
result.put(key, new SerializedStubTree(bytes.toByteArray(), rootStub));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+2
-2
@@ -48,11 +48,11 @@ public abstract class BasePlatformRefactoringAction extends BaseRefactoringActio
|
||||
|
||||
public BasePlatformRefactoringAction() {
|
||||
LanguageRefactoringSupport.INSTANCE.addListener(new ExtensionPointListener<RefactoringSupportProvider>() {
|
||||
public void extensionAdded(RefactoringSupportProvider extension, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
public void extensionAdded(@NotNull RefactoringSupportProvider extension, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
myHidden = null;
|
||||
}
|
||||
|
||||
public void extensionRemoved(RefactoringSupportProvider extension, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
public void extensionRemoved(@NotNull RefactoringSupportProvider extension, @Nullable PluginDescriptor pluginDescriptor) {
|
||||
myHidden = null;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -41,6 +41,10 @@ public class GotoTestOrCodeAction extends BaseCodeInsightAction {
|
||||
@Override
|
||||
public void update(AnActionEvent event) {
|
||||
Presentation p = event.getPresentation();
|
||||
if (TestFinderHelper.getFinders().length == 0) {
|
||||
p.setVisible(false);
|
||||
return;
|
||||
}
|
||||
p.setEnabled(false);
|
||||
Project project = event.getData(PlatformDataKeys.PROJECT);
|
||||
Editor editor = event.getData(PlatformDataKeys.EDITOR);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class TestFinderHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static TestFinder[] getFinders() {
|
||||
public static TestFinder[] getFinders() {
|
||||
return Extensions.getExtensions(TestFinder.EP_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ class ToolsPanel extends JPanel {
|
||||
// Fix GTK backround
|
||||
if (UIUtil.isUnderGTKLookAndFeel()){
|
||||
final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
|
||||
setBackground(background);
|
||||
UIUtil.changeBackGround(this, background);
|
||||
}
|
||||
|
||||
if (object instanceof ToolsGroup) {
|
||||
|
||||
@@ -523,10 +523,10 @@ public class PsiBuilderQuickTest {
|
||||
// check light tree composition
|
||||
final FlyweightCapableTreeStructure<LighterASTNode> lightTree = builder.getLightTree();
|
||||
final String lightExpected = expected.replaceAll("PsiErrorElement:.*\n", "PsiErrorElement\n");
|
||||
assertEquals(lightExpected, DebugUtil.lightTreeToString(lightTree, text, false));
|
||||
assertEquals(lightExpected, DebugUtil.lightTreeToString(lightTree, false));
|
||||
// verify that light tree can be taken multiple times
|
||||
final FlyweightCapableTreeStructure<LighterASTNode> lightTree2 = builder.getLightTree();
|
||||
assertEquals(lightExpected, DebugUtil.lightTreeToString(lightTree2, text, false));
|
||||
assertEquals(lightExpected, DebugUtil.lightTreeToString(lightTree2, false));
|
||||
|
||||
// check heavy tree composition
|
||||
final ASTNode root = builder.getTreeBuilt();
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.intellij.history.core.changes.ContentChange;
|
||||
import com.intellij.history.core.changes.StructuralChange;
|
||||
import com.intellij.history.integration.IdeaGateway;
|
||||
import com.intellij.history.integration.LocalHistoryImpl;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.undo.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -111,7 +110,10 @@ public class FileUndoProvider extends VirtualFileAdapter implements UndoProvider
|
||||
}
|
||||
|
||||
public void beforeFileDeletion(VirtualFileEvent e) {
|
||||
if (shouldNotProcess(e)) return;
|
||||
if (shouldNotProcess(e)) {
|
||||
invalidateActionsFor(e);
|
||||
return;
|
||||
}
|
||||
if (isUndoable(e)) {
|
||||
VirtualFile file = e.getFile();
|
||||
file.putUserData(DELETION_WAS_UNDOABLE, createDocumentReference(e));
|
||||
@@ -155,6 +157,10 @@ public class FileUndoProvider extends VirtualFileAdapter implements UndoProvider
|
||||
getUndoManager().nonundoableActionPerformed(createDocumentReference(e), true);
|
||||
}
|
||||
|
||||
private void invalidateActionsFor(VirtualFileEvent e) {
|
||||
getUndoManager().invalidateActionsFor(createDocumentReference(e));
|
||||
}
|
||||
|
||||
private DocumentReference createDocumentReference(VirtualFileEvent e) {
|
||||
return DocumentReferenceManager.getInstance().create(e.getFile());
|
||||
}
|
||||
|
||||
+18
-1
@@ -15,10 +15,13 @@
|
||||
*/
|
||||
package com.intellij.openapi.fileChooser;
|
||||
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.UIBundle;
|
||||
|
||||
public class FileChooserDescriptorFactory {
|
||||
private FileChooserDescriptorFactory() {}
|
||||
private FileChooserDescriptorFactory() {
|
||||
}
|
||||
|
||||
public static FileChooserDescriptor createAllButJarContentsDescriptor() {
|
||||
return new FileChooserDescriptor(true, true, true, true, false, true);
|
||||
@@ -59,4 +62,18 @@ public class FileChooserDescriptorFactory {
|
||||
fileChooserDescriptor.setTitle(UIBundle.message("file.chooser.select.object.title", aSearchedObjectName));
|
||||
return fileChooserDescriptor;
|
||||
}
|
||||
|
||||
public static FileChooserDescriptor createSingleFileDescriptor(final FileType fileType) {
|
||||
return new FileChooserDescriptor(true, false, false, false, false, false) {
|
||||
@Override
|
||||
public boolean isFileVisible(final VirtualFile file, final boolean showHiddenFiles) {
|
||||
return file.isDirectory() || file.getFileType() == fileType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFileSelectable(final VirtualFile file) {
|
||||
return super.isFileSelectable(file) && file.getFileType() == fileType;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,4 +180,6 @@ public interface JBPopup extends Disposable, LightweightWindow {
|
||||
void setFinalRunnable(@Nullable Runnable runnable);
|
||||
|
||||
void moveToFitScreen();
|
||||
|
||||
Point getLocationOnScreen();
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ public abstract class KeyedExtensionCollector<T, KeyT> {
|
||||
ExtensionPointName<KeyedLazyInstance<T>> typesafe = ExtensionPointName.create(myEpName);
|
||||
myPoint = Extensions.getRootArea().getExtensionPoint(typesafe);
|
||||
myListener = new ExtensionPointAndAreaListener<KeyedLazyInstance<T>>() {
|
||||
public void extensionAdded(final KeyedLazyInstance<T> bean, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
public void extensionAdded(@NotNull final KeyedLazyInstance<T> bean, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
w.lock();
|
||||
try {
|
||||
myCache.remove(bean.getKey());
|
||||
@@ -191,7 +191,7 @@ public abstract class KeyedExtensionCollector<T, KeyT> {
|
||||
}
|
||||
}
|
||||
|
||||
public void extensionRemoved(final KeyedLazyInstance<T> bean, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
public void extensionRemoved(@NotNull final KeyedLazyInstance<T> bean, @Nullable final PluginDescriptor pluginDescriptor) {
|
||||
w.lock();
|
||||
try {
|
||||
myCache.remove(bean.getKey());
|
||||
|
||||
@@ -232,7 +232,7 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component
|
||||
// Fix GTK backround
|
||||
if (UIUtil.isUnderGTKLookAndFeel()){
|
||||
final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
|
||||
setBackground(background);
|
||||
UIUtil.changeBackGround(this, background);
|
||||
}
|
||||
|
||||
if (!selected) return result;
|
||||
|
||||
@@ -210,51 +210,25 @@ public class HintManagerImpl extends HintManager implements Disposable {
|
||||
((ScrollAwareHint)hint.getComponent()).editorScrolled();
|
||||
}
|
||||
|
||||
if (!hint.isVisible()) {
|
||||
return;
|
||||
}
|
||||
if (!hint.isVisible()) return;
|
||||
|
||||
Editor editor = e.getEditor();
|
||||
if (!editor.getComponent().isShowing() || editor.isOneLineMode()) return;
|
||||
Rectangle newRectangle = e.getOldRectangle();
|
||||
Rectangle oldRectangle = e.getNewRectangle();
|
||||
Rectangle bounds = hint.getBounds();
|
||||
Point location;
|
||||
|
||||
final Window window = SwingUtilities.getWindowAncestor(hint.getComponent());
|
||||
final boolean realPopup = window != null && window != SwingUtilities.getWindowAncestor(editor.getComponent());
|
||||
if (realPopup) {
|
||||
location = window.getLocationOnScreen();
|
||||
SwingUtilities.convertPointFromScreen(location, editor.getContentComponent());
|
||||
} else {
|
||||
location = SwingUtilities.convertPoint(
|
||||
editor.getComponent().getRootPane().getLayeredPane(),
|
||||
bounds.getLocation(),
|
||||
editor.getContentComponent()
|
||||
);
|
||||
}
|
||||
|
||||
Point location = hint.getLocationOn(editor.getContentComponent());
|
||||
Dimension size = hint.getSize();
|
||||
|
||||
int xOffset = location.x - oldRectangle.x;
|
||||
int yOffset = location.y - oldRectangle.y;
|
||||
location = new Point(newRectangle.x + xOffset, newRectangle.y + yOffset);
|
||||
|
||||
Rectangle newBounds = new Rectangle(location.x, location.y, bounds.width, bounds.height);
|
||||
|
||||
final boolean valid = hideIfOutOfEditor ? oldRectangle.contains(newBounds) : oldRectangle.intersects(newBounds);
|
||||
if (valid) {
|
||||
if (!realPopup) {
|
||||
location = SwingUtilities.convertPoint(
|
||||
editor.getContentComponent(),
|
||||
location,
|
||||
editor.getComponent().getRootPane().getLayeredPane()
|
||||
);
|
||||
hint.updateBounds(location.x, location.y);
|
||||
} else {
|
||||
SwingUtilities.convertPointToScreen(location, editor.getContentComponent());
|
||||
window.setLocation(location);
|
||||
}
|
||||
Rectangle newBounds = new Rectangle(location.x, location.y, size.width, size.height);
|
||||
|
||||
final boolean okToUpdateBounds = hideIfOutOfEditor ? oldRectangle.contains(newBounds) : oldRectangle.intersects(newBounds);
|
||||
if (okToUpdateBounds) {
|
||||
hint.setLocation(new RelativePoint(editor.getContentComponent(), location));
|
||||
}
|
||||
else {
|
||||
hint.hide();
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.intellij.ui.LightweightHint;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
@@ -57,7 +56,13 @@ public class TooltipController {
|
||||
final boolean alignToRight,
|
||||
@NotNull final TooltipGroup group, final HintHint hintHint) {
|
||||
if (myCurrentTooltip == null || !myCurrentTooltip.isVisible()) {
|
||||
myCurrentTooltipObject = null;
|
||||
if (myCurrentTooltip != null) {
|
||||
if (!IdeTooltipManager.getInstance().isQueuedToShow(myCurrentTooltip.getCurrentIdeTooltip())) {
|
||||
myCurrentTooltipObject = null;
|
||||
}
|
||||
} else {
|
||||
myCurrentTooltipObject = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (Comparing.equal(tooltipObject, myCurrentTooltipObject)) {
|
||||
|
||||
@@ -67,8 +67,7 @@ public class ProgressTipPanel {
|
||||
final HTMLEditorKit editorKit = new HTMLEditorKit();
|
||||
myBrowser.setEditorKit(editorKit);
|
||||
myBrowser.setContentType(UIUtil.HTML_MIME);
|
||||
myBrowser.setBackground(UIUtil.getTextFieldBackground());
|
||||
|
||||
myBrowser.setBackground(Color.white);
|
||||
myScrollPane.setPreferredSize(new Dimension(600, 200));
|
||||
myBrowser.setEditable(false);
|
||||
myPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
|
||||
|
||||
@@ -17,11 +17,12 @@ package com.intellij.ide;
|
||||
|
||||
import com.intellij.openapi.ui.popup.Balloon;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.util.ui.update.ComparableObject;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class IdeTooltip {
|
||||
public class IdeTooltip extends ComparableObject.Impl {
|
||||
|
||||
private Component myComponent;
|
||||
private Point myPoint;
|
||||
@@ -34,7 +35,8 @@ public class IdeTooltip {
|
||||
private boolean myToCenterIfSmall = true;
|
||||
private boolean myHighlighter;
|
||||
|
||||
public IdeTooltip(Component component, Point point, JComponent tipComponent) {
|
||||
public IdeTooltip(Component component, Point point, JComponent tipComponent, Object... identity) {
|
||||
super(identity);
|
||||
myComponent = component;
|
||||
myPoint = point;
|
||||
myTipComponent = tipComponent;
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.ApplicationComponent;
|
||||
import com.intellij.openapi.ui.popup.BalloonBuilder;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
@@ -31,7 +32,9 @@ import com.intellij.ui.HintHint;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.IJSwingUtilities;
|
||||
import com.intellij.util.containers.ComparatorUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.util.ui.update.ComparableObjectCheck;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -72,7 +75,7 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener
|
||||
|
||||
private IdeTooltip myCurrentTooltip;
|
||||
private Runnable myShowRequest;
|
||||
|
||||
private IdeTooltip myQueuedTooltip;
|
||||
|
||||
|
||||
public IdeTooltipManager(JBPopupFactory popupFactory) {
|
||||
@@ -151,7 +154,7 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener
|
||||
}
|
||||
|
||||
private void queueShow(final JComponent c, final MouseEvent me, final boolean toCenter) {
|
||||
final IdeTooltip tooltip = new IdeTooltip(c, me.getPoint(), null) {
|
||||
final IdeTooltip tooltip = new IdeTooltip(c, me.getPoint(), null, new Object()) {
|
||||
@Override
|
||||
protected boolean beforeShow() {
|
||||
myCurrentEvent = me;
|
||||
@@ -179,6 +182,7 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener
|
||||
hideCurrent(null);
|
||||
|
||||
myQueuedComponent = tooltip.getComponent();
|
||||
myQueuedTooltip = tooltip;
|
||||
|
||||
myShowRequest = new Runnable() {
|
||||
@Override
|
||||
@@ -265,6 +269,7 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener
|
||||
myCurrentTooltip = tooltip;
|
||||
myShowRequest = null;
|
||||
myQueuedComponent = null;
|
||||
myQueuedTooltip = null;
|
||||
|
||||
myCurrentTipUi.show(new RelativePoint(tooltip.getComponent(), effectivePoint), tooltip.getPreferredPosition());
|
||||
myAlarm.addRequest(new Runnable() {
|
||||
@@ -328,6 +333,7 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener
|
||||
private boolean hideCurrent(@Nullable MouseEvent me) {
|
||||
myShowRequest = null;
|
||||
myQueuedComponent = null;
|
||||
myQueuedTooltip = null;
|
||||
|
||||
if (myCurrentTooltip == null) return true;
|
||||
|
||||
@@ -378,6 +384,7 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener
|
||||
myCurrentTipUi = null;
|
||||
myCurrentComponent = null;
|
||||
myQueuedComponent = null;
|
||||
myQueuedTooltip = null;
|
||||
myCurrentEvent = null;
|
||||
myCurrentTipIsCentered = false;
|
||||
myX = -1;
|
||||
@@ -538,4 +545,8 @@ public class IdeTooltipManager implements ApplicationComponent, AWTEventListener
|
||||
public String getComponentName() {
|
||||
return "IDE Tooltip Manager";
|
||||
}
|
||||
|
||||
public boolean isQueuedToShow(IdeTooltip tooltip) {
|
||||
return Comparing.equal(myQueuedTooltip, tooltip);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,8 +20,8 @@ import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
|
||||
public class OtherGroup extends DefaultActionGroup implements DumbAware {
|
||||
public OtherGroup() {
|
||||
public class NonEmptyActionGroup extends DefaultActionGroup implements DumbAware {
|
||||
public NonEmptyActionGroup() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -17,20 +17,24 @@ package com.intellij.ide.dnd;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.ui.awt.RelativeRectangle;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class DnDEventImpl extends UserDataHolderBase implements Transferable, DnDEvent {
|
||||
private static final Logger LOG = Logger.getInstance("com.intellij.ide.dnd.DnDEventImpl");
|
||||
|
||||
private static DataFlavor ourDataFlavor;
|
||||
public static DataFlavor ourDataFlavor;
|
||||
private DnDTarget myDelegatedTarget;
|
||||
|
||||
static {
|
||||
@@ -93,17 +97,24 @@ public class DnDEventImpl extends UserDataHolderBase implements Transferable, Dn
|
||||
}
|
||||
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return new DataFlavor[]{ourDataFlavor};
|
||||
}
|
||||
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
return flavor.equals(ourDataFlavor);
|
||||
return new DataFlavor[]{ourDataFlavor, DataFlavor.javaFileListFlavor};
|
||||
}
|
||||
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
|
||||
if (flavor == DataFlavor.javaFileListFlavor) {
|
||||
if (myAttachedObject instanceof FileFlavorProvider) {
|
||||
return ((FileFlavorProvider)myAttachedObject).asFileList();
|
||||
}
|
||||
}
|
||||
return getAttachedObject();
|
||||
}
|
||||
|
||||
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
DataFlavor[] flavors = getTransferDataFlavors();
|
||||
return ArrayUtil.find(flavors, flavor) != -1;
|
||||
}
|
||||
|
||||
public boolean isDropPossible() {
|
||||
return myDropPossible;
|
||||
}
|
||||
@@ -285,4 +296,8 @@ public class DnDEventImpl extends UserDataHolderBase implements Transferable, Dn
|
||||
myHandlerComponent = null;
|
||||
myManager = null;
|
||||
}
|
||||
|
||||
public interface FileFlavorProvider {
|
||||
java.util.List<File> asFileList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,8 @@ public class TipUIUtil {
|
||||
|
||||
StringBuffer text = new StringBuffer(ResourceUtil.loadText(url));
|
||||
updateShortcuts(text);
|
||||
browser.read(new StringReader(text.toString()), null);
|
||||
String replaced = text.toString().replace("&productName;", ApplicationNamesInfo.getInstance().getFullProductName());
|
||||
browser.read(new StringReader(replaced), null);
|
||||
final Document document = browser.getDocument();
|
||||
if (document instanceof HTMLDocument) {
|
||||
((HTMLDocument)document).setBase(url);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user