Merge remote-tracking branch 'origin/master'

This commit is contained in:
Roman Shevchenko
2016-03-23 18:01:07 +01:00
48 changed files with 361 additions and 142 deletions
@@ -55,6 +55,7 @@ import com.intellij.xdebugger.breakpoints.XBreakpoint;
import com.intellij.xdebugger.breakpoints.XBreakpointHandler;
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
import com.intellij.xdebugger.frame.XStackFrame;
import com.intellij.xdebugger.frame.XSuspendContext;
import com.intellij.xdebugger.frame.XValueMarkerProvider;
import com.intellij.xdebugger.impl.XDebugSessionImpl;
import com.intellij.xdebugger.impl.XDebuggerUtilImpl;
@@ -240,22 +241,22 @@ public class JavaDebugProcess extends XDebugProcess {
}
@Override
public void startStepOver() {
public void startStepOver(@Nullable XSuspendContext context) {
myJavaSession.stepOver(false);
}
@Override
public void startStepInto() {
public void startStepInto(@Nullable XSuspendContext context) {
myJavaSession.stepInto(false, null);
}
@Override
public void startForceStepInto() {
public void startForceStepInto(@Nullable XSuspendContext context) {
myJavaSession.stepInto(true, null);
}
@Override
public void startStepOut() {
public void startStepOut(@Nullable XSuspendContext context) {
myJavaSession.stepOut();
}
@@ -271,12 +272,12 @@ public class JavaDebugProcess extends XDebugProcess {
}
@Override
public void resume() {
public void resume(@Nullable XSuspendContext context) {
myJavaSession.resume();
}
@Override
public void runToPosition(@NotNull XSourcePosition position) {
public void runToPosition(@NotNull XSourcePosition position, @Nullable XSuspendContext context) {
myJavaSession.runToCursor(position, false);
}
@@ -87,6 +87,13 @@ public abstract class AbstractPatternBasedConfigurationProducer<T extends Module
collectContextElements(dataContext, true, false, classes, new PsiElementProcessor.CollectElements<PsiElement>());
}
if (Comparing.equal(classes, patterns)) {
if (patterns.size() == 1) {
final String pattern = patterns.iterator().next();
if (!pattern.contains(",")) {
final PsiMethod method = PsiTreeUtil.getParentOfType(CommonDataKeys.PSI_ELEMENT.getData(dataContext), PsiMethod.class);
return method != null && isTestMethod(false, method);
}
}
return true;
}
return false;
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInspection.concurrencyAnnotations;
import com.intellij.codeInsight.PsiEquivalenceUtil;
import com.intellij.codeInsight.daemon.GroupNames;
import com.intellij.codeInspection.BaseJavaBatchLocalInspectionTool;
import com.intellij.codeInspection.ProblemsHolder;
@@ -81,6 +82,20 @@ public class FieldAccessNotGuardedInspection extends BaseJavaBatchLocalInspectio
if (containingMethod != null && containingMethod.hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
return;
}
final PsiSynchronizedStatement synchronizedStatement = PsiTreeUtil.getParentOfType(expression, PsiSynchronizedStatement.class);
if (synchronizedStatement != null) {
final PsiExpression lockExpression = synchronizedStatement.getLockExpression();
final PsiExpression qualifierExpression = expression.getQualifierExpression();
if (lockExpression instanceof PsiThisExpression && qualifierExpression == null) {
return;
}
if (lockExpression instanceof PsiReferenceExpression &&
qualifierExpression != null &&
PsiEquivalenceUtil.areElementsEquivalent(lockExpression, qualifierExpression)) {
return;
}
}
}
if (findLockTryStatement(expression, guard) != null) {
@@ -31,6 +31,8 @@ import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.psi.*;
import com.intellij.psi.controlFlow.*;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.javadoc.PsiDocTagValue;
import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiTreeUtil;
@@ -135,6 +137,10 @@ public class FieldCanBeLocalInspectionBase extends BaseJavaBatchLocalInspectionT
}
}
}
final PsiDocComment docComment = method.getDocComment();
if (docComment != null) {
docComment.accept(this);
}
//do not go inside method
}
@@ -145,15 +151,26 @@ public class FieldCanBeLocalInspectionBase extends BaseJavaBatchLocalInspectionT
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
final PsiElement resolved = expression.resolve();
excludeFieldCandidate(expression);
super.visitReferenceExpression(expression);
}
@Override
public void visitDocTagValue(PsiDocTagValue value) {
excludeFieldCandidate(value.getReference());
super.visitDocTagValue(value);
}
private void excludeFieldCandidate(PsiReference ref) {
if (ref == null) return;
final PsiElement resolved = ref.resolve();
if (resolved instanceof PsiField) {
final PsiField field = (PsiField)resolved;
if (aClass.equals(field.getContainingClass())) {
candidates.remove(field);
}
}
super.visitReferenceExpression(expression);
}
});
}
@@ -145,19 +145,25 @@ public final class FieldFromParameterUtils {
else if (expression instanceof PsiAssignmentExpression) {
PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)expression;
PsiExpression lExpression = assignmentExpression.getLExpression();
PsiExpression rExpression = assignmentExpression.getRExpression();
if (!(lExpression instanceof PsiReferenceExpression)) break;
if (!(rExpression instanceof PsiReferenceExpression)) break;
PsiReferenceExpression lReference = (PsiReferenceExpression)lExpression;
PsiReferenceExpression rReference = (PsiReferenceExpression)rExpression;
PsiElement lElement = lReference.resolve();
PsiElement rElement = rReference.resolve();
PsiElement lElement = ((PsiReferenceExpression)lExpression).resolve();
if (!(lElement instanceof PsiField) || ((PsiField)lElement).getContainingClass() != targetClass) break;
if (!(rElement instanceof PsiParameter)) break;
final Set<PsiParameter> parameters = new HashSet<>();
SyntaxTraverser.psiTraverser().withRoot(assignmentExpression.getRExpression())
.filter(PsiReferenceExpression.class)
.forEach(expr -> {
final PsiElement resolve = expr.resolve();
if (resolve instanceof PsiParameter && ((PsiParameter)resolve).getDeclarationScope() == myParameter.getDeclarationScope()) {
parameters.add((PsiParameter)resolve);
}
});
if (parameters.size() != 1) break;
PsiElement rElement = parameters.iterator().next();
if (myParameter.getTextRange().getStartOffset() < rElement.getTextRange().getStartOffset()) {
if (anchorRef != null) {
@@ -0,0 +1,11 @@
// "Assign Parameter to Field 'myId'" "true"
class Person {
int a;
int myId;
void f(int a, int id) {
this.a = foo(a);
myId = id;
}
int foo(int a) {return a;}
}
@@ -0,0 +1,10 @@
// "Assign Parameter to Field 'myId'" "true"
class Person {
int a;
int myId;
void f(int a, int id<caret>) {
this.a = foo(a);
}
int foo(int a) {return a;}
}
@@ -0,0 +1,17 @@
// "Convert to local" "false"
class TestFieldConversion
{
private static int som<caret>eInt = 0;
public TestFieldConversion()
{
int usingThatInt = someInt;
}
/**
* Referencing that value here {@value #someInt}
*/
public void someMethod() {
}
}
@@ -0,0 +1,21 @@
import javax.annotation.concurrent.GuardedBy;
class Example
{
private final Distribution distribution = new Distribution();
public void add(long value)
{
synchronized (distribution) {
distribution.total += value;
<error descr="Cannot resolve symbol 'total'">total</error> += value;
}
}
protected static class Distribution
{
@GuardedBy("this")
private long total = 0;
}
}
@@ -24,11 +24,20 @@ import org.jetbrains.annotations.NotNull;
public class FieldAccessedNotGuardedInspectionTest extends LightCodeInsightFixtureTestCase {
public void testItself() throws Exception {
myFixture.addClass("package net.jcip.annotations;\n" + getGuardedByAnnotationText());
myFixture.testHighlighting(true, false, false, getTestName(true) + ".java");
doTest();
}
public void testJavax_itself() throws Exception {
myFixture.addClass("package javax.annotation.concurrent;\n" + getGuardedByAnnotationText());
doTest();
}
public void testSyncOnFieldQualifier() throws Exception {
myFixture.addClass("package javax.annotation.concurrent;\n" + getGuardedByAnnotationText());
doTest();
}
private void doTest() {
myFixture.testHighlighting(true, false, false, getTestName(true) + ".java");
}
@@ -130,7 +130,7 @@ public class SetEditorSettingsAction extends ActionGroup implements DumbAware {
@Override
public void applyDefaults(@NotNull List<? extends Editor> editors) {
for (Editor editor : editors) {
if (editor != null && editor.getUserData(EditorImpl.FORCED_SOFT_WRAPS) != null) myForcedSoftWrap = true;
if (editor.getUserData(EditorImpl.FORCED_SOFT_WRAPS) != null) myForcedSoftWrap = true;
}
super.applyDefaults(editors);
}
@@ -169,7 +169,6 @@ public class SetEditorSettingsAction extends ActionGroup implements DumbAware {
public void setSelected(AnActionEvent e, boolean state) {
setSelected(state);
for (Editor editor : myEditors) {
if (editor == null) continue;
apply(editor, state);
}
}
@@ -182,7 +181,6 @@ public class SetEditorSettingsAction extends ActionGroup implements DumbAware {
public void applyDefaults(@NotNull List<? extends Editor> editors) {
for (Editor editor : editors) {
if (editor == null) continue;
apply(editor, isSelected());
}
}
@@ -214,7 +212,6 @@ public class SetEditorSettingsAction extends ActionGroup implements DumbAware {
private void apply(@NotNull HighlightingLevel layer) {
for (Editor editor : myEditors) {
if (editor == null) continue;
((EditorImpl)editor).setHighlightingFilter(layer.getCondition());
}
}
@@ -53,8 +53,15 @@ public class UISettings extends SimpleModificationTracker implements PersistentS
/** Not tabbed pane. */
public static final int TABS_NONE = 0;
private String lafID;
public static UISettings getInstance() {
return ServiceManager.getService(UISettings.class);
UISettings instance = ServiceManager.getService(UISettings.class);
if (!instance.lafID.equals(UIManager.getLookAndFeel().getID())) {
// Re-init if LaF changed.
instance.init();
}
return instance;
}
/**
@@ -135,6 +142,10 @@ public class UISettings extends SimpleModificationTracker implements PersistentS
private final EventDispatcher<UISettingsListener> myDispatcher = EventDispatcher.create(UISettingsListener.class);
public UISettings() {
init();
}
private void init() {
tweakPlatformDefaults();
setSystemFontFaceAndSize();
@@ -142,6 +153,7 @@ public class UISettings extends SimpleModificationTracker implements PersistentS
if (scrollToSource != null) {
DEFAULT_AUTOSCROLL_TO_SOURCE = scrollToSource;
}
lafID = UIManager.getLookAndFeel().getID();
}
private void tweakPlatformDefaults() {
@@ -181,11 +193,9 @@ public class UISettings extends SimpleModificationTracker implements PersistentS
}
private void setSystemFontFaceAndSize() {
if (FONT_FACE == null || FONT_SIZE <= 0) {
final Pair<String, Integer> fontData = getSystemFontFaceAndSize();
FONT_FACE = fontData.first;
FONT_SIZE = fontData.second;
}
final Pair<String, Integer> fontData = getSystemFontFaceAndSize();
FONT_FACE = fontData.first;
FONT_SIZE = fontData.second;
}
private static Pair<String, Integer> getSystemFontFaceAndSize() {
Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 B

After

Width:  |  Height:  |  Size: 92 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 B

After

Width:  |  Height:  |  Size: 170 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 B

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 B

After

Width:  |  Height:  |  Size: 88 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 B

After

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 B

After

Width:  |  Height:  |  Size: 88 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 B

After

Width:  |  Height:  |  Size: 165 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 B

After

Width:  |  Height:  |  Size: 165 B

@@ -34,7 +34,6 @@ import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.util.IncorrectOperationException;
@@ -235,8 +234,7 @@ public class CreateFileAction extends CreateElementActionBase implements DumbAwa
DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() {
@Override
public void run() {
final FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(new FakeVirtualFile(psiDirectory.getVirtualFile(), getFileName(inputString)),
project);
final FileType type = FileTypeChooser.getKnownFileTypeOrAssociate(psiDirectory.getVirtualFile(), getFileName(inputString), project);
result[0] = type != null && MyValidator.super.canClose(getFileName(inputString));
}
});
@@ -43,6 +43,7 @@ import com.intellij.util.Alarm;
import com.intellij.util.NullableFunction;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashSet;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.TextTransferable;
import com.intellij.util.ui.table.IconTableCellRenderer;
import org.jetbrains.annotations.NotNull;
@@ -99,10 +100,10 @@ public class InspectionsConfigTreeTable extends TreeTable {
return value;
}
});
severitiesColumn.setMaxWidth(20);
severitiesColumn.setMaxWidth(JBUI.scale(20));
final TableColumn isEnabledColumn = getColumnModel().getColumn(IS_ENABLED_COLUMN);
isEnabledColumn.setMaxWidth(20 + getAdditionalPadding());
isEnabledColumn.setMaxWidth(JBUI.scale(20 + getAdditionalPadding()));
isEnabledColumn.setCellRenderer(new ThreeStateCheckBoxRenderer());
isEnabledColumn.setCellEditor(new ThreeStateCheckBoxRenderer());
@@ -16,6 +16,7 @@
package com.intellij.profile.codeInspection.ui.table;
import com.intellij.profile.codeInspection.ui.inspectionsTree.InspectionsConfigTreeTable;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.util.SmartList;
import com.intellij.util.ui.ThreeStateCheckBox;
import org.jetbrains.annotations.Nullable;
@@ -43,7 +44,7 @@ public class ThreeStateCheckBoxRenderer extends ThreeStateCheckBox implements Ta
setThirdStateEnabled(false);
setHorizontalAlignment(CENTER);
setVerticalAlignment(CENTER);
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, InspectionsConfigTreeTable.getAdditionalPadding()));
setBorder(IdeBorderFactory.createEmptyBorder(0, 0, 0, InspectionsConfigTreeTable.getAdditionalPadding()));
addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
@@ -26,6 +26,7 @@ import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.ex.FileTypeChooser;
import com.intellij.openapi.help.HelpManager;
import com.intellij.openapi.keymap.KeymapUtil;
import com.intellij.openapi.project.Project;
@@ -51,6 +52,7 @@ import com.intellij.util.PathUtilRt;
import com.intellij.util.ui.FormBuilder;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
@@ -91,7 +93,7 @@ public class CopyFilesOrDirectoriesDialog extends DialogWrapper {
private PsiDirectory myTargetDirectory;
private boolean myFileCopy = false;
public CopyFilesOrDirectoriesDialog(PsiElement[] elements, PsiDirectory defaultTargetDirectory, Project project, boolean doClone) {
public CopyFilesOrDirectoriesDialog(PsiElement[] elements, @Nullable PsiDirectory defaultTargetDirectory, Project project, boolean doClone) {
super(project, true);
myElements = elements;
myProject = project;
@@ -122,6 +124,7 @@ public class CopyFilesOrDirectoriesDialog extends DialogWrapper {
myNewNameField.select(0, dotIdx);
myNewNameField.putClientProperty(DialogWrapperPeer.HAVE_INITIAL_SELECTION, true);
}
myTargetDirectory = file.getContainingDirectory();
myFileCopy = true;
}
else {
@@ -265,6 +268,10 @@ public class CopyFilesOrDirectoriesDialog extends DialogWrapper {
Messages.showErrorDialog(myNewNameField, "Name is not a valid file name");
return;
}
if (myFileCopy && FileTypeChooser.getKnownFileTypeOrAssociate(myTargetDirectory.getVirtualFile(), newName, myProject) == null) {
return;
}
}
saveOpenInEditorState(myOpenFilesInEditor.isSelected());
@@ -35,6 +35,7 @@ import com.intellij.openapi.wm.impl.DesktopLayout;
import com.intellij.openapi.wm.impl.IdeFrameImpl;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -147,7 +148,7 @@ public class TogglePresentationModeAction extends AnAction implements DumbAware
}
}
}
float scaleFactor = settings.PRESENTATION_MODE_FONT_SIZE / 12f;
float scaleFactor = settings.PRESENTATION_MODE_FONT_SIZE / UIUtil.DEF_SYSTEM_FONT_SIZE;
ourSavedScaleFactor = JBUI.scale(1f);
JBUI.setScaleFactor(scaleFactor);
for (Object key : ourSavedValues.keySet()) {
@@ -729,7 +729,7 @@ public final class LafManagerImpl extends LafManager implements ApplicationCompo
UISettings uiSettings = UISettings.getInstance();
if (uiSettings.OVERRIDE_NONIDEA_LAF_FONTS) {
storeOriginalFontDefaults(uiDefaults);
JBUI.setScaleFactor(uiSettings.FONT_SIZE/12f);
JBUI.setScaleFactor(uiSettings.FONT_SIZE/UIUtil.DEF_SYSTEM_FONT_SIZE);
initFontDefaults(uiDefaults, uiSettings.FONT_SIZE, new FontUIResource(uiSettings.FONT_FACE, Font.PLAIN, uiSettings.FONT_SIZE));
}
else {
@@ -745,7 +745,7 @@ public final class LafManagerImpl extends LafManager implements ApplicationCompo
defaults.put(resource, lfDefaults.get(resource));
}
}
JBUI.setScaleFactor(JBUI.Fonts.label().getSize()/12f);
JBUI.setScaleFactor(JBUI.Fonts.label().getSize()/UIUtil.DEF_SYSTEM_FONT_SIZE);
}
private void storeOriginalFontDefaults(UIDefaults defaults) {
@@ -149,7 +149,7 @@ public class DarculaLaf extends BasicLookAndFeel {
private static void applySystemFonts(UIDefaults defaults) {
try {
String fqn = UIManager.getSystemLookAndFeelClassName();
String fqn = UIUtil.getSystemLookAndFeelClassName();
Object systemLookAndFeel = Class.forName(fqn).newInstance();
final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults");
superMethod.setAccessible(true);
@@ -149,6 +149,14 @@ public class FileTypeChooser extends DialogWrapper {
return type;
}
/**
* Speculates if file with newName would have known file type
*/
@Nullable
public static FileType getKnownFileTypeOrAssociate(@NotNull VirtualFile parent, @NotNull String newName, @Nullable Project project) {
return getKnownFileTypeOrAssociate(new FakeVirtualFile(parent, newName), project);
}
@Nullable
public static FileType getKnownFileTypeOrAssociate(@NotNull String fileName) {
FileTypeManager fileTypeManager = FileTypeManager.getInstance();
@@ -197,7 +197,7 @@ abstract class LineBreakpointManager(internal val debugProcess: DebugProcessImpl
protected open fun checkDuplicates(newTarget: BreakpointTarget, location: Location, breakpointManager: BreakpointManager): Breakpoint? = null
fun runToLocation(position: XSourcePosition) {
fun runToLocation(position: XSourcePosition, vm: Vm) {
val addedBreakpoints = doRunToLocation(position)
if (addedBreakpoints.isEmpty()) {
return
@@ -206,7 +206,7 @@ abstract class LineBreakpointManager(internal val debugProcess: DebugProcessImpl
synchronized (lock) {
runToLocationBreakpoints.addAll(addedBreakpoints)
}
debugProcess.resume(debugProcess.activeOrMainVm!!)
debugProcess.resume(vm)
}
protected abstract fun doRunToLocation(position: XSourcePosition): List<Breakpoint>
@@ -468,6 +468,9 @@ cvs.roots.refresh.uses.vfs=true
cvs.roots.refresh.uses.vfs.description=Should CVS roots refresh after update use VFS
vcs.add.remove.silent=true
ide.ui.scale.override=false
ide.ui.scale=1.0
ide.new.notification.enabled=false
ide.new.notification.visible.count=2
@@ -36,61 +36,35 @@ import java.awt.*;
public class JBUI {
private static final Logger LOG = Logger.getInstance("#com.intellij.util.ui.JBUI");
private static float SCALE_FACTOR = calculateScaleFactor();
private static float scaleFactor = 1.0f;
private static float calculateScaleFactor() {
static {
calculateScaleFactor();
}
private static void calculateScaleFactor() {
if (SystemInfo.isMac) {
LOG.info("UI scale factor: 1.0");
return 1.0f;
scaleFactor = 1.0f;
return;
}
if (SystemProperties.has("hidpi") && !SystemProperties.is("hidpi")) {
LOG.info("UI scale factor: 1.0");
return 1.0f;
scaleFactor = 1.0f;
return;
}
float s = 1f;
UIUtil.initSystemFontData();
Pair<String, Integer> fdata = UIUtil.getSystemFontData();
// On Linux: rely on DPI
if (SystemInfo.isLinux) {
final int dpi = getSystemDPI();
if (dpi < 120) s = 1f;
else if (dpi < 144) s = 1.25f;
else if (dpi < 168) s = 1.5f;
else if (dpi < 192) s = 1.75f;
else s = 2f;
LOG.info("UI scale factor: " + s);
return s;
}
int size = -1;
// On Windows: rely on default system font
if (SystemInfo.isWindows) {
UIUtil.initSystemFontData();
Pair<String, Integer> fdata = UIUtil.getSystemFontData();
if (fdata != null) size = fdata.getSecond();
}
if (size == -1) {
int size;
if (fdata != null) {
size = fdata.getSecond();
} else {
size = Fonts.label().getSize();
}
if (size <= 13) s = 1.0f;
else if (size <= 16) s = 1.25f;
else if (size <= 18) s = 1.5f;
else if (size < 24) s = 1.75f;
else s = 2.0f;
LOG.info("UI scale factor: " + s);
return s;
}
private static int getSystemDPI() {
try {
return Toolkit.getDefaultToolkit().getScreenResolution();
} catch (HeadlessException e) {
return 96;
}
setScaleFactor(size/UIUtil.DEF_SYSTEM_FONT_SIZE);
}
public static void setScaleFactor(float scale) {
@@ -108,19 +82,22 @@ public class JBUI {
//Default UI font size for Unity and Gnome is 15. Scaling factor 1.25f works badly on Linux
scale = 1f;
}
LOG.info("UI scale factor changed: " + scale);
if (scaleFactor == scale) {
return;
}
LOG.info("UI scale factor: " + scale);
SCALE_FACTOR = scale;
scaleFactor = scale;
IconLoader.setScale(scale);
}
public static int scale(int i) {
return Math.round(SCALE_FACTOR * i);
return Math.round(scaleFactor * i);
}
public static int scaleFontSize(int fontSize) {
if (SCALE_FACTOR == 1.25f) return (int)(fontSize * 1.34f);
if (SCALE_FACTOR == 1.75f) return (int)(fontSize * 1.67f);
if (scaleFactor == 1.25f) return (int)(fontSize * 1.34f);
if (scaleFactor == 1.75f) return (int)(fontSize * 1.67f);
return scale(fontSize);
}
@@ -177,7 +154,7 @@ public class JBUI {
}
public static float scale(float f) {
return f * SCALE_FACTOR;
return f * scaleFactor;
}
public static JBInsets insets(Insets insets) {
@@ -185,7 +162,7 @@ public class JBUI {
}
public static boolean isHiDPI() {
return SCALE_FACTOR > 1.0f;
return scaleFactor > 1.0f;
}
public static class Fonts {
@@ -323,6 +323,8 @@ public class UIUtil {
private static volatile Pair<String, Integer> ourSystemFontData = null;
public static final float DEF_SYSTEM_FONT_SIZE = 12f; // TODO: consider 12 * 1.33 to compensate JDK's 72dpi font scale
@NonNls private static final String ROOT_PANE = "JRootPane.future";
private static final Ref<Boolean> ourRetina = Ref.create(SystemInfo.isMac ? null : false);
@@ -2542,9 +2544,16 @@ public class UIUtil {
}
}
public static String getSystemLookAndFeelClassName() {
// Force GTK LaF on Linux to let it retrieve system font settings
// with proper font scale based on Xft.dpi
return SystemInfo.isLinux ? "com.sun.java.swing.plaf.gtk.GTKLookAndFeel" :
UIManager.getSystemLookAndFeelClassName();
}
public static void initDefaultLAF() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
UIManager.setLookAndFeel(getSystemLookAndFeelClassName());
initSystemFontData();
}
catch (Exception ignore) {}
@@ -2553,16 +2562,36 @@ public class UIUtil {
public static void initSystemFontData() {
if (ourSystemFontData != null) return;
// With JB Linux JDK the label font comes properly scaled based on Xft.dpi settings.
Font font = getLabelFont();
if (SystemInfo.isWindows) {
Float forcedScale = null;
if (Registry.is("ide.ui.scale.override")) {
forcedScale = Float.valueOf((float)Registry.get("ide.ui.scale").asDouble());
}
else if (SystemInfo.isLinux && !SystemInfo.isJetbrainsJvm) {
// With Oracle JDK: derive scale from X server DPI
float scale = getScreenScale();
if (scale > 1f) {
forcedScale = Float.valueOf(scale);
}
// Or otherwise leave the detected font. It's undetermined if it's scaled or not.
// If it is (likely with GTK DE), then the UI scale will be derived from it,
// if it's not, then IDEA will start unscaled. This lets the users of GTK DEs
// not to bother about X server DPI settings. Users of other DEs (like KDE)
// will have to set X server DPI to meet their display.
}
else if (SystemInfo.isWindows) {
//noinspection HardCodedStringLiteral
Font winFont = (Font)Toolkit.getDefaultToolkit().getDesktopProperty("win.messagebox.font");
if (winFont != null) font = winFont;
if (winFont != null) {
font = winFont; // comes scaled
}
}
else if (SystemInfo.isLinux && JBUI.isHiDPI()) {
// We don't expect the default GUI font to be scaled on Linux and do it ourselves.
// TODO: this is valid until HIDPI support comes to J2D/Swing on Linux.
font = JBFont.create(font);
if (forcedScale != null) {
// With forced scale, we derive font from a hard-coded value as we cannot be sure
// the system font comes unscaled.
font = font.deriveFont(DEF_SYSTEM_FONT_SIZE * forcedScale.floatValue());
}
ourSystemFontData = Pair.create(font.getName(), font.getSize());
}
@@ -2572,6 +2601,22 @@ public class UIUtil {
return ourSystemFontData;
}
private static float getScreenScale() {
int dpi = 96;
try {
dpi = Toolkit.getDefaultToolkit().getScreenResolution();
} catch (HeadlessException e) {
}
float scale = 1f;
if (dpi < 120) scale = 1f;
else if (dpi < 144) scale = 1.25f;
else if (dpi < 168) scale = 1.5f;
else if (dpi < 192) scale = 1.75f;
else scale = 2f;
return scale;
}
public static void addKeyboardShortcut(final JComponent target, final AbstractButton button, final KeyStroke keyStroke) {
target.registerKeyboardAction(
new ActionListener() {
@@ -27,6 +27,7 @@ import java.awt.*;
public class CurrentBranchHighlighter implements VcsLogHighlighter {
private static final JBColor CURRENT_BRANCH_BG = new JBColor(new Color(228, 250, 255), new Color(63, 71, 73));
private static final String HEAD = "HEAD";
@NotNull private final VcsLogDataManager myDataManager;
@NotNull private final VcsLogUi myLogUi;
@Nullable private String mySingleFilteredBranch;
@@ -42,7 +43,7 @@ public class CurrentBranchHighlighter implements VcsLogHighlighter {
if (isSelected || !myLogUi.isHighlighterEnabled(Factory.ID)) return VcsCommitStyle.DEFAULT;
VcsLogProvider provider = myDataManager.getLogProvider(details.getRoot());
String currentBranch = provider.getCurrentBranch(details.getRoot());
if (currentBranch != null && !(currentBranch.equals(mySingleFilteredBranch))) {
if (!HEAD.equals(mySingleFilteredBranch) && currentBranch != null && !(currentBranch.equals(mySingleFilteredBranch))) {
Condition<CommitId> condition =
myDataManager.getContainingBranchesGetter().getContainedInBranchCondition(currentBranch, details.getRoot());
if (condition.value(new CommitId(details.getId(), details.getRoot()))) {
@@ -88,32 +88,51 @@ public abstract class XDebugProcess {
public void startPausing() {
}
@Deprecated
/**
* Resume execution and call {@link XDebugSession#positionReached}
* when next line in current method/function is reached.
* Do not call this method directly. Use {@link XDebugSession#stepOver} instead
* @deprecated Use {@link #startStepOver(XSuspendContext)} instead
*/
public void startStepOver() {
throw new AbstractMethodError();
}
/**
* Resume execution and call {@link XDebugSession#positionReached}
* when next line in current method/function is reached.
* Do not call this method directly. Use {@link XDebugSession#stepOver} instead
*/
public void startStepOver(@Nullable XSuspendContext context) {
//noinspection deprecation
startStepOver();
}
@Deprecated
/**
* @deprecated Use {@link #startForceStepInto(XSuspendContext)} instead
*/
public void startForceStepInto(){
//noinspection deprecation
startStepInto();
}
/**
* Steps into suppressed call
*
* <p>
* Resume execution and call {@link XDebugSession#positionReached}
* when next line is reached.
* Do not call this method directly. Use {@link XDebugSession#forceStepInto} instead
*/
public void startForceStepInto(){
startStepInto();
public void startForceStepInto(@Nullable XSuspendContext context) {
//noinspection deprecation
startForceStepInto();
}
public void startForceStepInto(@Nullable XSuspendContext context) {
startForceStepInto();
@Deprecated
/**
* @deprecated Use {@link #startStepInto(XSuspendContext)} instead
*/
public void startStepInto() {
throw new AbstractMethodError();
}
/**
@@ -121,12 +140,17 @@ public abstract class XDebugProcess {
* when next line is reached.
* Do not call this method directly. Use {@link XDebugSession#stepInto} instead
*/
public void startStepInto() {
throw new AbstractMethodError();
public void startStepInto(@Nullable XSuspendContext context) {
//noinspection deprecation
startStepInto();
}
public void startStepInto(@Nullable XSuspendContext context) {
startStepInto();
@Deprecated
/**
* @deprecated Use {@link #startStepOut(XSuspendContext)} instead
*/
public void startStepOut() {
throw new AbstractMethodError();
}
/**
@@ -134,11 +158,8 @@ public abstract class XDebugProcess {
* after returning from current method/function.
* Do not call this method directly. Use {@link XDebugSession#stepOut} instead
*/
public void startStepOut() {
throw new AbstractMethodError();
}
public void startStepOut(@Nullable XSuspendContext context) {
//noinspection deprecation
startStepOut();
}
@@ -165,29 +186,40 @@ public abstract class XDebugProcess {
return Promise.DONE;
}
@Deprecated
/**
* Resume execution.
* Do not call this method directly. Use {@link XDebugSession#resume} instead
* @deprecated Use {@link #resume(XSuspendContext)} instead
*/
public void resume() {
throw new AbstractMethodError();
}
/**
* Resume execution.
* Do not call this method directly. Use {@link XDebugSession#resume} instead
*/
public void resume(@Nullable XSuspendContext context) {
//noinspection deprecation
resume();
}
@Deprecated
/**
* @deprecated Use {@link #runToPosition(XSuspendContext)} instead
*/
public void runToPosition(@NotNull XSourcePosition position) {
throw new AbstractMethodError();
}
/**
* Resume execution and call {@link XDebugSession#positionReached(com.intellij.xdebugger.frame.XSuspendContext)}
* when <code>position</code> is reached.
* Do not call this method directly. Use {@link XDebugSession#runToPosition} instead
*
* @param position position in source code
*/
public void runToPosition(@NotNull XSourcePosition position) {
throw new AbstractMethodError();
}
public void runToPosition(@NotNull XSourcePosition position, @Nullable XSuspendContext context) {
//noinspection deprecation
runToPosition(position);
}
@@ -905,7 +905,7 @@ public class JavaFxPsiUtil {
if (eventType instanceof PsiClassType) {
return (PsiClassType)eventType;
}
if (eventType instanceof PsiWildcardType) {
if (eventType instanceof PsiWildcardType) { // TODO Handle wildcards more accurately
final PsiType boundType = ((PsiWildcardType)eventType).getBound();
if (boundType instanceof PsiClassType) {
return (PsiClassType)boundType;
@@ -121,17 +121,17 @@ public class XsltDebugProcess extends XDebugProcess implements Disposable {
}
@Override
public void startStepOver() {
public void startStepOver(@Nullable XSuspendContext context) {
myDebuggerSession.stepOver();
}
@Override
public void startStepInto() {
public void startStepInto(@Nullable XSuspendContext context) {
myDebuggerSession.stepInto();
}
@Override
public void startStepOut() {
public void startStepOut(@Nullable XSuspendContext context) {
myDebuggerSession.stepOver();
}
@@ -155,7 +155,7 @@ public class XsltDebugProcess extends XDebugProcess implements Disposable {
}
@Override
public void resume() {
public void resume(@Nullable XSuspendContext context) {
myDebuggerSession.resume();
}
@@ -164,7 +164,7 @@ public class XsltDebugProcess extends XDebugProcess implements Disposable {
}
@Override
public void runToPosition(@NotNull XSourcePosition position) {
public void runToPosition(@NotNull XSourcePosition position, @Nullable XSuspendContext context) {
final PsiFile psiFile = PsiManager.getInstance(getSession().getProject()).findFile(position.getFile());
assert psiFile != null;
if (myDebuggerSession.canRunTo(position)) {
@@ -360,11 +360,12 @@ def exception_break(plugin, pydb, pydb_frame, frame, args, arg):
elif get_exception_name(exception) in ('TemplateSyntaxError', 'TemplateAssertionError'):
#errors in compile time
name = frame.f_code.co_name
if name in ('template', 'top-level template code') or name.startswith('block '):
if name in ('template', 'top-level template code', '<module>') or name.startswith('block '):
#Jinja2 translates exception info and creates fake frame on his own
pydb_frame.set_suspend(thread, CMD_ADD_EXCEPTION_BREAK, message=exception_type)
pydb_frame.set_suspend(thread, CMD_ADD_EXCEPTION_BREAK)
add_exception_to_frame(frame, (exception, value, trace))
thread.additional_info.suspend_type = JINJA2_SUSPEND
thread.additional_info.pydev_message = exception_type
flag = True
return flag, frame
return None
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -40,7 +40,7 @@ public class PyRequirement {
private static final Pattern NAME = Pattern.compile("\\s*(\\w(\\w|[-.])*)\\s*(.*)");
private static final Pattern VERSION_SPEC = Pattern.compile("\\s*(<=?|>=?|==|!=)\\s*((\\w|[-.])+)");
private static final Pattern EDITABLE_EGG = Pattern.compile("\\s*(-e)?\\s*([^#]*)(#egg=(.*))?");
private static final Pattern RECURSIVE_REQUIREMENT = Pattern.compile("\\s*-r\\s+(.*)");
private static final Pattern RECURSIVE_REQUIREMENT = Pattern.compile("^-r\\s*(.*)");
private static final Pattern VCS_PATH = Pattern.compile(".*/([^/]+)/?");
public enum Relation {
@@ -253,7 +253,7 @@ public class PyRequirement {
*
* @param line requirement to parse
* @return requirement
* @throws java.lang.IllegalArgumentException if line can't be parsed
* @throws IllegalArgumentException if line can't be parsed
*/
@NotNull
public static PyRequirement fromStringGuaranteed(@NotNull final String line) {
@@ -304,7 +304,7 @@ public class PyRequirement {
}
@NotNull
public static List<PyRequirement> parse(@NotNull VirtualFile file, @NotNull Set<VirtualFile> visited) {
private static List<PyRequirement> parse(@NotNull VirtualFile file, @NotNull Set<VirtualFile> visited) {
if (!visited.contains(file)) {
visited.add(file);
final Document document = FileDocumentManager.getInstance().getDocument(file);
@@ -339,9 +339,9 @@ public class PyRequirement {
}
@NotNull
private static List<PyRequirement> parseRecursiveRequirement(@NotNull String line, @NotNull VirtualFile anchor,
private static List<PyRequirement> parseRecursiveRequirement(@NotNull String trimmedLine, @NotNull VirtualFile anchor,
@NotNull Set<VirtualFile> visited) {
final Matcher matcher = RECURSIVE_REQUIREMENT.matcher(line);
final Matcher matcher = RECURSIVE_REQUIREMENT.matcher(trimmedLine);
if (matcher.matches()) {
final String fileName = FileUtil.toSystemIndependentName(matcher.group(1));
final VirtualFile dir = anchor.getParent();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -360,7 +360,7 @@ public class PyNames {
.put("__rmod__", _self_other_descr)
.put("__rmul__", _self_other_descr)
.put("__ror__", _self_other_descr)
.put("__rpow__", new BuiltinDescription("(self, power, modulo=None)"))
.put("__rpow__", _self_other_descr)
.put("__rrshift__", _self_other_descr)
.put("__rshift__", _self_other_descr)
.put("__rsub__", _self_other_descr)
@@ -491,7 +491,7 @@ public class RemoteDebugger implements ProcessDebugger {
private StringBuilder myTextBuilder = new StringBuilder();
private DebuggerReader(final InputStream stream) throws IOException {
super(stream, CharsetToolkit.UTF8_CHARSET, SleepingPolicy.BLOCKING); //TODO: correct encoding?
super(stream, CharsetToolkit.UTF8_CHARSET); //TODO: correct encoding?
start(getClass().getName());
}
@@ -407,7 +407,7 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr
}
@Override
public void resume() {
public void resume(@Nullable XSuspendContext context) {
passToAllThreads(ResumeOrStepCommand.Mode.RESUME);
}
@@ -0,0 +1,2 @@
class Cl(object):
def __rpow__(self, other):
@@ -0,0 +1,2 @@
class Cl(object):
def __rp<caret>
@@ -0,0 +1 @@
bitly_api
@@ -0,0 +1 @@
numpy
@@ -0,0 +1,2 @@
-r requirements.a.txt
-rrequirements.b.txt
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
*/
package com.jetbrains.python;
import com.intellij.openapi.vfs.VirtualFile;
import com.jetbrains.python.fixtures.PyTestCase;
import com.jetbrains.python.packaging.PyPackage;
import com.jetbrains.python.packaging.PyRequirement;
@@ -100,6 +101,15 @@ public class PyRequirementTest extends PyTestCase {
PyRequirement.fromString("git+git://github.com/django/django.git@stable/1.5.x"));
}
// PY-18543
public void testRecursiveRequirement() {
final VirtualFile requirementsFile = getVirtualFileByName(getTestDataPath() + "/requirement/recursive/requirements.txt");
assertNotNull(requirementsFile);
assertEquals(list(new PyRequirement("bitly_api"), new PyRequirement("numpy")),
PyRequirement.parse(requirementsFile));
}
private static <T> List<T> list(T... xs) {
return Arrays.asList(xs);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -981,6 +981,11 @@ public class PythonCompletionTest extends PyTestCase {
doMultiFileTest();
}
// PY-18684
public void testRPowSignature() {
doTest();
}
@Override
protected String getTestDataPath() {
return super.getTestDataPath() + "/completion";