Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
Bas Leijdekkers
2009-12-03 09:04:08 +01:00
9 changed files with 129 additions and 62 deletions
@@ -42,7 +42,7 @@ public abstract class IntentionManager {
*/
@Deprecated
public static IntentionManager getInstance(Project project) {
return ServiceManager.getService(IntentionManager.class);
return getInstance();
}
public static IntentionManager getInstance() {
@@ -54,15 +54,25 @@ public abstract class IntentionManager {
*
* @param action the intention action to register.
*/
public abstract void addAction(IntentionAction action);
public abstract void addAction(@NotNull IntentionAction action);
/**
* Returns all registered intention actions.
*
* @return array of registered actions.
*/
@NotNull
public abstract IntentionAction[] getIntentionActions();
/**
* Returns all registered intention actions which are available now
* (not disabled via Settings|Intentions or Alt-Enter|Disable intention quick fix)
*
* @return array of actions.
*/
@NotNull
public abstract IntentionAction[] getAvailableIntentionActions();
/**
* Registers an intention action which can be enabled or disabled through the "Intention
* Settings" dialog. To provide the description and the example code for the intention,
@@ -79,25 +89,32 @@ public abstract class IntentionManager {
* @param category the name of the category or categories under which the intention will be shown
* in the "Intention Settings" dialog.
*/
public abstract void registerIntentionAndMetaData(IntentionAction action, String... category);
public abstract void registerIntentionAndMetaData(@NotNull IntentionAction action, @NotNull String... category);
/**
* @deprecated custom directory name causes problem with internationalization of inspection descriptions.
* @deprecated custom directory name causes problem with internationalization of intention descriptions.
* Register intention class via extension point {@link IntentionManager.EP_INTENTION_ACTIONS} instead.
*/
@Deprecated
public abstract void registerIntentionAndMetaData(IntentionAction action, String[] category, String descriptionDirectoryName);
public abstract void registerIntentionAndMetaData(@NotNull IntentionAction action,
@NotNull String[] category,
@NotNull String descriptionDirectoryName);
public abstract void registerIntentionAndMetaData(IntentionAction action, String[] category,
String description, String exampleFileExtension,
String[] exampleTextBefore, String[] exampleTextAfter);
public abstract void registerIntentionAndMetaData(@NotNull IntentionAction action,
@NotNull String[] category,
@NotNull String description,
@NotNull String exampleFileExtension,
@NotNull String[] exampleTextBefore,
@NotNull String[] exampleTextAfter);
public abstract void unregisterIntention(IntentionAction intentionAction);
public abstract void unregisterIntention(@NotNull IntentionAction intentionAction);
/**
* @return actions used as additional options for the given problem.
* E.g. actions for suppress the problem via comment, javadoc or annotation,
* and edit corresponding inspection settings.
*/
@NotNull
public abstract List<IntentionAction> getStandardIntentionOptions(@NotNull HighlightDisplayKey displayKey, @NotNull PsiElement context);
/**
@@ -105,5 +122,6 @@ public abstract class IntentionManager {
* @param action action to convert.
* @return quick fix instance.
*/
public abstract LocalQuickFix convertToFix(IntentionAction action);
@NotNull
public abstract LocalQuickFix convertToFix(@NotNull IntentionAction action);
}
@@ -190,7 +190,7 @@ public class ShowIntentionsPass extends TextEditorHighlightingPass {
int offset = editor.getCaretModel().getOffset();
Project project = psiFile.getProject();
for (IntentionAction action : IntentionManager.getInstance().getIntentionActions()) {
for (IntentionAction action : IntentionManager.getInstance().getAvailableIntentionActions()) {
Pair<PsiFile,Editor> place = ShowIntentionActionsHandler.availableFor(psiFile, editor, action, psiElement);
if (place != null) {
List<IntentionAction> enableDisableIntentionAction = new ArrayList<IntentionAction>();
@@ -108,7 +108,7 @@ public class IntentionManagerImpl extends IntentionManager {
return new IntentionActionWrapper(intentionActionBean,categories);
}
public void registerIntentionAndMetaData(IntentionAction action, String... category) {
public void registerIntentionAndMetaData(@NotNull IntentionAction action, @NotNull String... category) {
registerIntentionAndMetaData(action, category, getDescriptionDirectoryName(action));
}
@@ -132,12 +132,12 @@ public class IntentionManagerImpl extends IntentionManager {
mySettings.registerIntentionMetaData(action, category, descriptionDirectoryName);
}
public void registerIntentionAndMetaData(final IntentionAction action,
final String[] category,
final String description,
final String exampleFileExtension,
final String[] exampleTextBefore,
final String[] exampleTextAfter) {
public void registerIntentionAndMetaData(@NotNull final IntentionAction action,
@NotNull final String[] category,
@NotNull final String description,
@NotNull final String exampleFileExtension,
@NotNull final String[] exampleTextBefore,
@NotNull final String[] exampleTextAfter) {
addAction(action);
IntentionActionMetaData metaData = new IntentionActionMetaData(action, category,
@@ -148,19 +148,20 @@ public class IntentionManagerImpl extends IntentionManager {
}
@Override
public void unregisterIntention(IntentionAction intentionAction) {
public void unregisterIntention(@NotNull IntentionAction intentionAction) {
myActions.remove(intentionAction);
mySettings.unregisterMetaData(intentionAction);
}
private static TextDescriptor[] mapToDescriptors(String[] texts, String fileName) {
private static TextDescriptor[] mapToDescriptors(String[] texts, @NonNls String fileName) {
TextDescriptor[] result = new TextDescriptor[texts.length];
for (int i = 0; i < texts.length; i++) {
result [i] = new PlainTextDescriptor(texts [i], fileName);
result [i] = new PlainTextDescriptor(texts[i], fileName);
}
return result;
}
@NotNull
public List<IntentionAction> getStandardIntentionOptions(@NotNull final HighlightDisplayKey displayKey, @NotNull final PsiElement context) {
List<IntentionAction> options = new ArrayList<IntentionAction>(9);
options.add(new EditInspectionToolsSettingsAction(displayKey));
@@ -169,7 +170,8 @@ public class IntentionManagerImpl extends IntentionManager {
return options;
}
public LocalQuickFix convertToFix(final IntentionAction action) {
@NotNull
public LocalQuickFix convertToFix(@NotNull final IntentionAction action) {
if (action instanceof LocalQuickFix) {
return (LocalQuickFix)action;
}
@@ -196,12 +198,24 @@ public class IntentionManagerImpl extends IntentionManager {
};
}
public void addAction(IntentionAction action) {
public void addAction(@NotNull IntentionAction action) {
myActions.add(action);
}
@NotNull
public IntentionAction[] getIntentionActions() {
return myActions.toArray(new IntentionAction[myActions.size()]);
}
@NotNull
@Override
public IntentionAction[] getAvailableIntentionActions() {
List<IntentionAction> list = new ArrayList<IntentionAction>(myActions.size());
for (IntentionAction action : myActions) {
if (mySettings.isEnabled(action)) {
list.add(action);
}
}
return list.toArray(new IntentionAction[list.size()]);
}
}
@@ -16,6 +16,9 @@
package com.intellij.codeInsight.intention.impl.config;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
/**
@@ -25,15 +28,17 @@ public class PlainTextDescriptor implements TextDescriptor {
private final String myText;
private final String myFileName;
public PlainTextDescriptor(final String text, final String fileName) {
public PlainTextDescriptor(@NotNull String text, @NonNls @NotNull String fileName) {
myText = text;
myFileName = fileName;
}
@NotNull
public String getText() throws IOException {
return myText;
}
@NotNull
public String getFileName() {
return myFileName;
}
@@ -597,9 +597,9 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Expo
return getTemplateFromManager(templateName, myJ2eeTemplatesManager);
}
private FileTemplate getTemplateFromManager(@NotNull @NonNls String templateName, @NotNull FileTemplateManagerImpl templatesManager) {
private static FileTemplate getTemplateFromManager(@NotNull @NonNls String templateName, @NotNull FileTemplateManagerImpl templatesManager) {
String name = templateName;
String extension = myTypeManager.getExtension(name);
String extension = templatesManager.myTypeManager.getExtension(name);
if (extension.length() > 0) {
name = name.substring(0, name.length() - extension.length() - 1);
}
@@ -612,24 +612,39 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Expo
else {
if (ApplicationManager.getApplication().isUnitTestMode() && templateName.endsWith("ForTest")) return null;
String message = templateNotFound(templateName, templatesManager);
String message = templatesManager.templateNotFoundMessage(templateName);
LOG.error(message);
}
return null;
}
private static String templateNotFound(String templateName, FileTemplateManagerImpl templatesManager) {
Collection<VirtualFile> defaultTemplates = templatesManager.getDefaultTemplates();
private String templateNotFoundMessage(String templateName) {
Collection<VirtualFile> defaultTemplates = getDefaultTemplates();
@NonNls String message =
"Unable to find template '" + templateName + "' in " + templatesManager + " in '"+templatesManager.myDefaultTemplatesDir+"'" +
"\n" +
"Default templates are: ";
message += StringUtil.join(defaultTemplates, new Function<VirtualFile, String>() {
"Unable to find template '" + templateName + "' in " + this +
"\n Default templates are: " + toString(defaultTemplates);
message+= "\n Default template dir: '"+ myDefaultTemplatesDir+"'";
for (VirtualFile topDir : getTopTemplatesDir()) {
VirtualFile parentDir = myDefaultTemplatesDir.equals(".") ? topDir : topDir.findChild(myDefaultTemplatesDir);
if (parentDir == null) {
message += "\n No templates in '" + topDir.getPath() + "'";
}
else {
message += "\n " + parentDir.getPath() + ": " + toString(listDir(parentDir));
}
}
message += "\n Deleted templates: " + myDeletedTemplatesManager.DELETED_DEFAULT_TEMPLATES;
return message;
}
private static String toString(Collection<VirtualFile> defaultTemplates) {
return StringUtil.join(defaultTemplates, new Function<VirtualFile, String>() {
public String fun(VirtualFile virtualFile) {
return virtualFile.getPresentableUrl();
}
}, ",");
return message;
}, ", ");
}
@@ -722,7 +737,7 @@ public class FileTemplateManagerImpl extends FileTemplateManager implements Expo
if (file == null) {
String message = "";
for (FileTemplateManagerImpl child : ArrayUtil.append(myChildren,this)) {
message += templateNotFound(name, child) + "\n";
message += child.templateNotFoundMessage(name) + "\n";
}
LOG.error(message);
return null;
@@ -18,6 +18,7 @@ package com.intellij.refactoring.rename;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
@@ -77,6 +78,9 @@ public class RenameHandlerRegistry {
if (availableHandlers.size() == 1) return availableHandlers.values().iterator().next();
if (availableHandlers.size() > 1) {
final String[] strings = availableHandlers.keySet().toArray(new String[availableHandlers.keySet().size()]);
if (ApplicationManager.getApplication().isUnitTestMode()) {
return availableHandlers.get(strings[strings.length - 1]);
}
final HandlersChooser chooser = new HandlersChooser(PlatformDataKeys.PROJECT.getData(dataContext), strings);
chooser.show();
if (chooser.isOK()) {
@@ -61,30 +61,13 @@ public class LineTooltipRenderer implements TooltipRenderer {
//setup text
myText = myText.replaceAll(String.valueOf(UIUtil.MNEMONIC), "");
final boolean [] expanded = new boolean[] { myCurrentWidth > 0 && dressDescription(editor)};
final boolean expanded = myCurrentWidth > 0 && dressDescription(editor);
//pane
final JEditorPane pane = initPane(myText);
pane.setCaretPosition(0);
final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
final JComponent contentComponent = editor.getContentComponent();
// This listener makes hint transparent for mouse events. It means that hint is closed
// by MousePressed and this MousePressed goes into the underlying editor component.
pane.addMouseListener(new MouseAdapter() {
public void mouseReleased(final MouseEvent e) {
if (!myActiveLink) {
MouseEvent newMouseEvent = SwingUtilities.convertMouseEvent(e.getComponent(), e, contentComponent);
hintManager.hideAllHints();
contentComponent.dispatchEvent(newMouseEvent);
}
}
public void mouseExited(final MouseEvent e) {
if (!expanded[0]) {
hintManager.hideAllHints();
}
}
});
final JComponent editorComponent = editor.getComponent();
final JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
@@ -94,8 +77,8 @@ public class LineTooltipRenderer implements TooltipRenderer {
final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(pane);
scrollPane.setBorder(null);
int width = expanded[0] ? 3 * myCurrentWidth / 2 : pane.getPreferredSize().width;
int height = expanded[0] ? Math.max(pane.getPreferredSize().height, 150) : pane.getPreferredSize().height;
int width = expanded ? 3 * myCurrentWidth / 2 : pane.getPreferredSize().width;
int height = expanded ? Math.max(pane.getPreferredSize().height, 150) : pane.getPreferredSize().height;
if (alignToRight) {
p.x -= width;
@@ -166,7 +149,7 @@ public class LineTooltipRenderer implements TooltipRenderer {
return;
}
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (!expanded[0]) { // more -> less
if (!expanded) { // more -> less
for (final TooltipLinkHandlerEP handlerEP : Extensions.getExtensions(TooltipLinkHandlerEP.EP_NAME)) {
if (handlerEP.handleLink(e.getDescription(), editor, pane)) {
myText = convertTextOnLinkHandled(myText);
@@ -189,6 +172,25 @@ public class LineTooltipRenderer implements TooltipRenderer {
}
}
});
// This listener makes hint transparent for mouse events. It means that hint is closed
// by MousePressed and this MousePressed goes into the underlying editor component.
pane.addMouseListener(new MouseAdapter() {
public void mouseReleased(final MouseEvent e) {
if (!myActiveLink) {
MouseEvent newMouseEvent = SwingUtilities.convertMouseEvent(e.getComponent(), e, contentComponent);
hint.hide();
contentComponent.dispatchEvent(newMouseEvent);
}
}
public void mouseExited(final MouseEvent e) {
if (!expanded) {
hint.hide();
}
}
});
hintManager.showEditorHint(hint, editor, p,
HintManagerImpl.HIDE_BY_ANY_KEY | HintManagerImpl.HIDE_BY_TEXT_CHANGE | HintManagerImpl.HIDE_BY_OTHER_HINT |
HintManagerImpl.HIDE_BY_SCROLLING, 0, false);
@@ -260,9 +262,7 @@ public class LineTooltipRenderer implements TooltipRenderer {
final LineTooltipRenderer lineTooltipRenderer = (LineTooltipRenderer)o;
if (myText != null ? !myText.equals(lineTooltipRenderer.myText) : lineTooltipRenderer.myText != null) return false;
return true;
return myText == null ? lineTooltipRenderer.myText == null : myText.equals(lineTooltipRenderer.myText);
}
public int hashCode() {
@@ -226,4 +226,9 @@ public class LightweightHint extends UserDataHolderBase implements Hint {
hide();
}
}
@Override
public String toString() {
return getComponent().toString();
}
}
@@ -83,6 +83,7 @@ import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiManagerImpl;
import com.intellij.psi.impl.cache.impl.todo.TodoIndex;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.impl.source.PsiFileImpl;
import com.intellij.psi.impl.source.resolve.FileContextUtil;
@@ -1082,8 +1083,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
@NotNull
public static List<HighlightInfo> instantiateAndRun(PsiFile file, Editor editor, int[] toIgnore, boolean allowDirt) {
Project project = file.getProject();
FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, null);
assertTrue(!DumbServiceImpl.getInstance(project).isDumb());
ensureIndexesUpToDate(project);
FileStatusMap fileStatusMap = ((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project)).getFileStatusMap();
for (int ignoreId : toIgnore) {
fileStatusMap.markFileUpToDate(editor.getDocument(), file, ignoreId);
@@ -1111,6 +1111,12 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
}
}
private static void ensureIndexesUpToDate(Project project) {
FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, null);
FileBasedIndex.getInstance().ensureUpToDate(TodoIndex.NAME, project, null);
assertTrue(!DumbServiceImpl.getInstance(project).isDumb());
}
public String getTestDataPath() {
return myTestDataPath;
}