Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Jemerov
2012-07-03 12:59:23 +02:00
43 changed files with 771 additions and 248 deletions
@@ -628,7 +628,7 @@ public class JavaCompletionData extends JavaAwareCompletionData {
return false;
}
if (psiElement().withSuperParent(2, PsiConditionalExpression.class).accepts(position)) {
if (psiElement().withSuperParent(2, PsiConditionalExpression.class).andNot(psiElement().insideStarting(psiElement(PsiConditionalExpression.class))).accepts(position)) {
return false;
}
@@ -53,7 +53,7 @@ public class InheritanceUtil {
return isInheritorOrSelf(aClass, baseClass, checkDeep);
}
public static boolean processSupers(@Nullable PsiClass aClass, boolean includeSelf, Processor<PsiClass> superProcessor) {
public static boolean processSupers(@Nullable PsiClass aClass, boolean includeSelf, @NotNull Processor<PsiClass> superProcessor) {
if (aClass == null) return true;
if (includeSelf && !superProcessor.process(aClass)) return false;
@@ -61,7 +61,7 @@ public class InheritanceUtil {
return processSupers(aClass, superProcessor, new THashSet<PsiClass>());
}
private static boolean processSupers(@NotNull PsiClass aClass, Processor<PsiClass> superProcessor, Set<PsiClass> visited) {
private static boolean processSupers(@NotNull PsiClass aClass, @NotNull Processor<PsiClass> superProcessor, @NotNull Set<PsiClass> visited) {
if (!visited.add(aClass)) return true;
for (final PsiClass intf : aClass.getInterfaces()) {
@@ -82,11 +82,11 @@ public class InheritanceUtil {
return false;
}
public static boolean isInheritor(@Nullable PsiClass psiClass, final String baseClassName) {
public static boolean isInheritor(@Nullable PsiClass psiClass, @NotNull final String baseClassName) {
return isInheritor(psiClass, false, baseClassName);
}
public static boolean isInheritor(@Nullable PsiClass psiClass, final boolean strict, final String baseClassName) {
public static boolean isInheritor(@Nullable PsiClass psiClass, final boolean strict, @NotNull final String baseClassName) {
if (psiClass == null) {
return false;
}
@@ -105,21 +105,22 @@ public class InheritanceUtil {
* @param results
* @param includeNonProject
*/
public static void getSuperClasses(PsiClass aClass, Set<PsiClass> results, boolean includeNonProject) {
getSuperClassesOfList(aClass.getSuperTypes(), results, includeNonProject);
public static void getSuperClasses(@NotNull PsiClass aClass, @NotNull Set<PsiClass> results, boolean includeNonProject) {
getSuperClassesOfList(aClass.getSuperTypes(), results, includeNonProject, new THashSet<PsiClass>(), aClass.getManager());
}
public static void getSuperClassesOfList(PsiClassType[] types, Set<PsiClass> results,
boolean includeNonProject) {
private static void getSuperClassesOfList(@NotNull PsiClassType[] types,
@NotNull Set<PsiClass> results,
boolean includeNonProject,
@NotNull Set<PsiClass> visited,
@NotNull PsiManager manager) {
for (PsiClassType type : types) {
PsiClass resolved = type.resolve();
if (resolved != null) {
if (!results.contains(resolved)) {
if (includeNonProject || resolved.getManager().isInProject(resolved)) {
results.add(resolved);
}
getSuperClasses(resolved, results, includeNonProject);
if (resolved != null && visited.add(resolved)) {
if (includeNonProject || manager.isInProject(resolved)) {
results.add(resolved);
}
getSuperClassesOfList(resolved.getSuperTypes(), results, includeNonProject, visited, manager);
}
}
}
@@ -0,0 +1,5 @@
public class Util {
int goo() {
ret<caret>cond ? 1: 0;
}
}
@@ -92,6 +92,7 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
public void testNewInMethodRefs() throws Exception { doTest(false); }
public void testAbstractInInterface() throws Exception { doTest(1, "abstract"); }
public void testCharInAnnotatedParameter() throws Exception { doTest(1, "char"); }
public void testReturnInTernary() throws Exception { doTest(1, "return"); }
public void testTryInExpression() throws Exception {
configureByFile(BASE_PATH + "/" + getTestName(true) + ".java");
@@ -276,7 +276,7 @@ public class CompositeElement extends TreeElement {
final int len = getTextLength();
if (startStamp != myModificationsCount) {
throw new AssertionError("Tree changed while calculating text");
throw new AssertionError("Tree changed while calculating text. startStamp:"+startStamp+"; current:"+myModificationsCount+"; myHC:"+myHC+"; assertThreading:"+ASSERT_THREADING+"; Thread.holdsLock(START_OFFSET_LOCK):"+Thread.holdsLock(START_OFFSET_LOCK)+"; Thread.holdsLock(PSI_LOCK):"+Thread.holdsLock(PsiLock.LOCK));
}
char[] buffer = new char[len];
@@ -181,7 +181,8 @@ public class LowLevelSearchUtil {
}
public static int searchWord(@NotNull CharSequence text,
char[] textArray, int startOffset,
char[] textArray,
int startOffset,
int endOffset,
@NotNull StringSearcher searcher,
@Nullable ProgressIndicator progress) {
@@ -303,7 +303,7 @@ public abstract class PsiElementPattern<T extends PsiElement,Self extends PsiEle
});
}
public Self insideStarting(final ElementPattern<PsiElement> ancestor) {
public Self insideStarting(final ElementPattern<? extends PsiElement> ancestor) {
return with(new PatternCondition<PsiElement>("insideStarting") {
@Override
public boolean accepts(@NotNull PsiElement start, ProcessingContext context) {
@@ -304,7 +304,7 @@
</component>
</children>
</grid>
<grid id="7f3f5" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="7f3f5" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -339,9 +339,27 @@
</component>
<vspacer id="82d85">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="9558b" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="2006d" class="javax.swing.JCheckBox" binding="myCbShowQuickDocOnCheckBox" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/ApplicationBundle" key="checkbox.show.quick.doc.on.mouse.over"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="5df80" binding="myHighlightSettingsPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -21,8 +21,10 @@ import com.intellij.application.options.OptionsApplicabilityFilter;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass;
import com.intellij.codeInsight.documentation.QuickDocOnMouseOverManager;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
@@ -83,6 +85,7 @@ public class EditorOptionsPanel {
private JTextField myCustomSoftWrapIndent;
private JCheckBox myCbShowAllSoftWraps;
private JCheckBox myPreselectCheckBox;
private JCheckBox myCbShowQuickDocOnCheckBox;
private final ErrorHighlightingPanel myErrorHighlightingPanel = new ErrorHighlightingPanel();
private final MyConfigurable myConfigurable;
@@ -156,6 +159,7 @@ public class EditorOptionsPanel {
}
myCbEnsureBlankLineBeforeCheckBox.setSelected(editorSettings.isEnsureNewLineAtEOF());
myCbShowQuickDocOnCheckBox.setSelected(editorSettings.isShowQuickDocOnMouseOverElement());
// Advanced mouse
myCbEnableDnD.setSelected(editorSettings.isDndEnabled());
@@ -235,6 +239,12 @@ public class EditorOptionsPanel {
editorSettings.setEnsureNewLineAtEOF(myCbEnsureBlankLineBeforeCheckBox.isSelected());
if (myCbShowQuickDocOnCheckBox.isSelected() ^ editorSettings.isShowQuickDocOnMouseOverElement()) {
boolean enabled = myCbShowQuickDocOnCheckBox.isSelected();
editorSettings.setShowQuickDocOnMouseOverElement(enabled);
ServiceManager.getService(QuickDocOnMouseOverManager.class).setEnabled(enabled);
}
editorSettings.setDndEnabled(myCbEnableDnD.isSelected());
editorSettings.setWheelFontChangeEnabled(myCbEnableWheelFontChange.isSelected());
@@ -341,6 +351,7 @@ public class EditorOptionsPanel {
// Strip trailing spaces, ensure EOL on EOF on save
isModified |= !getStripTrailingSpacesValue().equals(editorSettings.getStripTrailingSpaces());
isModified |= isModified(myCbEnsureBlankLineBeforeCheckBox, editorSettings.isEnsureNewLineAtEOF());
isModified |= isModified(myCbShowQuickDocOnCheckBox, editorSettings.isShowQuickDocOnMouseOverElement());
// advanced mouse
isModified |= isModified(myCbEnableDnD, editorSettings.isDndEnabled());
@@ -146,7 +146,7 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr
}
{
enableEvents(KeyEvent.KEY_EVENT_MASK);
enableEvents(AWTEvent.KEY_EVENT_MASK);
}
protected void processKeyEvent(KeyEvent e) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -154,7 +154,20 @@ public class DocumentationManager extends DockablePopupManager<DocumentationComp
myUpdateDocAlarm = new Alarm(Alarm.ThreadToUse.OWN_THREAD,myProject);
}
public void showJavaDocInfo(@NotNull Editor editor,
@NotNull final PsiElement element,
@NotNull final PsiElement original,
@Nullable Runnable closeCallback)
{
myEditor = editor;
showJavaDocInfo(element, original, closeCallback);
}
public void showJavaDocInfo(@NotNull final PsiElement element, final PsiElement original) {
showJavaDocInfo(element, original, null);
}
public void showJavaDocInfo(@NotNull final PsiElement element, final PsiElement original, @Nullable Runnable closeCallback) {
PopupUpdateProcessor updateProcessor = new PopupUpdateProcessor(element.getProject()) {
public void updatePopup(Object lookupItemObject) {
if (lookupItemObject instanceof PsiElement) {
@@ -163,7 +176,7 @@ public class DocumentationManager extends DockablePopupManager<DocumentationComp
}
};
doShowJavaDocInfo(element, false, updateProcessor, original, false);
doShowJavaDocInfo(element, false, updateProcessor, original, false, closeCallback);
}
public void showJavaDocInfo(final Editor editor, @Nullable final PsiFile file, boolean requestFocus) {
@@ -251,7 +264,18 @@ public class DocumentationManager extends DockablePopupManager<DocumentationComp
}
private void doShowJavaDocInfo(final PsiElement element, boolean requestFocus, PopupUpdateProcessor updateProcessor,
final PsiElement originalElement, final boolean autoupdate) {
final PsiElement originalElement, final boolean autoupdate)
{
doShowJavaDocInfo(element, requestFocus, updateProcessor, originalElement, autoupdate, null);
}
private void doShowJavaDocInfo(final PsiElement element,
boolean requestFocus,
PopupUpdateProcessor updateProcessor,
final PsiElement originalElement,
final boolean autoupdate,
@Nullable final Runnable closeCallback)
{
Project project = getProject(element);
if (myToolWindow == null && PropertiesComponent.getInstance().isTrueValue(SHOW_DOCUMENTATION_IN_TOOL_WINDOW)) {
@@ -267,10 +291,12 @@ public class DocumentationManager extends DockablePopupManager<DocumentationComp
fetchDocInfo(getDefaultCollector(element, originalElement), component, true);
if (!myToolWindow.isVisible()) myToolWindow.show(null);
return;
} else {
}
else {
if (element != null && !autoupdate) {
restorePopupBehavior();
} else {
}
else {
return;
}
}
@@ -289,7 +315,7 @@ public class DocumentationManager extends DockablePopupManager<DocumentationComp
@Override
public void consume(PsiElement psiElement) {
final AbstractPopup jbPopup = (AbstractPopup)getDocInfoHint();
if(jbPopup != null) {
if (jbPopup != null) {
final String title = getTitle(psiElement, false);
jbPopup.setCaption(title);
}
@@ -304,7 +330,8 @@ public class DocumentationManager extends DockablePopupManager<DocumentationComp
};
final KeyboardShortcut keyboardShortcut = ActionManagerEx.getInstanceEx().getKeyboardShortcut("QuickJavaDoc");
final List<Pair<ActionListener, KeyStroke>> actions = Collections.singletonList(Pair.<ActionListener, KeyStroke>create(new ActionListener() {
final List<Pair<ActionListener, KeyStroke>> actions =
Collections.singletonList(Pair.<ActionListener, KeyStroke>create(new ActionListener() {
public void actionPerformed(ActionEvent e) {
createToolWindow(element, originalElement);
final JBPopup hint = getDocInfoHint();
@@ -314,63 +341,66 @@ public class DocumentationManager extends DockablePopupManager<DocumentationComp
boolean hasLookup = LookupManager.getActiveLookup(myEditor) != null;
final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component)
.setRequestFocusCondition(project, NotLookupOrSearchCondition.INSTANCE)
.setProject(project)
.addListener(updateProcessor)
.addUserData(updateProcessor)
.setKeyboardActions(actions)
.setDimensionServiceKey(myProject, JAVADOC_LOCATION_AND_SIZE, false)
.setResizable(true)
.setMovable(true)
.setRequestFocus(requestFocus)
.setCancelOnClickOutside(!hasLookup) // otherwise selecting lookup items by mouse would close the doc
.setTitle(getTitle(element, false))
.setCouldPin(pinCallback)
.setCancelCallback(new Computable<Boolean>() {
public Boolean compute() {
if (fromQuickSearch()) {
((ChooseByNameBase.JPanelProvider)myPreviouslyFocused.getParent()).unregisterHint();
}
Disposer.dispose(component);
myEditor = null;
myPreviouslyFocused = null;
myParameterInfoController = null;
return Boolean.TRUE;
}
})
.createPopup();
AbstractPopup oldHint = (AbstractPopup)getDocInfoHint();
if (oldHint != null) {
DocumentationComponent oldComponent = (DocumentationComponent)oldHint.getComponent();
PsiElement element1 = oldComponent.getElement();
if (Comparing.equal(element, element1)) {
if (requestFocus) {
component.getComponent().requestFocus();
.setRequestFocusCondition(project, NotLookupOrSearchCondition.INSTANCE)
.setProject(project)
.addListener(updateProcessor)
.addUserData(updateProcessor)
.setKeyboardActions(actions)
.setDimensionServiceKey(myProject, JAVADOC_LOCATION_AND_SIZE, false)
.setResizable(true)
.setMovable(true)
.setRequestFocus(requestFocus)
.setCancelOnClickOutside(!hasLookup) // otherwise selecting lookup items by mouse would close the doc
.setTitle(getTitle(element, false))
.setCouldPin(pinCallback)
.setCancelCallback(new Computable<Boolean>() {
public Boolean compute() {
if (closeCallback != null) {
closeCallback.run();
}
return;
if (fromQuickSearch()) {
((ChooseByNameBase.JPanelProvider)myPreviouslyFocused.getParent()).unregisterHint();
}
Disposer.dispose(component);
myEditor = null;
myPreviouslyFocused = null;
myParameterInfoController = null;
return Boolean.TRUE;
}
oldHint.cancel();
})
.createPopup();
AbstractPopup oldHint = (AbstractPopup)getDocInfoHint();
if (oldHint != null) {
DocumentationComponent oldComponent = (DocumentationComponent)oldHint.getComponent();
PsiElement element1 = oldComponent.getElement();
if (Comparing.equal(element, element1)) {
if (requestFocus) {
component.getComponent().requestFocus();
}
return;
}
oldHint.cancel();
}
component.setHint(hint);
component.setHint(hint);
if (myEditor == null) {
// subsequent invocation of javadoc popup from completion will have myEditor == null because of cancel invoked,
// so reevaluate the editor for proper popup placement
Lookup lookup = LookupManager.getInstance(myProject).getActiveLookup();
myEditor = lookup != null ? lookup.getEditor() : null;
}
fetchDocInfo(getDefaultCollector(element, originalElement), component);
if (myEditor == null) {
// subsequent invocation of javadoc popup from completion will have myEditor == null because of cancel invoked,
// so reevaluate the editor for proper popup placement
Lookup lookup = LookupManager.getInstance(myProject).getActiveLookup();
myEditor = lookup != null ? lookup.getEditor() : null;
}
fetchDocInfo(getDefaultCollector(element, originalElement), component);
myDocInfoHintRef = new WeakReference<JBPopup>(hint);
myPreviouslyFocused = WindowManagerEx.getInstanceEx().getFocusedComponent(project);
myDocInfoHintRef = new WeakReference<JBPopup>(hint);
myPreviouslyFocused = WindowManagerEx.getInstanceEx().getFocusedComponent(project);
if (fromQuickSearch()) {
((ChooseByNameBase.JPanelProvider)myPreviouslyFocused.getParent()).registerHint(hint);
}
if (fromQuickSearch()) {
((ChooseByNameBase.JPanelProvider)myPreviouslyFocused.getParent()).registerHint(hint);
}
}
private static String getTitle(@NotNull final PsiElement element, final boolean _short) {
@@ -392,13 +422,19 @@ public class DocumentationManager extends DockablePopupManager<DocumentationComp
@Nullable
public PsiElement findTargetElement(final Editor editor, @Nullable final PsiFile file, PsiElement contextElement) {
PsiElement element = editor != null ? TargetElementUtilBase.findTargetElement(editor, ourFlagsForTargetElements) : null;
return findTargetElement(editor, editor.getCaretModel().getOffset(), file, contextElement);
}
@Nullable
public PsiElement findTargetElement(final Editor editor, int offset, @Nullable final PsiFile file, PsiElement contextElement) {
TargetElementUtilBase util = TargetElementUtilBase.getInstance();
PsiElement element = editor != null ? util.findTargetElement(editor, ourFlagsForTargetElements, offset)
: null;
assertSameProject(element);
// Allow context doc over xml tag content
if (element != null || contextElement != null) {
final PsiElement adjusted = TargetElementUtilBase.getInstance()
.adjustElement(editor, ourFlagsForTargetElements, element, contextElement);
final PsiElement adjusted = util.adjustElement(editor, ourFlagsForTargetElements, element, contextElement);
if (adjusted != null) {
element = adjusted;
assertSameProject(element);
@@ -410,10 +446,10 @@ public class DocumentationManager extends DockablePopupManager<DocumentationComp
assertSameProject(element);
if (element == null) {
final PsiReference ref = TargetElementUtilBase.findReference(editor, editor.getCaretModel().getOffset());
final PsiReference ref = util.findReference(editor, offset);
if (ref != null) {
element = TargetElementUtilBase.getInstance().adjustReference(ref);
element = util.adjustReference(ref);
assertSameProject(element);
if (element == null && ref instanceof PsiPolyVariantReference) {
element = ref.getElement();
@@ -0,0 +1,269 @@
/*
* Copyright 2000-2012 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.documentation;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.event.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.ui.popup.PopupFactoryImpl;
import com.intellij.util.Alarm;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
/**
* Serves as a facade to the 'show quick doc on mouse over an element' functionality.
* <p/>
* Not thread-safe.
*
* @author Denis Zhdanov
* @since 7/2/12 9:09 AM
*/
public class QuickDocOnMouseOverManager {
private static final long QUICK_DOC_DELAY_MILLIS;
static {
long delay = 500;
String property = System.getProperty("editor.auto.quick.doc.delay.ms");
if (property != null) {
try {
long parsed = Long.parseLong(property);
if (parsed > 0) {
delay = parsed;
}
}
catch (Exception e) {
// Ignore.
}
}
QUICK_DOC_DELAY_MILLIS = delay;
}
@NotNull private final EditorMouseMotionListener myEditorListener = new MyEditorMouseListener();
@NotNull private final Alarm myAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);
@NotNull private final Runnable myRequest = new MyShowQuickDocRequest();
@NotNull private final Runnable myHintCloseCallback = new Runnable() {
@Override
public void run() {
myActiveElements.clear();
myDocumentationManager = null;
}
};
private final Map<Editor, PsiElement /** PSI element which is located under the current mouse position */> myActiveElements
= new HashMap<Editor, PsiElement>();
/** Holds a reference (if any) to the documentation manager used last time to show an 'auto quick doc' popup. */
@Nullable private WeakReference<DocumentationManager> myDocumentationManager;
@Nullable private DelayedQuickDocInfo myDelayedQuickDocInfo;
private boolean myEnabled;
public QuickDocOnMouseOverManager(@NotNull Application application) {
EditorFactory factory = EditorFactory.getInstance();
if (factory != null) {
factory.addEditorFactoryListener(new MyEditorFactoryListener(), application);
}
}
/**
* Instructs the manager to enable or disable 'show quick doc automatically when the mouse goes over an editor element' mode.
*
* @param enabled flag that identifies if quick doc should be automatically shown
*/
public void setEnabled(boolean enabled) {
myEnabled = enabled;
if (!enabled) {
closeAutoQuickDocComponentIfNecessary();
myAlarm.cancelAllRequests();
}
EditorFactory factory = EditorFactory.getInstance();
if (factory == null) {
return;
}
for (Editor editor : factory.getAllEditors()) {
if (enabled) {
editor.addEditorMouseMotionListener(myEditorListener);
}
else {
editor.removeEditorMouseMotionListener(myEditorListener);
}
}
}
private void processMouseMove(@NotNull EditorMouseEvent e) {
if (e.getArea() != EditorMouseEventArea.EDITING_AREA) {
// Skip if the mouse is not at the editing area.
closeAutoQuickDocComponentIfNecessary();
return;
}
Editor editor = e.getEditor();
Project project = editor.getProject();
if (project == null) {
return;
}
DocumentationManager documentationManager = DocumentationManager.getInstance(project);
JBPopup hint = documentationManager.getDocInfoHint();
if (hint != null) {
// Skip the event if the control is shown because of explicit 'show quick doc' action call.
WeakReference<DocumentationManager> ref = myDocumentationManager;
if (ref == null || ref.get() == null) {
return;
}
// Skip the event if the mouse is under the opened quick doc control.
Point hintLocation = hint.getLocationOnScreen();
Dimension hintSize = hint.getSize();
int mouseX = e.getMouseEvent().getXOnScreen();
int mouseY = e.getMouseEvent().getYOnScreen();
if (mouseX >= hintLocation.x && mouseX <= hintLocation.x + hintSize.width && mouseY >= hintLocation.y
&& mouseY <= hintLocation.y + hintSize.height)
{
return;
}
}
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (psiFile == null) {
closeAutoQuickDocComponentIfNecessary();
return;
}
int mouseOffset = editor.logicalPositionToOffset(editor.xyToLogicalPosition(e.getMouseEvent().getPoint()));
PsiElement elementUnderMouse = psiFile.findElementAt(mouseOffset);
if (elementUnderMouse == null || elementUnderMouse instanceof PsiWhiteSpace) {
closeAutoQuickDocComponentIfNecessary();
return;
}
PsiElement targetElementUnderMouse = documentationManager.findTargetElement(editor, mouseOffset, psiFile, elementUnderMouse);
if (targetElementUnderMouse == null) {
// No PSI element is located under the current mouse position - close quick doc if any.
closeAutoQuickDocComponentIfNecessary();
return;
}
PsiElement activeElement = myActiveElements.get(editor);
if (targetElementUnderMouse.equals(activeElement)
&& (myAlarm.getActiveRequestCount() > 0 // Request to show documentation for the target component has been already queued.
|| hint != null)) // Documentation for the target component is being shown.
{
return;
}
closeAutoQuickDocComponentIfNecessary();
myActiveElements.put(editor, targetElementUnderMouse);
myDelayedQuickDocInfo = new DelayedQuickDocInfo(documentationManager, editor, targetElementUnderMouse, elementUnderMouse);
myAlarm.cancelAllRequests();
myAlarm.addRequest(myRequest, QUICK_DOC_DELAY_MILLIS);
}
private void closeAutoQuickDocComponentIfNecessary() {
myAlarm.cancelAllRequests();
WeakReference<DocumentationManager> ref = myDocumentationManager;
if (ref == null) {
return;
}
DocumentationManager docManager = ref.get();
if (docManager == null) {
return;
}
JBPopup hint = docManager.getDocInfoHint();
if (hint == null) {
return;
}
hint.cancel();
}
private static class DelayedQuickDocInfo {
@NotNull public final DocumentationManager docManager;
@NotNull public final Editor editor;
@NotNull public final PsiElement targetElement;
@NotNull public final PsiElement originalElement;
private DelayedQuickDocInfo(@NotNull DocumentationManager docManager,
@NotNull Editor editor, @NotNull PsiElement targetElement,
@NotNull PsiElement originalElement)
{
this.docManager = docManager;
this.editor = editor;
this.targetElement = targetElement;
this.originalElement = originalElement;
}
}
private class MyShowQuickDocRequest implements Runnable {
@Override
public void run() {
myAlarm.cancelAllRequests();
DelayedQuickDocInfo info = myDelayedQuickDocInfo;
if (info == null || !info.targetElement.equals(myActiveElements.get(info.editor))) {
return;
}
info.editor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION,
info.editor.offsetToVisualPosition(info.originalElement.getTextRange().getStartOffset()));
try {
info.docManager.showJavaDocInfo(info.editor, info.targetElement, info.originalElement, myHintCloseCallback);
myDocumentationManager = new WeakReference<DocumentationManager>(info.docManager);
}
finally {
info.editor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, null);
}
}
}
private class MyEditorFactoryListener implements EditorFactoryListener {
@Override
public void editorCreated(@NotNull EditorFactoryEvent event) {
if (myEnabled) {
event.getEditor().addEditorMouseMotionListener(myEditorListener);
}
}
@Override
public void editorReleased(@NotNull EditorFactoryEvent event) {
event.getEditor().removeEditorMouseMotionListener(myEditorListener);
}
}
private class MyEditorMouseListener extends EditorMouseMotionAdapter {
@Override
public void mouseMoved(EditorMouseEvent e) {
processMouseMove(e);
}
}
}
@@ -0,0 +1,35 @@
/*
* Copyright 2000-2012 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.documentation;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
/**
* @author Denis Zhdanov
* @since 7/2/12 9:44 AM
*/
public class QuickDocOnMouseOverStartupActivity implements StartupActivity {
@Override
public void runActivity(Project project) {
if (EditorSettingsExternalizable.getInstance().isShowQuickDocOnMouseOverElement()) {
ServiceManager.getService(QuickDocOnMouseOverManager.class).setEnabled(true);
}
}
}
@@ -244,9 +244,11 @@ public class LookupCellRenderer implements ListCellRenderer {
return getGrayedForeground(isSelected);
}
final Color tailForeground = presentation.getTailForeground();
if (tailForeground != null) {
return tailForeground;
if (!isSelected) {
final Color tailForeground = presentation.getTailForeground();
if (tailForeground != null) {
return tailForeground;
}
}
return defaultForeground;
@@ -362,8 +362,9 @@ public class ChooseRunConfigurationPopup {
return new ItemWrapper<RunnerAndConfigurationSettings>(settings) {
@Override
public void perform(@NotNull Project project, @NotNull Executor executor, @NotNull DataContext context) {
RunManagerEx.getInstanceEx(project).setSelectedConfiguration(getValue());
ProgramRunnerUtil.executeConfiguration(project, getValue(), executor);
RunnerAndConfigurationSettings config = getValue();
RunManagerEx.getInstanceEx(project).setSelectedConfiguration(config);
doRunConfiguration(config, executor, project);
}
@Override
@@ -470,7 +471,7 @@ public class ChooseRunConfigurationPopup {
@Override
public void perform(@NotNull final Project project, @NotNull final Executor executor, @NotNull DataContext context) {
ExecutionTargetManager.setActiveTarget(project, eachTarget);
ProgramRunnerUtil.executeConfiguration(project, selectedConfiguration, executor);
doRunConfiguration(selectedConfiguration, executor, project);
}
@Override
@@ -531,12 +532,7 @@ public class ChooseRunConfigurationPopup {
if (dialog.isOK()) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final RunnerAndConfigurationSettings configuration = RunManager.getInstance(project).getSelectedConfiguration();
if (configuration instanceof RunnerAndConfigurationSettingsImpl) {
if (canRun(executor, configuration)) {
ProgramRunnerUtil.executeConfiguration(project, configuration, executor);
}
}
doRunConfiguration(RunManager.getInstance(project).getSelectedConfiguration(), executor, project);
}
});
}
@@ -616,7 +612,7 @@ public class ChooseRunConfigurationPopup {
public void perform(@NotNull Project project, @NotNull Executor executor, @NotNull DataContext context) {
manager.setTemporaryConfiguration(configuration);
RunManagerEx.getInstanceEx(project).setSelectedConfiguration(configuration);
ProgramRunnerUtil.executeConfiguration(project, configuration, executor);
doRunConfiguration(configuration, executor, project);
}
@Override
@@ -729,6 +725,14 @@ public class ChooseRunConfigurationPopup {
}
}
private static void doRunConfiguration(RunnerAndConfigurationSettings configuration, Executor executor, Project project) {
if (configuration instanceof RunnerAndConfigurationSettingsImpl) {
if (canRun(executor, configuration)) {
ProgramRunnerUtil.executeConfiguration(project, configuration, executor);
}
}
}
private static final class ConfigurationActionsStep extends BaseListPopupStep<ActionWrapper> {
private ConfigurationActionsStep(@NotNull final Project project,
ChooseRunConfigurationPopup action,
@@ -761,7 +765,7 @@ public class ChooseRunConfigurationPopup {
manager.setSelectedConfiguration(settings);
ExecutionTargetManager.setActiveTarget(project, eachTarget);
ProgramRunnerUtil.executeConfiguration(project, settings, action.getCurrentExecutor(), eachTarget);
doRunConfiguration(settings, action.getCurrentExecutor(), project);
}
});
}
@@ -776,7 +780,7 @@ public class ChooseRunConfigurationPopup {
final RunManagerEx manager = RunManagerEx.getInstanceEx(project);
if (dynamic) manager.setTemporaryConfiguration(settings);
manager.setSelectedConfiguration(settings);
ProgramRunnerUtil.executeConfiguration(project, settings, executor);
doRunConfiguration(settings, executor, project);
}
});
isFirst = false;
@@ -280,7 +280,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider {
EmptyAction.registerActionShortcuts(myHistoryViewer.getComponent(), myConsoleEditor.getComponent());
}
private boolean isFullEditorMode() {
public boolean isFullEditorMode() {
return myPanel.getComponentCount() == 1;
}
@@ -124,7 +124,7 @@ public class InjectedLanguageManagerImpl extends InjectedLanguageManager impleme
public void startRunInjectors(@NotNull final Document hostDocument, final boolean synchronously) {
if (myProject.isDisposed()) return;
assert synchronously || !ApplicationManager.getApplication().isWriteAccessAllowed();
if (!synchronously && ApplicationManager.getApplication().isWriteAccessAllowed()) return;
// use cached to avoid recreate PSI in alien project
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
final PsiFile hostPsiFile = documentManager.getCachedPsiFile(hostDocument);
@@ -50,13 +50,15 @@ public class IndexingStamp {
private Timestamps(@Nullable DataInputStream stream) throws IOException {
if (stream != null) {
try {
long dominatingIndexStamp = DataInputOutputUtil.readTIME(stream);
while(stream.available() > 0) {
ID<?, ?> id = ID.findById(DataInputOutputUtil.readINT(stream));
if (id != null) {
long stamp = IndexInfrastructure.getIndexCreationStamp(id);
if (myIndexStamps == null) myIndexStamps = new TObjectLongHashMap<ID<?, ?>>(5, 0.98f);
if (stamp <= dominatingIndexStamp) myIndexStamps.put(id, stamp);
if (stream.available() > 0) {
long dominatingIndexStamp = DataInputOutputUtil.readTIME(stream);
while(stream.available() > 0) {
ID<?, ?> id = ID.findById(DataInputOutputUtil.readINT(stream));
if (id != null) {
long stamp = IndexInfrastructure.getIndexCreationStamp(id);
if (myIndexStamps == null) myIndexStamps = new TObjectLongHashMap<ID<?, ?>>(5, 0.98f);
if (stamp <= dominatingIndexStamp) myIndexStamps.put(id, stamp);
}
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -36,6 +36,7 @@ public abstract class EditorFactory implements ApplicationComponent {
*
* @return the editor factory instance.
*/
@Nullable
public static EditorFactory getInstance() {
final Application application = ApplicationManager.getApplication();
return application == null ? null : application.getComponent(EditorFactory.class);
@@ -168,7 +169,7 @@ public abstract class EditorFactory implements ApplicationComponent {
/**
* Registers a listener for receiving notifications when editor instances are created and released
* and removes the listener when {@link parentDisposable} get disposed.
* and removes the listener when the <code>'parentDisposable'</code> gets disposed.
*
* @param listener the listener instance.
* @param parentDisposable the Disposable which triggers the removal of the listener
@@ -176,7 +177,7 @@ public abstract class EditorFactory implements ApplicationComponent {
public abstract void addEditorFactoryListener(@NotNull EditorFactoryListener listener, @NotNull Disposable parentDisposable);
/**
* Unregisters a listener for receiving notifications when editor instances are created
* Un-registers a listener for receiving notifications when editor instances are created
* and released.
*
* @param listener the listener instance.
@@ -215,7 +215,7 @@ public class OpenFileDescriptor implements Navigatable {
}
}
private void unfoldCurrentLine(@NotNull final Editor editor) {
private static void unfoldCurrentLine(@NotNull final Editor editor) {
final FoldRegion[] allRegions = editor.getFoldingModel().getAllFoldRegions();
final int offset = editor.getCaretModel().getOffset();
int line = editor.getDocument().getLineNumber(offset);
@@ -226,7 +226,7 @@ public class OpenFileDescriptor implements Navigatable {
@Override
public void run() {
for (FoldRegion region : allRegions) {
if (!region.isExpanded() && range.intersects(TextRange.create(region))) /*region.getStartOffset() <= offset && offset <= region.getEndOffset()*/ {
if (!region.isExpanded() && range.intersects(TextRange.create(region))) {
region.setExpanded(true);
}
}
@@ -240,14 +240,15 @@ public class OpenFileDescriptor implements Navigatable {
@Override
public boolean canNavigate() {
return myProject != null;
return myFile.isValid();
}
@Override
public boolean canNavigateToSource() {
return myProject != null;
return canNavigate();
}
@NotNull
public Project getProject() {
return myProject;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -19,6 +19,7 @@ import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.components.ExportableApplicationComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces;
import com.intellij.openapi.options.OptionsBundle;
import com.intellij.openapi.util.DefaultJDOMExternalizer;
@@ -50,6 +51,7 @@ public class EditorSettingsExternalizable implements NamedJDOMExternalizable, Ex
public boolean IS_CARET_INSIDE_TABS;
@NonNls public String STRIP_TRAILING_SPACES = "Changed";
public boolean IS_ENSURE_NEWLINE_AT_EOF = false;
public boolean SHOW_QUICK_DOC_ON_MOUSE_OVER_ELEMENT = false;
public boolean IS_CARET_BLINKING = true;
public int CARET_BLINKING_PERIOD = 500;
public boolean IS_RIGHT_MARGIN_SHOWN = true;
@@ -356,7 +358,7 @@ public class EditorSettingsExternalizable implements NamedJDOMExternalizable, Ex
public void setEnsureNewLineAtEOF(boolean ensure) {
myOptions.IS_ENSURE_NEWLINE_AT_EOF = ensure;
}
public String getStripTrailingSpaces() {
return myOptions.STRIP_TRAILING_SPACES;
} // TODO: move to CodeEditorManager or something else
@@ -365,6 +367,14 @@ public class EditorSettingsExternalizable implements NamedJDOMExternalizable, Ex
myOptions.STRIP_TRAILING_SPACES = stripTrailingSpaces;
}
public boolean isShowQuickDocOnMouseOverElement() {
return myOptions.SHOW_QUICK_DOC_ON_MOUSE_OVER_ELEMENT;
}
public void setShowQuickDocOnMouseOverElement(boolean show) {
myOptions.SHOW_QUICK_DOC_ON_MOUSE_OVER_ELEMENT = show;
}
public boolean isRefrainFromScrolling() {
return myOptions.REFRAIN_FROM_SCROLLING;
}
@@ -2508,7 +2508,8 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
@NotNull Rectangle clip,
@NotNull LogicalPosition clipStartPosition,
int clipStartOffset,
int clipEndOffset) {
int clipEndOffset)
{
myCurrentFontType = null;
myLastCache = null;
final int plainSpaceWidth = EditorUtil.getSpaceWidth(Font.PLAIN, this);
@@ -323,16 +323,17 @@ abstract class FoldRegionsTree {
}
public int getLastTopLevelIndexBefore(int offset) {
if (!isFoldingEnabledAndUpToDate()) return -1;
int[] endOffsets = myCachedEndOffsets;
if (!isFoldingEnabledAndUpToDate() || endOffsets == null) return -1;
int start = 0;
int end = myCachedEndOffsets.length - 1;
int end = endOffsets.length - 1;
while (start <= end) {
int i = (start + end) / 2;
if (offset < myCachedEndOffsets[i]) {
if (offset < endOffsets[i]) {
end = i - 1;
} else if (offset > myCachedEndOffsets[i]) {
} else if (offset > endOffsets[i]) {
start = i + 1;
}
else {
@@ -589,6 +589,7 @@ public class SoftWrapApplianceManager implements SoftWrapFoldingListener, Docume
myContext.currentPosition.offset--;
myContext.currentPosition.logicalColumn -= columnsDiff;
myContext.currentPosition.visualColumn -= columnsDiff;
myContext.currentPosition.x -= pixelsDiff;
}
}
}
@@ -899,6 +900,10 @@ public class SoftWrapApplianceManager implements SoftWrapFoldingListener, Docume
return myListeners.add(listener);
}
public boolean removeListener(@NotNull SoftWrapAwareDocumentParsingListener listener) {
return myListeners.remove(listener);
}
@SuppressWarnings({"ForLoopReplaceableByForEach"})
private void revertListeners(int offset, int visualLine) {
for (int i = 0; i < myListeners.size(); i++) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.NotNull;
* @author Denis Zhdanov
* @since 11/23/11 7:04 PM
*/
public class SoftWrapAwareDocumentParsingListenerAdapter implements SoftWrapAwareDocumentParsingListener {
public abstract class SoftWrapAwareDocumentParsingListenerAdapter implements SoftWrapAwareDocumentParsingListener {
@Override
public void onVisualLineStart(@NotNull EditorPosition position) {
}
@@ -823,7 +823,7 @@ public class FSRecords implements Forceable {
}
}
public static void updateList(int id, int[] children) {
public static void updateList(int id, @NotNull int[] children) {
try {
w.lock();
DbConnection.markDirty();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -28,6 +28,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.VisualPosition;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.*;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -36,6 +36,7 @@ import com.intellij.openapi.ui.popup.*;
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.EmptyRunnable;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.openapi.wm.ex.WindowManagerEx;
import com.intellij.openapi.wm.impl.IdeFrameImpl;
@@ -65,6 +66,14 @@ import java.util.HashMap;
import java.util.List;
public class PopupFactoryImpl extends JBPopupFactory {
/**
* Allows to get an editor position for which a popup with auxiliary information might be shown.
* <p/>
* Primary intention for this key is to hint popup position for the non-caret location.
*/
public static final Key<VisualPosition> ANCHOR_POPUP_POSITION = Key.create("popup.anchor.position");
private static final Logger LOG = Logger.getInstance("#com.intellij.ui.popup.PopupFactoryImpl");
private static final Icon QUICK_LIST_ICON = AllIcons.Actions.QuickList;
@@ -78,7 +87,7 @@ public class PopupFactoryImpl extends JBPopupFactory {
}
public JBPopup createMessage(String text) {
return createListPopup(new BaseListPopupStep<String>(null, new String[]{text}));
return createListPopup(new BaseListPopupStep<String>(null, new String[]{text}));
}
@Override
@@ -98,28 +107,34 @@ public class PopupFactoryImpl extends JBPopupFactory {
return null;
}
public ListPopup createConfirmation(String title, final String yesText, String noText, final Runnable onYes, final Runnable onNo, int defaultOptionIndex) {
public ListPopup createConfirmation(String title,
final String yesText,
String noText,
final Runnable onYes,
final Runnable onNo,
int defaultOptionIndex)
{
final BaseListPopupStep<String> step = new BaseListPopupStep<String>(title, new String[]{yesText, noText}) {
public PopupStep onChosen(String selectedValue, final boolean finalChoice) {
if (selectedValue.equals(yesText)) {
onYes.run();
}
else {
onNo.run();
}
return FINAL_CHOICE;
final BaseListPopupStep<String> step = new BaseListPopupStep<String>(title, new String[]{yesText, noText}) {
public PopupStep onChosen(String selectedValue, final boolean finalChoice) {
if (selectedValue.equals(yesText)) {
onYes.run();
}
public void canceled() {
else {
onNo.run();
}
return FINAL_CHOICE;
}
public boolean isMnemonicsNavigationEnabled() {
return true;
}
};
step.setDefaultOptionIndex(defaultOptionIndex);
public void canceled() {
onNo.run();
}
public boolean isMnemonicsNavigationEnabled() {
return true;
}
};
step.setDefaultOptionIndex(defaultOptionIndex);
final ApplicationEx app = ApplicationManagerEx.getApplicationEx();
return app == null || !app.isUnitTestMode() ? new ListPopupImpl(step) : new MockConfirmation(step, yesText);
@@ -127,13 +142,13 @@ public class PopupFactoryImpl extends JBPopupFactory {
private static ListPopup createActionGroupPopup(final String title,
final ActionGroup actionGroup,
@NotNull DataContext dataContext,
boolean showNumbers,
boolean useAlphaAsNumbers,
boolean showDisabledActions,
boolean honorActionMnemonics,
final Runnable disposeCallback,
final ActionGroup actionGroup,
@NotNull DataContext dataContext,
boolean showNumbers,
boolean useAlphaAsNumbers,
boolean showDisabledActions,
boolean honorActionMnemonics,
final Runnable disposeCallback,
final int maxRowCount) {
return createActionGroupPopup(title, actionGroup, dataContext, showNumbers, useAlphaAsNumbers, showDisabledActions, honorActionMnemonics, disposeCallback,
maxRowCount, null, null);
@@ -458,14 +473,18 @@ public class PopupFactoryImpl extends JBPopupFactory {
}
public RelativePoint guessBestPopupLocation(Editor editor) {
CaretModel caretModel = editor.getCaretModel();
final VisualPosition visualPosition;
if (caretModel.isUpToDate()) {
visualPosition = caretModel.getVisualPosition();
}
else {
visualPosition = editor.offsetToVisualPosition(caretModel.getOffset());
VisualPosition visualPosition = editor.getUserData(ANCHOR_POPUP_POSITION);
if (visualPosition == null) {
CaretModel caretModel = editor.getCaretModel();
if (caretModel.isUpToDate()) {
visualPosition = caretModel.getVisualPosition();
}
else {
visualPosition = editor.offsetToVisualPosition(caretModel.getOffset());
}
}
Point p = editor.visualPositionToXY(new VisualPosition(visualPosition.line + 1, visualPosition.column));
final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
@@ -372,6 +372,7 @@ checkbox.show.virtual.space.at.file.bottom=Show virtual space at file bottom
checkbox.optimize.imports.on.the.fly=Optimize imports on the fly
checkbox.add.unambiguous.imports.on.the.fly=Add unambiguous imports on the fly
combobox.strip.trailing.spaces.on.save=Strip trailing spaces on Save:
checkbox.show.quick.doc.on.mouse.over=Show quick doc on mouse over element
group.limits=Limits
editbox.recent.files.limit=Recent files limit:
editbox.console.history.limit=Console commands history size:
@@ -733,7 +733,10 @@
<applicationService serviceInterface="com.intellij.ide.todo.TodoConfiguration"
serviceImplementation="com.intellij.ide.todo.TodoConfiguration"/>
<indexPatternProvider implementation="com.intellij.ide.todo.TodoIndexPatternProvider"/>
<applicationService serviceImplementation="com.intellij.codeInsight.documentation.QuickDocOnMouseOverManager"/>
<postStartupActivity implementation="com.intellij.codeInsight.documentation.QuickDocOnMouseOverStartupActivity"/>
<hectorComponentProvider implementation="com.intellij.codeInsight.daemon.PowerSaveHectorProvider"/>
<copyPastePostProcessor implementation="com.intellij.codeInsight.editorActions.CopyPasteIndentProcessor"/>
@@ -17,8 +17,12 @@ package com.intellij.openapi.editor.impl.softwrap.mapping;
import com.intellij.codeInsight.folding.CodeFoldingManager;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.impl.*;
import com.intellij.openapi.editor.impl.AbstractEditorProcessingOnDocumentModificationTest;
import com.intellij.openapi.editor.impl.DefaultEditorTextRepresentationHelper;
import com.intellij.openapi.editor.impl.EditorImpl;
import com.intellij.openapi.editor.impl.SoftWrapModelImpl;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.testFramework.TestFileType;
import gnu.trove.TIntHashSet;
@@ -994,9 +998,37 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorP
assertEquals(text.substring(0, text.indexOf("line")) + text.substring(text.indexOf('9')), myEditor.getDocument().getText());
assertEquals(position, caretModel.getVisualPosition());
}
public void testNoUnnecessaryHorizontalScrollBar() throws IOException {
// Inspired by IDEA-87184
final String text = "12345678 abcdefgh";
init(15, 7, text);
myEditor.getCaretModel().moveToOffset(text.length());
final Ref<Boolean> fail = new Ref<Boolean>(true);
SoftWrapApplianceManager applianceManager = ((SoftWrapModelImpl)myEditor.getSoftWrapModel()).getApplianceManager();
SoftWrapAwareDocumentParsingListener listener = new SoftWrapAwareDocumentParsingListenerAdapter() {
@Override
public void beforeSoftWrapLineFeed(@NotNull EditorPosition position) {
if (position.x == text.indexOf("a") * 7) {
fail.set(false);
}
}
};
applianceManager.addListener(listener);
try {
backspace();
}
finally {
applianceManager.removeListener(listener);
}
assertFalse(fail.get());
}
private void init(final int visibleWidthInColumns, @NotNull String fileText) throws IOException {
int symbolWidthInPixels = 7;
init(visibleWidthInColumns, 7, fileText);
}
private void init(final int visibleWidthInColumns, final int symbolWidthInPixels, @NotNull String fileText) throws IOException {
init(visibleWidthInColumns * symbolWidthInPixels, fileText, symbolWidthInPixels);
}
@@ -588,14 +588,13 @@ public class DirectoryIndexImpl extends DirectoryIndex {
}
protected void fillMapWithOrderEntries(final VirtualFile root,
final Collection<OrderEntry> orderEntries,
@NotNull final Collection<OrderEntry> orderEntries,
@Nullable final Module module,
@Nullable final VirtualFile libraryClassRoot,
@Nullable final VirtualFile librarySourceRoot,
@Nullable final DirectoryInfo parentInfo, @Nullable final ProgressIndicator progress) {
VfsUtilCore.visitChildrenRecursively(root, new DirectoryVisitor() {
private final Stack<List<OrderEntry>> myEntries = new Stack<List<OrderEntry>>();
@Override
@@ -21,6 +21,7 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.OrderEntry;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
@@ -80,12 +81,13 @@ public class DirectoryInfo {
"}";
}
@NotNull
public List<OrderEntry> getOrderEntries() {
return orderEntries == null ? Collections.<OrderEntry>emptyList() : orderEntries;
}
@SuppressWarnings({"unchecked"})
public void addOrderEntries(Collection<OrderEntry> orderEntries,
public void addOrderEntries(@NotNull Collection<OrderEntry> orderEntries,
@Nullable final DirectoryInfo parentInfo,
@Nullable final List<OrderEntry> oldParentEntries) {
if (orderEntries.isEmpty()) {
@@ -16,6 +16,8 @@
package com.intellij.openapi.util;
import com.intellij.openapi.util.text.StringUtilRt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collection;
@@ -28,24 +30,22 @@ import java.util.Set;
public class Comparing {
private Comparing() { }
public static <T> boolean equal(T arg1, T arg2){
public static <T> boolean equal(@Nullable T arg1, @Nullable T arg2){
if (arg1 == null || arg2 == null){
return arg1 == arg2;
}
else if (arg1 instanceof Object[] && arg2 instanceof Object[]){
if (arg1 instanceof Object[] && arg2 instanceof Object[]){
Object[] arr1 = (Object[])arg1;
Object[] arr2 = (Object[])arg2;
return Arrays.equals(arr1, arr2);
}
else if (arg1 instanceof CharSequence && arg2 instanceof CharSequence) {
if (arg1 instanceof CharSequence && arg2 instanceof CharSequence) {
return equal((CharSequence)arg1, (CharSequence)arg2, true);
}
else{
return arg1.equals(arg2);
}
return arg1.equals(arg2);
}
public static <T> boolean equal(T[] arr1, T[] arr2){
public static <T> boolean equal(@Nullable T[] arr1, @Nullable T[] arr2){
if (arr1 == null || arr2 == null){
return arr1 == arr2;
}
@@ -60,7 +60,7 @@ public class Comparing {
return equal(arg1, arg2, true);
}
public static boolean equal(CharSequence s1, CharSequence s2, boolean caseSensitive) {
public static boolean equal(@Nullable CharSequence s1, @Nullable CharSequence s2, boolean caseSensitive) {
if (s1 == s2) return true;
if (s1 == null || s2 == null) return false;
@@ -84,7 +84,7 @@ public class Comparing {
return true;
}
public static boolean equal(String arg1, String arg2, boolean caseSensitive){
public static boolean equal(@Nullable String arg1, @Nullable String arg2, boolean caseSensitive){
if (arg1 == null || arg2 == null){
return arg1 == arg2;
}
@@ -97,11 +97,11 @@ public class Comparing {
return strEqual(arg1, arg2, true);
}
public static boolean strEqual(String arg1, String arg2, boolean caseSensitive){
public static boolean strEqual(@Nullable String arg1, @Nullable String arg2, boolean caseSensitive){
return equal(arg1 == null ? "" : arg1, arg2 == null ? "" : arg2, caseSensitive);
}
public static <T> boolean haveEqualElements(Collection<T> a, Collection<T> b) {
public static <T> boolean haveEqualElements(@NotNull Collection<T> a, @NotNull Collection<T> b) {
if (a.size() != b.size()) {
return false;
}
@@ -115,7 +115,7 @@ public class Comparing {
return true;
}
public static <T> boolean haveEqualElements(T[] a, T[] b) {
public static <T> boolean haveEqualElements(@Nullable T[] a, @Nullable T[] b) {
if (a == null || b == null) {
return a == b;
}
@@ -133,7 +133,7 @@ public class Comparing {
return true;
}
public static int hashcode(Object obj) { return obj == null ? 0 : obj.hashCode(); }
public static int hashcode(@Nullable Object obj) { return obj == null ? 0 : obj.hashCode(); }
public static int hashcode(Object obj1, Object obj2) { return hashcode(obj1) ^ hashcode(obj2); }
public static int compare(byte o1, byte o2) {
@@ -152,7 +152,7 @@ public class Comparing {
return o1 < o2 ? -1 : o1 == o2 ? 0 : 1;
}
public static int compare(byte[] o1, byte[] o2) {
public static int compare(@Nullable byte[] o1, @Nullable byte[] o2) {
if (o1 == o2) return 0;
if (o1 == null) return 1;
if (o2 == null) return -1;
@@ -167,7 +167,7 @@ public class Comparing {
return 0;
}
public static <T extends Comparable<T>> int compare(final T o1, final T o2) {
public static <T extends Comparable<T>> int compare(@Nullable final T o1, @Nullable final T o2) {
if (o1 == null) return o2 == null ? 0 : -1;
if (o2 == null) return 1;
return o1.compareTo(o2);
@@ -1658,13 +1658,11 @@ public class StringUtil extends StringUtilRt {
@NonNls private static final String[] REPLACES_REFS = {"&lt;", "&gt;", "&amp;", "&#39;", "&quot;"};
@NonNls private static final String[] REPLACES_DISP = {"<", ">", "&", "'", "\""};
@Nullable
public static String unescapeXml(@Nullable final String text) {
if (text == null) return null;
return replace(text, REPLACES_REFS, REPLACES_DISP);
}
@Nullable
public static String escapeXml(@Nullable final String text) {
if (text == null) return null;
return replace(text, REPLACES_DISP, REPLACES_REFS);
@@ -18,6 +18,7 @@ package com.intellij.util.containers;
import com.intellij.util.ConcurrencyUtil;
import gnu.trove.TObjectHashingStrategy;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.Serializable;
@@ -592,6 +593,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
}
// inherit Map javadoc
@Override
public boolean isEmpty() {
final Segment[] segments = this.segments;
/*
@@ -625,6 +627,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
}
// inherit Map javadoc
@Override
public int size() {
final Segment[] segments = this.segments;
long sum = 0;
@@ -678,6 +681,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
* @throws NullPointerException if the key is
* <tt>null</tt>.
*/
@Override
public V get(Object key) {
int hash = myHashingStrategy.computeHashCode((K)key); // throws NullPointerException if key null
return segmentFor(hash).get((K)key, hash);
@@ -693,6 +697,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
* @throws NullPointerException if the key is
* <tt>null</tt>.
*/
@Override
public boolean containsKey(Object key) {
int hash = myHashingStrategy.computeHashCode((K)key); // throws NullPointerException if key null
return segmentFor(hash).containsKey((K)key, hash);
@@ -709,9 +714,8 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
* specified value.
* @throws NullPointerException if the value is <tt>null</tt>.
*/
public boolean containsValue(Object value) {
if (value == null)
throw new NullPointerException();
@Override
public boolean containsValue(@NotNull Object value) {
// See explanation of modCount use above
@@ -793,9 +797,8 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
* @throws NullPointerException if the key or value is
* <tt>null</tt>.
*/
public V put(K key, V value) {
if (value == null)
throw new NullPointerException();
@Override
public V put(K key, @NotNull V value) {
int hash = myHashingStrategy.computeHashCode(key);
return segmentFor(hash).put(key, hash, value, false);
}
@@ -818,9 +821,8 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
* @throws NullPointerException if the specified key or value is
* <tt>null</tt>.
*/
public V putIfAbsent(K key, V value) {
if (value == null)
throw new NullPointerException();
@Override
public V putIfAbsent(@NotNull K key, @NotNull V value) {
int hash = myHashingStrategy.computeHashCode(key);
return segmentFor(hash).put(key, hash, value, true);
}
@@ -834,6 +836,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
*
* @param t Mappings to be stored in this map.
*/
@Override
public void putAll(Map<? extends K, ? extends V> t) {
for (Iterator<? extends Entry<? extends K, ? extends V>> it = (Iterator<? extends Entry<? extends K, ? extends V>>) t.entrySet().iterator(); it.hasNext(); ) {
Entry<? extends K, ? extends V> e = it.next();
@@ -851,6 +854,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
* @throws NullPointerException if the key is
* <tt>null</tt>.
*/
@Override
public V remove(Object key) {
int hash = myHashingStrategy.computeHashCode((K)key);
return segmentFor(hash).remove((K)key, hash, null);
@@ -872,7 +876,8 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
* @throws NullPointerException if the specified key is
* <tt>null</tt>.
*/
public boolean remove(Object key, Object value) {
@Override
public boolean remove(@NotNull Object key, Object value) {
int hash = myHashingStrategy.computeHashCode((K)key);
return segmentFor(hash).remove((K)key, hash, value) != null;
}
@@ -895,9 +900,8 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
* @throws NullPointerException if the specified key or values are
* <tt>null</tt>.
*/
public boolean replace(K key, V oldValue, V newValue) {
if (oldValue == null || newValue == null)
throw new NullPointerException();
@Override
public boolean replace(@NotNull K key, @NotNull V oldValue, @NotNull V newValue) {
int hash = myHashingStrategy.computeHashCode(key);
return segmentFor(hash).replace(key, hash, oldValue, newValue);
}
@@ -918,9 +922,8 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
* @throws NullPointerException if the specified key or value is
* <tt>null</tt>.
*/
public V replace(K key, V value) {
if (value == null)
throw new NullPointerException();
@Override
public V replace(@NotNull K key, @NotNull V value) {
int hash = myHashingStrategy.computeHashCode(key);
return segmentFor(hash).replace(key, hash, value);
}
@@ -929,9 +932,9 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
/**
* Removes all mappings from this map.
*/
@Override
public void clear() {
for (int i = 0; i < segments.length; ++i)
segments[i].clear();
for (Segment segment : segments) segment.clear();
}
/**
@@ -950,6 +953,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
*
* @return a set view of the keys contained in this map.
*/
@Override
public Set<K> keySet() {
Set<K> ks = keySet;
return (ks != null) ? ks : (keySet = new KeySet());
@@ -972,6 +976,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
*
* @return a collection view of the values contained in this map.
*/
@Override
public Collection<V> values() {
Collection<V> vs = values;
return (vs != null) ? vs : (values = new Values());
@@ -995,6 +1000,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
*
* @return a collection view of the mappings contained in this map.
*/
@Override
public Set<Entry<K,V>> entrySet() {
Set<Entry<K,V>> es = entrySet;
return (es != null) ? es : (entrySet = (Set<Entry<K,V>>) (Set) new EntrySet());
@@ -1080,12 +1086,16 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
}
final class KeyIterator extends HashIterator implements Iterator<K>, Enumeration<K> {
@Override
public K next() { return super.nextEntry().key; }
@Override
public K nextElement() { return super.nextEntry().key; }
}
final class ValueIterator extends HashIterator implements Iterator<V>, Enumeration<V> {
@Override
public V next() { return super.nextEntry().value; }
@Override
public V nextElement() { return super.nextEntry().value; }
}
@@ -1098,23 +1108,27 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
* itself acts as a forwarding pseudo-entry.
*/
final class EntryIterator extends HashIterator implements Entry<K,V>, Iterator<Entry<K,V>> {
@Override
public Entry<K,V> next() {
nextEntry();
return this;
}
@Override
public K getKey() {
if (lastReturned == null)
throw new IllegalStateException("Entry was removed");
return lastReturned.key;
}
@Override
public V getValue() {
if (lastReturned == null)
throw new IllegalStateException("Entry was removed");
return ConcurrentHashMap.this.get(lastReturned.key);
}
@Override
public V setValue(V value) {
if (lastReturned == null)
throw new IllegalStateException("Entry was removed");
@@ -1159,27 +1173,34 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
}
final class KeySet extends AbstractSet<K> {
@Override
public Iterator<K> iterator() {
return new KeyIterator();
}
@Override
public int size() {
return ConcurrentHashMap.this.size();
}
@Override
public boolean contains(Object o) {
return ConcurrentHashMap.this.containsKey(o);
}
@Override
public boolean remove(Object o) {
return ConcurrentHashMap.this.remove(o) != null;
}
@Override
public void clear() {
ConcurrentHashMap.this.clear();
}
@Override
public Object[] toArray() {
Collection<K> c = new ArrayList<K>();
for (Iterator<K> i = iterator(); i.hasNext(); )
c.add(i.next());
return c.toArray();
}
@Override
public <T> T[] toArray(T[] a) {
Collection<K> c = new ArrayList<K>();
for (Iterator<K> i = iterator(); i.hasNext(); )
@@ -1189,24 +1210,30 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
}
final class Values extends AbstractCollection<V> {
@Override
public Iterator<V> iterator() {
return new ValueIterator();
}
@Override
public int size() {
return ConcurrentHashMap.this.size();
}
@Override
public boolean contains(Object o) {
return ConcurrentHashMap.this.containsValue(o);
}
@Override
public void clear() {
ConcurrentHashMap.this.clear();
}
@Override
public Object[] toArray() {
Collection<V> c = new ArrayList<V>();
for (Iterator<V> i = iterator(); i.hasNext(); )
c.add(i.next());
return c.toArray();
}
@Override
public <T> T[] toArray(T[] a) {
Collection<V> c = new ArrayList<V>();
for (Iterator<V> i = iterator(); i.hasNext(); )
@@ -1216,9 +1243,11 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
}
final class EntrySet extends AbstractSet<Entry<K,V>> {
@Override
public Iterator<Entry<K,V>> iterator() {
return new EntryIterator();
}
@Override
public boolean contains(Object o) {
if (!(o instanceof Entry))
return false;
@@ -1226,18 +1255,22 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
V v = ConcurrentHashMap.this.get(e.getKey());
return v != null && v.equals(e.getValue());
}
@Override
public boolean remove(Object o) {
if (!(o instanceof Entry))
return false;
Entry<K,V> e = (Entry<K,V>)o;
return ConcurrentHashMap.this.remove(e.getKey(), e.getValue());
}
@Override
public int size() {
return ConcurrentHashMap.this.size();
}
@Override
public void clear() {
ConcurrentHashMap.this.clear();
}
@Override
public Object[] toArray() {
// Since we don't ordinarily have distinct Entry objects, we
// must pack elements using exportable SimpleEntry
@@ -1246,6 +1279,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
c.add(new SimpleEntry(i.next()));
return c.toArray();
}
@Override
public <T> T[] toArray(T[] a) {
Collection<Entry<K,V>> c = new ArrayList<Entry<K,V>>(size());
for (Iterator<Entry<K,V>> i = iterator(); i.hasNext(); )
@@ -1273,14 +1307,17 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
this.value = e.getValue();
}
@Override
public K getKey() {
return key;
}
@Override
public V getValue() {
return value;
}
@Override
public V setValue(V value) {
V oldValue = this.value;
this.value = value;
@@ -1368,6 +1405,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
}
}
@Override
public int computeHashCode(final K object) {
int h = object.hashCode();
h += ~(h << 9);
@@ -1377,6 +1415,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements Concur
return h;
}
@Override
public boolean equals(final K o1, final K o2) {
return o1.equals(o2);
}
@@ -38,14 +38,14 @@ public class StringSearcher {
}
public StringSearcher(@NotNull String pattern, boolean caseSensitive, boolean forwardDirection) {
LOG.assertTrue(pattern.length() > 0);
LOG.assertTrue(!pattern.isEmpty());
myPattern = pattern;
myCaseSensitive = caseSensitive;
myForwardDirection = forwardDirection;
myPatternArray = myCaseSensitive ? myPattern.toCharArray() : myPattern.toLowerCase().toCharArray();
myPatternLength = myPatternArray.length;
Arrays.fill(mySearchTable, -1);
myJavaIdentifier = pattern.length() == 0 ||
myJavaIdentifier = pattern.isEmpty() ||
Character.isJavaIdentifierPart(pattern.charAt(0)) &&
Character.isJavaIdentifierPart(pattern.charAt(pattern.length() - 1));
}
@@ -40,7 +40,9 @@ public class AndroidDesignerBundle {
private static ResourceBundle getBundle() {
ResourceBundle bundle = null;
if (ourBundle != null) bundle = ourBundle.get();
if (ourBundle != null) {
bundle = ourBundle.get();
}
if (bundle == null) {
bundle = ResourceBundle.getBundle(BUNDLE);
ourBundle = new SoftReference<ResourceBundle>(bundle);
@@ -224,6 +224,7 @@ public abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestC
file.setBinaryContent(file.contentsToByteArray(), file.getModificationStamp() + 1, file.getTimeStamp() + 1);
File ioFile = VfsUtil.virtualToIoFile(file);
assert ioFile.setLastModified(ioFile.lastModified() - 100000);
file.refresh(false, false);
}
protected static void setFileText(final PsiFile file, final String barText) throws IOException {
@@ -27,6 +27,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.ui.GuiUtils;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
@@ -35,16 +36,25 @@ public class PropertiesDocumentationProvider extends AbstractDocumentationProvid
@Nullable
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
if (element instanceof IProperty) {
@NonNls String info = "\n\"" + ((IProperty)element).getValue() + "\"";
PsiFile file = element.getContainingFile();
if (file != null) {
info += " [" + file.getName() + "]";
}
return info;
return "\"" + renderPropertyValue((IProperty)element) + "\"" + getLocationString(element);
}
return null;
}
private static String getLocationString(PsiElement element) {
PsiFile file = element.getContainingFile();
return file != null ? " [" + file.getName() + "]" : "";
}
@NotNull
private static String renderPropertyValue(IProperty prop) {
String raw = prop.getValue();
if (raw == null) {
return "<i>empty</i>";
}
return StringUtil.escapeXml(raw);
}
public String generateDoc(final PsiElement element, final PsiElement originalElement) {
if (element instanceof IProperty) {
IProperty property = (IProperty)element;
@@ -63,11 +73,8 @@ public class PropertiesDocumentationProvider extends AbstractDocumentationProvid
info += "</div>";
}
}
info += "\n<b>" + property.getName() + "</b>=\"" + ((IProperty)element).getValue() + "\"";
PsiFile file = element.getContainingFile();
if (file != null) {
info += " [" + file.getName() + "]";
}
info += "\n<b>" + property.getName() + "</b>=\"" + renderPropertyValue(((IProperty)element)) + "\"";
info += getLocationString(element);
return info;
}
return null;
@@ -40,7 +40,9 @@ public class DesignerBundle {
private static ResourceBundle getBundle() {
ResourceBundle bundle = null;
if (ourBundle != null) bundle = ourBundle.get();
if (ourBundle != null) {
bundle = ourBundle.get();
}
if (bundle == null) {
bundle = ResourceBundle.getBundle(BUNDLE);
ourBundle = new SoftReference<ResourceBundle>(bundle);
@@ -45,7 +45,7 @@ public abstract class MetaManager {
private static final String TAG = "tag";
private static final String WRAP_IN = "wrap-in";
private static final Logger LOG = Logger.getInstance("#com.intellij.designer.model.MetaManager");
protected static final Logger LOG = Logger.getInstance("#com.intellij.designer.model.MetaManager");
private final Map<String, MetaModel> myTag2Model = new HashMap<String, MetaModel>();
private final Map<String, MetaModel> myTarget2Model = new HashMap<String, MetaModel>();
@@ -111,7 +111,7 @@ public abstract class MetaManager {
String target = element.getAttributeValue("class");
String tag = element.getAttributeValue(TAG);
MetaModel meta = new MetaModel(model, target, tag);
MetaModel meta = createModel(model, target, tag);
String layout = element.getAttributeValue("layout");
if (layout != null) {
@@ -144,35 +144,7 @@ public abstract class MetaManager {
Element properties = element.getChild("properties");
if (properties != null) {
Attribute inplace = properties.getAttribute("inplace");
if (inplace != null) {
meta.setInplaceProperties(StringUtil.split(inplace.getValue(), " "));
}
Attribute top = properties.getAttribute("top");
if (top != null) {
meta.setTopProperties(StringUtil.split(top.getValue(), " "));
}
Attribute normal = properties.getAttribute("normal");
if (normal != null) {
meta.setNormalProperties(StringUtil.split(normal.getValue(), " "));
}
Attribute important = properties.getAttribute("important");
if (important != null) {
meta.setImportantProperties(StringUtil.split(important.getValue(), " "));
}
Attribute expert = properties.getAttribute("expert");
if (expert != null) {
meta.setExpertProperties(StringUtil.split(expert.getValue(), " "));
}
Attribute deprecated = properties.getAttribute("deprecated");
if (deprecated != null) {
meta.setDeprecatedProperties(StringUtil.split(deprecated.getValue(), " "));
}
loadProperties(meta, properties);
}
Element morphing = element.getChild("morphing");
@@ -180,6 +152,8 @@ public abstract class MetaManager {
modelToMorphing.put(meta, StringUtil.split(morphing.getAttribute("to").getValue(), " "));
}
loadOther(meta, element);
if (tag != null) {
myTag2Model.put(tag, meta);
}
@@ -189,6 +163,45 @@ public abstract class MetaManager {
}
}
protected MetaModel createModel(Class<RadComponent> model, String target, String tag) throws Exception {
return new MetaModel(model, target, tag);
}
protected void loadProperties(MetaModel meta, Element properties) throws Exception {
Attribute inplace = properties.getAttribute("inplace");
if (inplace != null) {
meta.setInplaceProperties(StringUtil.split(inplace.getValue(), " "));
}
Attribute top = properties.getAttribute("top");
if (top != null) {
meta.setTopProperties(StringUtil.split(top.getValue(), " "));
}
Attribute normal = properties.getAttribute("normal");
if (normal != null) {
meta.setNormalProperties(StringUtil.split(normal.getValue(), " "));
}
Attribute important = properties.getAttribute("important");
if (important != null) {
meta.setImportantProperties(StringUtil.split(important.getValue(), " "));
}
Attribute expert = properties.getAttribute("expert");
if (expert != null) {
meta.setExpertProperties(StringUtil.split(expert.getValue(), " "));
}
Attribute deprecated = properties.getAttribute("deprecated");
if (deprecated != null) {
meta.setDeprecatedProperties(StringUtil.split(deprecated.getValue(), " "));
}
}
protected void loadOther(MetaModel meta, Element element) throws Exception {
}
private void loadGroup(Element element) throws Exception {
PaletteGroup group = new PaletteGroup(element.getAttributeValue(NAME));
@@ -35,8 +35,8 @@ public class MetaModel {
private final String myTag;
private DefaultPaletteItem myPaletteItem;
private String myTitle;
private String myIconPath;
private Icon myIcon;
protected String myIconPath;
protected Icon myIcon;
private String myCreation;
private boolean myDelete = true;
private List<String> myInplaceProperties = Collections.emptyList();