libraryLicense(name: "JUnit", libraryName: "JUnit4", version: "4.11", license: "CPL 1.0", url: "http://junit.org/")
libraryLicense(name: "Log4j", libraryName: "Log4J", version: "1.2.17", license: "Apache 2.0", url: "http://logging.apache.org/log4j/1.2/index.html", licenseUrl: "http://logging.apache.org/license.html")
libraryLicense(name: "markdownj", libraryName: "markdownj", version: "0.4.2", license: "New BSD", url: "https://code.google.com/p/markdownj/", licenseUrl: "http://opensource.org/licenses/BSD-3-Clause")
+libraryLicense(name: "markdown4j", libraryName: "markdown4j-2.2", version: "2.2", license: "New BSD", url: "https://code.google.com/p/markdown4j/", licenseUrl: "http://opensource.org/licenses/BSD-3-Clause")
libraryLicense(name: "Maven", version: "2.2.1", license: "Apache 2.0", url: "http://maven.apache.org/", licenseUrl: "http://maven.apache.org/license.html")
libraryLicense(name: "plexus-util", version: "2.0.6", license: "Apache 2.0", url: "http://maven.apache.org/", libraryNames:['plexus-utils-2.0.6.jar'], licenseUrl: "http://apache.org/licenses/LICENSE-2.0")
libraryLicense(name: "plexus-archiver", libraryName: "plexus-archiver-2.4.4.jar", version: "2.4.4", license: "Apache 2.0", url: "http://plexus.codehaus.org/plexus-components/plexus-archiver", licenseUrl: "http://apache.org/licenses/LICENSE-2.0")
}
public void testPsiChangesWithLazyPointers() throws Exception {
- PsiClass aClass = myJavaFacade.findClass("AClass",GlobalSearchScope.allScope(getProject()));
+ PsiClass aClass = myJavaFacade.findClass("AClass", GlobalSearchScope.allScope(getProject()));
assertNotNull(aClass);
final SmartPsiElementPointer<PsiIdentifier> pointer =
assertNotNull(newSelect);
assertEquals("select", newSelect.getName());
}
+
+ public void testInXml2() {
+ final PsiFile file = configureByText(HtmlFileType.INSTANCE,
+ "<!DOCTYPE html>\n" +
+ "<html>\n" +
+ "<head>\n" +
+ " <title></title>\n" +
+ "</head>\n" +
+ "<body>\n" +
+ "<div class=\"cls\">\n" +
+ " <ul class=\"dropdown-menu\">\n" +
+ " <li><a href=\"#\">Action</a></li>\n" +
+ " <li><a href=\"#\">Another action</a></li>\n" +
+ " <li><a href=\"#\">Something else here</a></li>\n" +
+ " <li class=\"divider\"></li>\n" +
+ " <li class=\"dropdown-header\">Nav header</li>\n" +
+ " <li><a href=\"#\">Separated link</a></li>\n" +
+ " <li><a href=\"#\">One more separated link</a></li>\n" +
+ " </ul>\n" +
+ "<caret>\n" +
+ "</div>\n" +
+ "</body>\n" +
+ "</html>"
+ );
+
+ final XmlTag ul = PsiTreeUtil.getParentOfType(file.findElementAt(file.getText().indexOf("ul")), XmlTag.class);
+ assertNotNull(ul);
+ assertEquals("ul", ul.getName());
+ assertEquals("dropdown-menu", ul.getAttributeValue("class"));
+
+ final SmartPsiElementPointer<XmlTag> ulPointer = SmartPointerManager.getInstance(getProject()).createSmartPsiElementPointer(
+ ul);
+
+ WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
+ @Override
+ public void run() {
+ getEditor().getDocument().insertString(getEditor().getCaretModel().getOffset(), " <ul class=\"nav navbar-nav navbar-right\">\n" +
+ " <li><a href=\"../navbar/\">Default</a></li>\n" +
+ " <li class=\"active\"><a href=\"./\">Static top</a></li>\n" +
+ " <li><a href=\"../navbar-fixed-top/\">Fixed top</a></li>\n" +
+ " </ul>\n");
+ }
+ });
+
+ PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
+
+ final XmlTag newUl = ulPointer.getElement();
+ assertNotNull(newUl);
+ assertEquals("ul", newUl.getName());
+ assertEquals("dropdown-menu", newUl.getAttributeValue("class"));
+ }
+
public void testInsertImport() {
final PsiFile file = configureByText(JavaFileType.INSTANCE,
"class S {\n" +
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.extensions.PluginId;
-import com.intellij.openapi.project.ProjectType;
import com.intellij.openapi.util.ActionCallback;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
*/
public abstract AnAction getAction(@NonNls @NotNull String actionId);
- /**
- * Returns action associated with the specified actionId.
- *
- * @param actionId Id of the registered action
- *
- * @return Action associated with the specified actionId, <code>null</code> if
- * there is no actions associated with the specified actionId
- *
- * @exception java.lang.IllegalArgumentException if <code>actionId</code> is <code>null</code>
- *
- * @see com.intellij.openapi.actionSystem.IdeActions
- */
- public abstract AnAction getAction(@NonNls @NotNull String actionId, @Nullable ProjectType projectType);
-
/**
* Returns actionId associated with the specified action.
*
--- /dev/null
+/*
+ * Copyright 2000-2015 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.codeInsight.completion;
+
+import com.intellij.openapi.extensions.ExtensionPointName;
+import org.jetbrains.annotations.NotNull;
+
+public abstract class CompletionPreselectionBehaviourProvider {
+ public static ExtensionPointName<CompletionPreselectionBehaviourProvider> EP_NAME = ExtensionPointName.create("com.intellij.completion.completionBehaviourProvider");
+
+ public boolean shouldPreselectFirstSuggestion(@NotNull CompletionParameters parameters) {
+ return true;
+ }
+}
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.util.ProgressIndicatorBase;
return false;
}
+ if (Registry.is("ide.completion.lookup.element.preselect.depends.on.context")) {
+ for (CompletionPreselectionBehaviourProvider provider : Extensions.getExtensions(CompletionPreselectionBehaviourProvider.EP_NAME)) {
+ if (!provider.shouldPreselectFirstSuggestion(parameters)) {
+ return false;
+ }
+ }
+ }
+
if (!ApplicationManager.getApplication().isUnitTestMode()) {
return true;
}
logInitial(editor, startOffsets, endOffsets, indentSymbolsToStrip, firstLineStartOffset);
CharSequence text = editor.getDocument().getCharsSequence();
EditorColorsScheme schemeToUse = settings.getColorsScheme(editor.getColorsScheme());
- EditorHighlighter highlighter = HighlighterFactory.createHighlighter(file.getVirtualFile(), schemeToUse, file.getProject());
+ EditorHighlighter highlighter = HighlighterFactory.createHighlighter(file.getViewProvider().getVirtualFile(),
+ schemeToUse, file.getProject());
highlighter.setText(text);
MarkupModel markupModel = DocumentMarkupModel.forDocument(editor.getDocument(), file.getProject(), false);
Context context = new Context(text, schemeToUse, indentSymbolsToStrip);
@Override
public AnAction getAction(@NotNull String id) {
- return getActionImpl(id, false, null);
+ return getActionImpl(id, false);
}
- @Override
- public AnAction getAction(@NonNls @NotNull String actionId, @Nullable ProjectType projectType) {
- return getActionImpl(actionId, false, projectType);
- }
-
- private AnAction getActionImpl(String id, boolean canReturnStub, ProjectType projectType) {
+ private AnAction getActionImpl(String id, boolean canReturnStub) {
synchronized (myLock) {
- AnAction action;
- Object o = myId2Action.get(id);
- if (o == null) {
- return null;
- }
- if (o instanceof AnAction) {
- action = (AnAction)o;
- }
- else {
- //noinspection unchecked
- action = ((Map<ProjectType, AnAction>)o).get(projectType);
- }
+ AnAction action = myId2Action.get(id);
if (!canReturnStub && action instanceof ActionStub) {
action = convert((ActionStub)action);
}
@Override
public boolean isGroup(@NotNull String actionId) {
- return getActionImpl(actionId, true, null) instanceof ActionGroup;
+ return getActionImpl(actionId, true) instanceof ActionGroup;
}
@Override
@Override
public AnAction getActionOrStub(String id) {
- return getActionImpl(id, true, null);
+ return getActionImpl(id, true);
}
/**
reportActionError(pluginId, actionName + ": attribute \"group-id\" should be defined");
return null;
}
- AnAction parentGroup = getActionImpl(groupId, true, null);
+ AnAction parentGroup = getActionImpl(groupId, true);
if (parentGroup == null) {
reportActionError(pluginId, actionName + ": group with id \"" + groupId + "\" isn't registered; action will be added to the \"Other\" group");
- parentGroup = getActionImpl(IdeActions.GROUP_OTHER_MENU, true, null);
+ parentGroup = getActionImpl(IdeActions.GROUP_OTHER_MENU, true);
}
if (!(parentGroup instanceof DefaultActionGroup)) {
reportActionError(pluginId, actionName + ": group with id \"" + groupId + "\" should be instance of " + DefaultActionGroup.class.getName() +
return null;
}
- AnAction action = getActionImpl(ref, true, null);
+ AnAction action = getActionImpl(ref, true);
if (action == null) {
if (!myNotRegisteredInternalActionIds.contains(ref)) {
import com.intellij.openapi.actionSystem.ex.AnActionListener;
import com.intellij.openapi.actionSystem.ex.CustomComponentAction;
import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.keymap.ex.KeymapManagerEx;
import com.intellij.openapi.project.DumbAwareRunnable;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.update.UiNotifyConnector;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.TestOnly;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
myAddSeparatorFirst = addSeparatorFirst;
myUpdater.updateActions(false, true);
}
+
+ @TestOnly
+ public Presentation getPresentation(AnAction action) {
+ return myPresentationFactory.getPresentation(action);
+ }
}
private void updateActions(boolean now, final boolean transparentOnly, final boolean forced) {
final Runnable updateRunnable = new MyUpdateRunnable(this, transparentOnly, forced);
+ final Application app = ApplicationManager.getApplication();
- if (now) {
+ if (now || app.isUnitTestMode()) {
updateRunnable.run();
}
else {
- final Application app = ApplicationManager.getApplication();
final IdeFocusManager fm = IdeFocusManager.getInstance(null);
- if (!app.isUnitTestMode() && !app.isHeadlessEnvironment()) {
+ if (!app.isHeadlessEnvironment()) {
if (app.isDispatchThread()) {
fm.doWhenFocusSettlesDown(updateRunnable);
}
<with attribute="implementationClass" implements="com.intellij.codeInsight.completion.CompletionConfidence"/>
</extensionPoint>
+ <extensionPoint name="completion.completionBehaviourProvider"
+ interface="com.intellij.codeInsight.completion.CompletionPreselectionBehaviourProvider"/>
+
<extensionPoint name="completion.skip" interface="com.intellij.codeInsight.completion.CompletionPreselectSkipper"/>
<extensionPoint name="lookup.charFilter" interface="com.intellij.codeInsight.lookup.CharFilter"/>
<extensionPoint name="lookup.actionProvider" interface="com.intellij.codeInsight.lookup.LookupActionProvider"/>
package com.intellij.openapi.editor.richcopy;
import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.editor.LogicalPosition;
-import com.intellij.openapi.editor.SelectionModel;
+import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.impl.DocumentImpl;
import com.intellij.openapi.editor.richcopy.model.ColorRegistry;
import com.intellij.openapi.editor.richcopy.model.MarkupHandler;
import com.intellij.openapi.editor.richcopy.model.SyntaxInfo;
+import com.intellij.openapi.fileEditor.FileDocumentManager;
+import com.intellij.openapi.fileTypes.FileType;
+import com.intellij.openapi.fileTypes.FileTypeRegistry;
import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiFileFactory;
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
import com.intellij.ui.JBColor;
-import junit.framework.TestCase;
/**
* @author Denis Zhdanov
"\n" +
"text=}\n";
- TestCase.assertEquals(expected, getSyntaxInfo());
+ verifySyntaxInfo(expected);
selectionModel.setSelection(selectionStart - 2, selectionEnd);
- TestCase.assertEquals(expected, getSyntaxInfo());
+ verifySyntaxInfo(expected);
selectionModel.setSelection(selectionStart - 4, selectionEnd);
- TestCase.assertEquals(expected, getSyntaxInfo());
+ verifySyntaxInfo(expected);
}
public void testIncorrectFirstLineCalculationOffset() {
"\n" +
"text=}\n");
}
+
+ public void testNonPhysicalFile() throws Exception {
+ String fileName = "Test.java";
+ FileType fileType = FileTypeRegistry.getInstance().getFileTypeByFileName(fileName);
+ PsiFile psiFile = PsiFileFactory.getInstance(getProject()).createFileFromText(fileName, fileType, "class Test {}", 0, false);
+ VirtualFile virtualFile = psiFile.getViewProvider().getVirtualFile();
+ Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
+ assertNotNull(document);
+ EditorFactory editorFactory = EditorFactory.getInstance();
+ Editor editor = editorFactory.createViewer(document, getProject());
+ try {
+ editor.getSelectionModel().setSelection(0, document.getTextLength());
+ String syntaxInfo = getSyntaxInfo(editor, psiFile);
+ assertEquals("foreground=java.awt.Color[r=0,g=0,b=128],fontStyle=1,text=class \n" +
+ "foreground=java.awt.Color[r=0,g=0,b=0],fontStyle=0,text=Test {}\n", syntaxInfo);
+ }
+ finally {
+ editorFactory.releaseEditor(editor);
+ }
+ }
private String getSyntaxInfo() {
+ return getSyntaxInfo(myFixture.getEditor(), myFixture.getFile());
+ }
+
+ private static String getSyntaxInfo(Editor editor, PsiFile psiFile) {
final StringBuilder builder = new StringBuilder();
- final Editor editor = myFixture.getEditor();
- String selectedText = editor.getSelectionModel().getSelectedText(true);
+ SelectionModel selectionModel = editor.getSelectionModel();
+ String selectedText = selectionModel.getSelectedText(true);
assertNotNull(selectedText);
final String text = StringUtil.convertLineSeparators(selectedText);
final ColorRegistry colorRegistry = syntaxInfo.getColorRegistry();
assertEquals(JBColor.BLACK, colorRegistry.dataById(syntaxInfo.getDefaultForeground()));
assertEquals(JBColor.WHITE, colorRegistry.dataById(syntaxInfo.getDefaultBackground()));
- assertEquals((float)getFontSize(), syntaxInfo.getFontSize(), 0.01f);
+ assertEquals((float)editor.getColorsScheme().getEditorFontSize(), syntaxInfo.getFontSize(), 0.01f);
syntaxInfo.processOutputInfo(new MarkupHandler() {
@Override
public void handleText(int startOffset, int endOffset) throws Exception {
});
}
};
- SelectionModel selectionModel = editor.getSelectionModel();
- processor.collectTransferableData(myFixture.getFile(), editor, selectionModel.getBlockSelectionStarts(), selectionModel.getBlockSelectionEnds());
+ processor.collectTransferableData(psiFile, editor, selectionModel.getBlockSelectionStarts(), selectionModel.getBlockSelectionEnds());
return builder.toString();
}
assertEquals(info, getSyntaxInfo());
}
- private int getFontSize() {
- return myFixture.getEditor().getColorsScheme().getEditorFontSize();
- }
-
@Override
protected boolean isWriteActionRequired() {
return false;
this(DataManager.getInstance().getDataContext(), action);
}
+ public TestActionEvent(Presentation presentation) {
+ super(null, DataManager.getInstance().getDataContext(), "", presentation, ActionManager.getInstance(), 0);
+ }
+
public TestActionEvent() {
super(null, DataManager.getInstance().getDataContext(), "", new Presentation(), ActionManager.getInstance(), 0);
}
ide.completion.middle.matching=true
ide.completion.middle.matching.description=Suggest items in completion that contain the entered string somewhere in the middle.
+
+ide.completion.lookup.element.preselect.depends.on.context=true
+ide.completion.lookup.element.preselect.depends.on.context.description=Preselection of the first element in completion list depends on context
+
ide.goto.middle.matching=true
ide.goto.middle.matching.description=Suggest items in goto actions that contain the entered string somewhere in the middle.
ide.goto.rebuild.delay=0
*/
package com.intellij.tasks;
-import com.intellij.openapi.actionSystem.AnAction;
-import com.intellij.openapi.actionSystem.Presentation;
+import com.intellij.ide.ui.customization.CustomActionsSchema;
+import com.intellij.openapi.actionSystem.*;
+import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl;
import com.intellij.tasks.actions.SwitchTaskCombo;
import com.intellij.tasks.config.TaskSettings;
import com.intellij.testFramework.IdeaTestCase;
public void testTaskComboVisible() throws Exception {
- TaskManager manager = TaskManager.getManager(getProject());
- SwitchTaskCombo combo = new SwitchTaskCombo();
+ SwitchTaskCombo combo = null;
+ ActionGroup group = (ActionGroup)CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_MAIN_TOOLBAR);
+ ActionToolbarImpl toolbar = (ActionToolbarImpl)ActionManager.getInstance().createActionToolbar(ActionPlaces.MAIN_TOOLBAR, group, true);
+ AnAction[] children = group.getChildren(new TestActionEvent());
+ for (AnAction child : children) {
+ if (child instanceof ActionGroup) {
+ AnAction[] actions = ((ActionGroup)child).getChildren(new TestActionEvent());
+ for (AnAction action : actions) {
+ if (action instanceof SwitchTaskCombo) {
+ combo = (SwitchTaskCombo)action;
+ }
+ }
+ }
+ }
+ TaskManager manager = TaskManager.getManager(getProject());
LocalTask defaultTask = manager.getActiveTask();
assertTrue(defaultTask.isDefault());
assertEquals(defaultTask.getCreated(), defaultTask.getUpdated());
- Presentation presentation = doTest(combo);
+ Presentation presentation = doTest(combo, toolbar);
assertFalse(presentation.isVisible());
try {
TaskSettings.getInstance().ALWAYS_DISPLAY_COMBO = true;
- presentation = doTest(combo);
+ presentation = doTest(combo, toolbar);
assertTrue(presentation.isVisible());
}
finally {
LocalTask task = manager.createLocalTask("test");
manager.activateTask(task, false);
- presentation = doTest(combo);
+ presentation = doTest(combo, toolbar);
assertTrue(presentation.isVisible());
manager.activateTask(defaultTask, false);
task = manager.getActiveTask();
assertTrue(task.isDefault());
- presentation = doTest(combo);
+ presentation = doTest(combo, toolbar);
if (!presentation.isVisible()) {
LocalTask activeTask = manager.getActiveTask();
System.out.println(activeTask);
}
}
- private static Presentation doTest(AnAction action) {
- TestActionEvent event = new TestActionEvent(action);
+ private static Presentation doTest(AnAction action, ActionToolbarImpl toolbar) {
+ TestActionEvent event = new TestActionEvent(toolbar.getPresentation(action));
action.update(event);
return event.getPresentation();
}