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

This commit is contained in:
Vasily Romanikhin
2017-10-25 16:17:02 +03:00
24 changed files with 209 additions and 211 deletions
@@ -64,10 +64,7 @@ public class WrapWithAdapterMethodCallFix extends LocalQuickFixAndIntentionActio
return false;
}
PsiType variableType = GenericsUtil.getVariableTypeByExpressionType(inType);
if(variableType instanceof PsiLambdaExpressionType || variableType instanceof PsiMethodReferenceType
|| variableType instanceof PsiLambdaParameterType) {
return false;
}
if (LambdaUtil.notInferredType(variableType)) return false;
String typeText = variableType.getCanonicalText();
PsiExpression replacement = createReplacement(context, "((" + typeText + ")null)");
@@ -196,7 +196,7 @@ public class DuplicatesFinder {
ArrayList<PsiElement> candidates = new ArrayList<>();
for (final PsiElement element : myPattern) {
if (sibling == null) return null;
if (!canBeEquivalent(element, sibling) || sibling != candidate && isSelf(sibling)) return null;
if (!canBeEquivalent(element, sibling) || isSelf(sibling)) return null;
candidates.add(sibling);
sibling = PsiTreeUtil.skipSiblingsForward(sibling, PsiWhiteSpace.class, PsiComment.class, PsiEmptyStatement.class);
}
@@ -3,7 +3,7 @@ public class X {
<caret>int i;
@org.testng.annotations.BeforeMethod
public void setUp() throws Exception {
public void setUp() {
i = 7;
}
@@ -49,8 +49,9 @@ public class UsageInfo {
int effectiveEnd;
if (startOffset == -1 && endOffset == -1) {
// calculate natural element range
effectiveStart = element.getTextOffset() - elementRange.getStartOffset();
effectiveEnd = elementRange.getLength();
// Cls element.getTextOffset() returns -1
effectiveStart = Math.max(0, element.getTextOffset() - elementRange.getStartOffset());
effectiveEnd = Math.max(effectiveStart, elementRange.getLength());
}
else {
effectiveStart = startOffset;
@@ -44,6 +44,7 @@ public interface ExtensionsArea {
void registerExtensionPoint(@NotNull PluginDescriptor pluginDescriptor, @NotNull Element extensionPointElement);
void registerExtension(@NotNull PluginDescriptor pluginDescriptor, @NotNull Element extensionElement, String ns);
void registerExtension(@NotNull final ExtensionPoint extensionPoint, @NotNull final PluginDescriptor pluginDescriptor, @NotNull final Element extensionElement);
String getAreaClass();
}
@@ -131,20 +131,23 @@ public class ExtensionsAreaImpl implements ExtensionsArea {
@Override
public void registerExtension(@NotNull final PluginDescriptor pluginDescriptor, @NotNull final Element extensionElement, String ns) {
final PluginId pluginId = pluginDescriptor.getPluginId();
String epName = extractEPName(extensionElement, ns);
registerExtension(getExtensionPoint(epName), pluginDescriptor, extensionElement);
}
// Used in Upsource
@Override
public void registerExtension(@NotNull final ExtensionPoint extensionPoint, @NotNull final PluginDescriptor pluginDescriptor, @NotNull final Element extensionElement) {
if (!Extensions.isComponentSuitableForOs(extensionElement.getAttributeValue("os"))) {
return;
}
String epName = extractEPName(extensionElement, ns);
ExtensionComponentAdapter adapter;
final ExtensionPointImpl extensionPoint = getExtensionPoint(epName);
if (extensionPoint.getKind() == ExtensionPoint.Kind.INTERFACE) {
String implClass = extensionElement.getAttributeValue("implementation");
if (implClass == null) {
throw new RuntimeException("'implementation' attribute not specified for '" + epName + "' extension in '" + pluginId.getIdString() + "' plugin");
throw new RuntimeException("'implementation' attribute not specified for '" + extensionPoint.getName() + "' extension in '"
+ pluginDescriptor.getPluginId().getIdString() + "' plugin");
}
adapter = new ExtensionComponentAdapter(implClass, extensionElement, myPicoContainer, pluginDescriptor, shouldDeserializeInstance(extensionElement));
}
@@ -152,7 +155,7 @@ public class ExtensionsAreaImpl implements ExtensionsArea {
adapter = new ExtensionComponentAdapter(extensionPoint.getClassName(), extensionElement, myPicoContainer, pluginDescriptor, true);
}
myPicoContainer.registerComponent(adapter);
extensionPoint.registerExtensionAdapter(adapter);
((ExtensionPointImpl)extensionPoint).registerExtensionAdapter(adapter);
}
private static boolean shouldDeserializeInstance(Element extensionElement) {
@@ -35,6 +35,8 @@ public interface RunDashboardGroupingRule extends TreeAction {
return res != 0 ? res : (o1.getName().compareTo(o2.getName()));
};
Comparator<RunDashboardGroup> GROUP_NAME_COMPARATOR = Comparator.comparing(RunDashboardGroup::getName);
/**
* Grouping rules are ordered and applied to dashboard nodes according to their priority.
* The higher the priority, the higher groups produced by this rule are presented in the dashboard tree.
@@ -60,6 +62,10 @@ public interface RunDashboardGroupingRule extends TreeAction {
@Nullable
RunDashboardGroup getGroup(AbstractTreeNode<?> node);
default Comparator<RunDashboardGroup> getGroupComparator() {
return GROUP_NAME_COMPARATOR;
}
interface Priorities {
int BY_RUN_CONFIG = 200;
int BY_FOLDER = 400;
@@ -27,18 +27,22 @@ import javax.swing.*;
*/
public class RunDashboardRunConfigurationStatus {
public static final RunDashboardRunConfigurationStatus STARTED = new RunDashboardRunConfigurationStatus(
ExecutionBundle.message("run.dashboard.started.group.name"), AllIcons.Toolwindows.ToolWindowRun);
public static final RunDashboardRunConfigurationStatus STOPPED = new RunDashboardRunConfigurationStatus(
ExecutionBundle.message("run.dashboard.stopped.group.name"), AllIcons.Actions.Suspend);
ExecutionBundle.message("run.dashboard.started.group.name"), AllIcons.Actions.Execute, 10);
public static final RunDashboardRunConfigurationStatus FAILED = new RunDashboardRunConfigurationStatus(
ExecutionBundle.message("run.dashboard.failed.group.name"), AllIcons.General.Error);
ExecutionBundle.message("run.dashboard.failed.group.name"), AllIcons.General.Error, 20);
public static final RunDashboardRunConfigurationStatus STOPPED = new RunDashboardRunConfigurationStatus(
ExecutionBundle.message("run.dashboard.stopped.group.name"), AllIcons.Actions.Restart, 30);
public static final RunDashboardRunConfigurationStatus CONFIGURED = new RunDashboardRunConfigurationStatus(
ExecutionBundle.message("run.dashboard.configured.group.name"), AllIcons.General.Settings, 40);
private final String myName;
private final Icon myIcon;
private final int myPriority;
public RunDashboardRunConfigurationStatus(String name, Icon icon) {
public RunDashboardRunConfigurationStatus(String name, Icon icon, int priority) {
myName = name;
myIcon = icon;
myPriority = priority;
}
public String getName() {
@@ -49,10 +53,14 @@ public class RunDashboardRunConfigurationStatus {
return myIcon;
}
public int getPriority() {
return myPriority;
}
public static RunDashboardRunConfigurationStatus getStatus(RunDashboardRunConfigurationNode node) {
RunContentDescriptor descriptor = node.getDescriptor();
if (descriptor == null) {
return STOPPED;
return CONFIGURED;
}
ProcessHandler processHandler = descriptor.getProcessHandler();
if (processHandler == null) {
@@ -80,8 +80,14 @@ class RunConfigurationNode extends AbstractTreeNode<Pair<RunnerAndConfigurationS
RunnerAndConfigurationSettings configurationSettings = getConfigurationSettings();
//noinspection ConstantConditions
boolean isStored = RunManager.getInstance(getProject()).hasSettings(configurationSettings);
presentation.addText(configurationSettings.getName(),
isStored ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.GRAY_ATTRIBUTES);
SimpleTextAttributes nameAttributes;
if (isStored) {
nameAttributes = getContent() != null ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES;
}
else {
nameAttributes = SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES;
}
presentation.addText(configurationSettings.getName(), nameAttributes);
Icon icon = null;
RunDashboardRunConfigurationStatus status = myContributor != null ? myContributor.getStatus(this) :
RunDashboardRunConfigurationStatus.getStatus(this);
@@ -33,6 +33,10 @@ public class RunDashboardGroupImpl<T> implements RunDashboardGroup {
myIcon = icon;
}
public T getValue() {
return myValue;
}
@Override
public String getName() {
return myName;
@@ -50,6 +54,9 @@ public class RunDashboardGroupImpl<T> implements RunDashboardGroup {
@Override
public final boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof RunDashboardGroupImpl) {
return myValue.equals(((RunDashboardGroupImpl)obj).myValue);
}
@@ -138,7 +138,7 @@ public class RunDashboardTreeStructure extends AbstractTreeStructureBase {
});
}
else {
Collections.sort(result, Comparator.comparing(node -> ((GroupingNode)node).getGroup().getName()));
Collections.sort(result, Comparator.comparing(node -> ((GroupingNode)node).getGroup(), rule.getGroupComparator()));
result.addAll(ungroupedNodes);
}
return result;
@@ -25,6 +25,8 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Comparator;
/**
* @author konstantin.aleev
*/
@@ -72,4 +74,10 @@ public class StatusDashboardGroupingRule implements RunDashboardGroupingRule {
}
return null;
}
@Override
public Comparator<RunDashboardGroup> getGroupComparator() {
//noinspection unchecked
return Comparator.comparing(group -> ((RunDashboardGroupImpl<RunDashboardRunConfigurationStatus>)group).getValue().getPriority());
}
}
@@ -15,6 +15,7 @@
*/
package com.intellij.ide.ui.laf.darcula.ui;
import com.intellij.openapi.progress.util.ColorProgressBar;
import com.intellij.ui.Gray;
import com.intellij.ui.JBColor;
import com.intellij.util.ui.JBInsets;
@@ -36,16 +37,14 @@ public class DarculaProgressBarUI extends BasicProgressBarUI {
private static final Color REMAINDER_COLOR = new JBColor(Gray.xC4, Gray.x69);
private static final Color FINISHED_COLOR = new JBColor(Gray.x80, Gray.xA0);
private static final Color ERROR_COLOR = new JBColor(new Color(0xd80000), new Color(0xff4053));
private static final Color SUCCESS_COLOR = new JBColor(new Color(0x34b171), new Color(0x008f50));
private static final Color START_COLOR = new JBColor(Gray.xC4, Gray.x69);
private static final Color END_COLOR = new JBColor(Gray.x80, Gray.x83);
private static final Color ERROR_START_COLOR = new JBColor(new Color(0xFB8F89), new Color(0xf4a2a0));
private static final Color ERROR_END_COLOR = ERROR_COLOR;
private static final Color SUCCESS_START_COLOR = new JBColor(new Color(0x7EE8A5), new Color(0x5dc48f));
private static final Color SUCCESS_END_COLOR = SUCCESS_COLOR;
private static final Color RED = new JBColor(new Color(0xd80000), new Color(0xff4053));
private static final Color RED_LIGHT = new JBColor(new Color(0xFB8F89), new Color(0xf4a2a0));
private static final Color GREEN = new JBColor(new Color(0x34b171), new Color(0x008f50));
private static final Color GREEN_LIGHT = new JBColor(new Color(0x7EE8A5), new Color(0x5dc48f));
private static final int STEP = 6;
@@ -78,15 +77,16 @@ public class DarculaProgressBarUI extends BasicProgressBarUI {
JBInsets.removeFrom(r, i);
int orientation = progressBar.getOrientation();
// Detect gradient color
// Use foreground color as a reference, don't use it directly. This is done for compatibility reason.
// Colors are hardcoded in UI delegates by design. If more colors are needed contact designers.
Color startColor, endColor;
String type = (String)progressBar.getClientProperty("ProgressBar.color");
if ("error".equals(type)) {
startColor = ERROR_START_COLOR;
endColor = ERROR_END_COLOR;
} else if ("success".equals(type)) {
startColor = SUCCESS_START_COLOR;
endColor = SUCCESS_END_COLOR;
Color foreground = progressBar.getForeground();
if (foreground == ColorProgressBar.RED) {
startColor = RED;
endColor = RED_LIGHT;
} else if (foreground == ColorProgressBar.GREEN) {
startColor = GREEN;
endColor = GREEN_LIGHT;
} else {
startColor = getStartColor();
endColor = getEndColor();
@@ -206,12 +206,13 @@ public class DarculaProgressBarUI extends BasicProgressBarUI {
g2.setColor(getRemainderColor());
g2.fill(fullShape);
String type = (String)progressBar.getClientProperty("ProgressBar.color");
if ("error".equals(type)) {
g2.setColor(ERROR_COLOR);
} else if ("success".equals(type)) {
g2.setColor(SUCCESS_COLOR);
// Use foreground color as a reference, don't use it directly. This is done for compatibility reason.
// Colors are hardcoded in UI delegates by design. If more colors are needed contact designers.
Color foreground = progressBar.getForeground();
if (foreground == ColorProgressBar.RED) {
g2.setColor(RED);
} else if (foreground == ColorProgressBar.GREEN) {
g2.setColor(GREEN);
} else {
g2.setColor(getFinishedColor());
}
@@ -38,8 +38,10 @@ public class HidpiInfo extends AnAction implements DumbAware {
private final String JRE_HIDPI_MODE_TEXT = "Per-monitor DPI-aware";
private final String JRE_HIDPI_MODE_DESC =
"<html><span style='font-size:x-small'>When enabled, the IDE UI scaling honors per-monitor DPI.<br>" +
(SystemInfo.isWindows ?
"To " + (ENABLED ? "disable" : "enable") + " set the JVM option <code>-Dsun.java2d.uiScale.enabled=" +
(ENABLED ? "false" : "true") + "</code> and restart.</span></html>";
(ENABLED ? "false" : "true") + "</code> and restart.</span></html>" :
"The mode can not be changed on this platform.");
private final String SYS_SCALE_TEXT = "Monitor scale";
private final String SYS_SCALE_DESC =
@@ -20,8 +20,6 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.vfs.InvalidVirtualFileAccessException;
import com.intellij.openapi.vfs.newvfs.persistent.FSRecords;
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS;
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl;
import com.intellij.util.ArrayUtil;
import com.intellij.util.concurrency.AtomicFieldUpdater;
import com.intellij.util.containers.ConcurrentBitSet;
@@ -64,12 +62,12 @@ import static com.intellij.util.ObjectUtils.assertNotNull;
* and creates the file instance. See {@link #initFile}
*
* 3. After that the file is live, an object representing it can be retrieved any time from its parent. File system roots are
* kept on hard references in {@link PersistentFS}
* kept on hard references in {@link com.intellij.openapi.vfs.newvfs.persistent.PersistentFS}
*
* 4. If a file is deleted (invalidated), then its data is not needed anymore, and should be removed. But this can only happen after
* all the listener have been notified about the file deletion and have had their chance to look at the data the last time. See {@link #killInvalidatedFiles()}
*
* 5. The file with removed data is marked as "dead" (see {@link #ourDeadMarker}, any access to it will throw {@link InvalidVirtualFileAccessException}
* 5. The file with removed data is marked as "dead" (see {@link #ourDeadMarker}, any access to it will throw {@link com.intellij.openapi.vfs.InvalidVirtualFileAccessException}
* Dead ids won't be reused in the same session of the IDE.
*
* @author peter
@@ -112,11 +110,7 @@ public class VfsData {
}
@Nullable
static VirtualFileSystemEntry getFileById(int id, @NotNull VirtualDirectoryImpl parent) {
PersistentFSImpl persistentFS = (PersistentFSImpl)PersistentFS.getInstance();
VirtualFileSystemEntry dir = persistentFS.getCachedDir(id);
if (dir != null) return dir;
static VirtualFileSystemEntry getFileById(int id, VirtualDirectoryImpl parent) {
Segment segment = getSegment(id, false);
if (segment == null) return null;
@@ -133,7 +127,7 @@ public class VfsData {
throw new AssertionError("nameId=" + nameId + "; data=" + o + "; parent=" + parent + "; parent.id=" + parent.getId() + "; db.parent=" + FSRecords.getParent(id));
}
return o instanceof DirectoryData ? persistentFS.getOrCacheDir(id, segment, (DirectoryData)o, parent)
return o instanceof DirectoryData ? new VirtualDirectoryImpl(id, segment, (DirectoryData)o, parent, parent.getFileSystem())
: new VirtualFileImpl(id, segment, parent);
}
@@ -279,7 +273,7 @@ public class VfsData {
private Set<CharSequence> myAdoptedNames; // guarded by this
@NotNull
VirtualFileSystemEntry[] getFileChildren(int fileId, @NotNull VirtualDirectoryImpl parent) {
VirtualFileSystemEntry[] getFileChildren(int fileId, VirtualDirectoryImpl parent) {
assert fileId > 0;
VirtualFileSystemEntry[] children = new VirtualFileSystemEntry[myChildrenIds.length];
for (int i = 0; i < myChildrenIds.length; i++) {
@@ -69,7 +69,7 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone
private final ConcurrentIntObjectMap<VirtualFileSystemEntry> myRootsById = ContainerUtil.createConcurrentIntObjectMap(10, 0.4f, JobSchedulerImpl.CORES_COUNT);
// FS roots must be in this map too. findFileById() relies on this.
private final ConcurrentIntObjectMap<VirtualFileSystemEntry> myIdToDirCache = ContainerUtil.createConcurrentIntObjectSoftValueMap();
private final ConcurrentIntObjectMap<VirtualFileSystemEntry> myIdToDirCache = ContainerUtil.createConcurrentIntObjectMap();
private final Object myInputLock = new Object();
private final AtomicBoolean myShutDown = new AtomicBoolean(false);
@@ -121,20 +121,6 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone
return FSRecords.getCreationTimestamp();
}
@NotNull
public VirtualFileSystemEntry getOrCacheDir(int id,
@NotNull VfsData.Segment segment,
@NotNull VfsData.DirectoryData o,
@NotNull VirtualDirectoryImpl parent) {
VirtualFileSystemEntry dir = myIdToDirCache.get(id);
if (dir != null) return dir;
dir = new VirtualDirectoryImpl(id, segment, o, parent, parent.getFileSystem());
return myIdToDirCache.cacheOrGet(id, dir);
}
public VirtualFileSystemEntry getCachedDir(int id) {
return myIdToDirCache.get(id);
}
@NotNull
private static NewVirtualFileSystem getDelegate(@NotNull VirtualFile file) {
return (NewVirtualFileSystem)file.getFileSystem();
@@ -1053,10 +1039,11 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone
@Override
public void clearIdCache() {
// remove all except myRootsById contents
int[] ids = myIdToDirCache.keys();
for (int id : ids) {
for (Iterator<ConcurrentIntObjectMap.IntEntry<VirtualFileSystemEntry>> iterator = myIdToDirCache.entries().iterator(); iterator.hasNext(); ) {
ConcurrentIntObjectMap.IntEntry<VirtualFileSystemEntry> entry = iterator.next();
int id = entry.getKey();
if (!myRootsById.containsKey(id)) {
myIdToDirCache.remove(id);
iterator.remove();
}
}
}
@@ -18,6 +18,7 @@ package com.intellij.openapi.wm.impl.status;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.progress.util.ColorProgressBar;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
@@ -25,6 +26,7 @@ import com.intellij.util.Alarm;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
@@ -49,17 +51,17 @@ public class ShowProgressTestDialogAction extends AnAction implements DumbAware
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(createPanel(false, null, false));
panel.add(createPanel(false, "error", false));
panel.add(createPanel(false, "success", false));
panel.add(createPanel(false, ColorProgressBar.RED, false));
panel.add(createPanel(false, ColorProgressBar.GREEN, false));
panel.add(createPanel(false, null, true));
panel.add(createPanel(false, "error", true));
panel.add(createPanel(false, "success", true));
panel.add(createPanel(false, ColorProgressBar.RED, true));
panel.add(createPanel(false, ColorProgressBar.GREEN, true));
panel.add(createPanel(true, null, false));
panel.add(createPanel(true, null, true));
panel.add(createPanel(true, "error", false));
panel.add(createPanel(true, "success", false));
panel.add(createPanel(true, "error", true));
panel.add(createPanel(true, "success", true));
panel.add(createPanel(true, ColorProgressBar.RED, false));
panel.add(createPanel(true, ColorProgressBar.GREEN, false));
panel.add(createPanel(true, ColorProgressBar.RED, true));
panel.add(createPanel(true, ColorProgressBar.GREEN, true));
for(JProgressBar pb : pbList) {
if (!pb.isIndeterminate()) {
@@ -78,14 +80,14 @@ public class ShowProgressTestDialogAction extends AnAction implements DumbAware
return panel;
}
private JComponent createPanel(boolean indeterminate, String colorType, boolean modeless) {
private JComponent createPanel(boolean indeterminate, Color foreground, boolean modeless) {
String text = (indeterminate ? "indeterminate" : "determinate");
JLabel label = new JLabel(text);
JProgressBar progress = new JProgressBar(0, 100);
progress.setIndeterminate(indeterminate);
progress.setValue(0);
progress.putClientProperty("ProgressBar.color", colorType);
progress.setForeground(foreground);
progress.putClientProperty("ProgressBar.modeless", Boolean.valueOf(modeless));
JPanel panel = new JPanel();
@@ -407,8 +407,9 @@ run.dashboard.previous.configuration.action.name=Previous Started Configuration
run.dashboard.next.configuration.action.name=Next Started Configuration
run.dashboard.remove.configuration.dialog.title=Remove Configuration
run.dashboard.remove.configuration.dialog.message=Are you sure to remove selected configuration(s)?
run.dashboard.started.group.name=Started
run.dashboard.stopped.group.name=Stopped
run.dashboard.started.group.name=Running
run.dashboard.stopped.group.name=Finished
run.dashboard.configured.group.name=Configured
run.dashboard.failed.group.name=Failed
run.dashboard.group.configurations.title=Group Configurations
run.dashboard.group.configurations.label=Group Name:
@@ -1,16 +1,18 @@
// Copyright 2000-2017 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.
/*
* 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.
* 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.util.text;
@@ -72,14 +74,6 @@ public class CharSequenceSubSequence implements CharSequence, CharArrayExternali
CharArrayUtil.getChars(myChars, dest, start + myStart, destPos, end - start);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o instanceof CharSequenceSubSequence && hashCode() != o.hashCode()) return false;
if (o == null || !(o instanceof CharSequence)) return false;
return StringUtil.equals(this, (CharSequence)o);
}
private transient int hash;
@Override
public int hashCode() {
@@ -563,17 +563,22 @@ public class JBUI {
* @return the original graphics transform when aligned, otherwise null
*/
public static AffineTransform alignToIntGrid(@NotNull Graphics2D g) {
AffineTransform tx = g.getTransform();
double scaleX = tx.getScaleX();
double scaleY = tx.getScaleY();
boolean fpsTx = scaleX != (int)scaleX || scaleY != (int)scaleY;
if (fpsTx) {
AffineTransform alignedTx = new AffineTransform();
alignedTx.translate((int)Math.ceil(tx.getTranslateX() - 0.5), (int)Math.ceil(tx.getTranslateY() - 0.5));
alignedTx.scale(scaleX, scaleY);
assert tx.getShearX() == 0 && tx.getShearY() == 0; // the shear is ignored
g.setTransform(alignedTx);
return tx;
try {
AffineTransform tx = g.getTransform();
double scaleX = tx.getScaleX();
double scaleY = tx.getScaleY();
boolean fpsTx = scaleX != (int)scaleX || scaleY != (int)scaleY;
if (fpsTx) {
AffineTransform alignedTx = new AffineTransform();
alignedTx.translate((int)Math.ceil(tx.getTranslateX() - 0.5), (int)Math.ceil(tx.getTranslateY() - 0.5));
alignedTx.scale(scaleX, scaleY);
assert tx.getShearX() == 0 && tx.getShearY() == 0; // the shear is ignored
g.setTransform(alignedTx);
return tx;
}
}
catch (Exception e) {
LOG.trace(e);
}
return null;
}
@@ -16,10 +16,8 @@
package com.siyeh.ig.bugs;
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReferenceExpression;
import com.intellij.psi.PsiType;
import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiUtil;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
@@ -76,27 +74,56 @@ public class EqualsBetweenInconvertibleTypesInspection extends BaseInspection {
@Override
public BaseInspectionVisitor buildVisitor() {
return new BaseEqualsVisitor() {
void checkTypes(@NotNull PsiReferenceExpression expression, @NotNull PsiType leftType, @NotNull PsiType rightType) {
boolean convertible = TypeUtils.areConvertible(leftType, rightType);
if (convertible) {
if (!WARN_IF_NO_MUTUAL_SUBCLASS_FOUND) return;
if (leftType.isAssignableFrom(rightType) || rightType.isAssignableFrom(leftType)) return;
PsiClass leftClass = PsiUtil.resolveClassInClassTypeOnly(leftType);
PsiClass rightClass = PsiUtil.resolveClassInClassTypeOnly(rightType);
if (leftClass == null || rightClass == null) return;
if (!leftClass.isInterface() && !rightClass.isInterface()) return;
if (!rightClass.isInterface()) {
PsiClass tmp = leftClass;
leftClass = rightClass;
rightClass = tmp;
}
if (InheritanceUtil.existsMutualSubclass(leftClass, rightClass, isOnTheFly())) return;
}
if (TypeUtils.mayBeEqualByContract(leftType, rightType)) return;
PsiElement name = expression.getReferenceNameElement();
registerError(name == null ? expression : name, leftType, rightType, convertible);
return new EqualsBetweenInconvertibleTypesVisitor();
}
private class EqualsBetweenInconvertibleTypesVisitor extends BaseEqualsVisitor {
@Override
public void visitBinaryExpression(PsiBinaryExpression expression) {
super.visitBinaryExpression(expression);
if (!WARN_IF_NO_MUTUAL_SUBCLASS_FOUND) return;
final IElementType tokenType = expression.getOperationTokenType();
if (!tokenType.equals(JavaTokenType.EQEQ) && !tokenType.equals(JavaTokenType.NE)) {
return;
}
};
final PsiExpression lhs = expression.getLOperand();
final PsiType lhsType = lhs.getType();
final PsiExpression rhs = expression.getROperand();
if (rhs == null) {
return;
}
final PsiType rhsType = rhs.getType();
if (lhsType == null || rhsType == null || !TypeUtils.areConvertible(lhsType, rhsType)) {
// red code
return;
}
if (existsSharedSubclass(lhsType, rhsType)) {
return;
}
registerError(expression.getOperationSign(), lhsType, rhsType, true);
}
void checkTypes(@NotNull PsiReferenceExpression expression, @NotNull PsiType leftType, @NotNull PsiType rightType) {
boolean convertible = TypeUtils.areConvertible(leftType, rightType);
if (convertible && (!WARN_IF_NO_MUTUAL_SUBCLASS_FOUND || existsSharedSubclass(leftType, rightType))) return;
if (TypeUtils.mayBeEqualByContract(leftType, rightType)) return;
PsiElement name = expression.getReferenceNameElement();
registerError(name == null ? expression : name, leftType, rightType, convertible);
}
private boolean existsSharedSubclass(@NotNull PsiType leftType, @NotNull PsiType rightType) {
if (leftType.isAssignableFrom(rightType) || rightType.isAssignableFrom(leftType)) return true;
PsiClass leftClass = PsiUtil.resolveClassInClassTypeOnly(leftType);
PsiClass rightClass = PsiUtil.resolveClassInClassTypeOnly(rightType);
if (leftClass == null || rightClass == null) return true;
if (!leftClass.isInterface() && !rightClass.isInterface()) return true;
if (!rightClass.isInterface()) {
PsiClass tmp = leftClass;
leftClass = rightClass;
rightClass = tmp;
}
return InheritanceUtil.existsMutualSubclass(leftClass, rightClass, isOnTheFly());
}
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2013 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.
*/
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.siyeh.ig.bugs;
import com.intellij.codeInspection.InspectionProfileEntry;
@@ -102,6 +88,18 @@ public class EqualsBetweenInconvertibleTypesInspectionTest extends LightInspecti
"}");
}
public void testNoCommonSubclassEqualityComparison() {
doTest("import java.util.Date;\n" +
"import java.util.Map;\n" +
"import java.util.Objects;\n" +
"\n" +
"class X {\n" +
" public static boolean foo(Date date, Map<String, String> map) {\n" +
" return map /*No class found which is a subtype of both 'Map<String, String>' and 'Date'*/==/**/ date;\n" +
" }\n" +
"}");
}
public void testCommonSubclass() {
doTest("import java.util.Date;\n" +
"import java.util.Map;\n" +
@@ -38,6 +38,9 @@ public class CucumberJvmSMFormatterUtil {
}
public static String escape(String source) {
if (source == null) {
return "";
}
return source.replace("|", "||").replace("\n", "|n").replace("\r", "|r").replace("'", "|'").replace("[", "|[").replace("]", "|]");
}
}
@@ -18,7 +18,6 @@ argv
arial
arity
arquillian
asciifile
asensitive
aspectj
async
@@ -35,7 +34,6 @@ autoextend
autoincrement
autorelease
autorotate
autospace
backend
backref
backtrace
@@ -76,10 +74,8 @@ cglib
chai
changelog
changelist
charref
charset
charsets
charspacing
checkbox
checkboxes
checkstyle
@@ -126,8 +122,6 @@ covariant
cplusplus
cron
ctrl
currentx
currenty
customizer
customizers
cyclomatic
@@ -179,8 +173,6 @@ endif
enum
enums
eqeqeq
errorpolicy
escapesequence
eval
evex
exif
@@ -190,7 +182,6 @@ externalizer
facebook
facelet
facelets
fakebold
fallthrough
fastcall
favicon
@@ -199,15 +190,12 @@ fileset
filesets
filesystem
filesystems
fillrule
finalizer
finalizers
findbugs
firefox
fixme
foldr
fontname
fontsize
foreach
formatter
freelist
@@ -234,7 +222,6 @@ gists
github
gitlab
globals
glyphcheck
google
grapheme
gruntfile
@@ -257,9 +244,6 @@ hazelcast
hdiv
helvetica
holdability
honoriccprofile
honorlang
horizscaling
hostname
hprof
href
@@ -268,17 +252,8 @@ hsqldb
html
http
https
hypertextencoding
hypertextformat
icccomponents
iccprofile
iccprofilecmyk
iccprofilegray
iccprofilergb
iconable
iife
imageheight
imagewidth
impl
implementor
implementors
@@ -307,7 +282,6 @@ iphone
iphoneos
isnan
isnull
italicangle
jacoco
javabean
javabeans
@@ -351,7 +325,6 @@ lcovonly
ldap
lexing
libxml
licensefile
lifecycle
likec
linestring
@@ -365,7 +338,6 @@ localtime
localtimestamp
logfile
login
logmsg
logoff
logon
logout
@@ -385,7 +357,6 @@ makefiles
malloc
maxdatafiles
maxextents
maxfilehandles
maximizable
maxinstances
maxlogfiles
@@ -449,7 +420,6 @@ noclone
nocommon
nocreate
nocycle
nodemostamp
noduplicate
noexcept
nodegroup
@@ -501,12 +471,9 @@ opensymphony
optnone
osgi
outfile
overline
overrider
overriders
pageable
pageheight
pagewidth
param
parameterizable
params
@@ -519,7 +486,6 @@ pctincrease
pctthreshold
pctused
pctversion
pdflib
permalink
petersburg
pipelined
@@ -559,7 +525,6 @@ prepended
prepends
preprocessor
preprocessors
preserveoldpantonenames
println
processlist
profiler
@@ -602,7 +567,6 @@ reimport
reindex
reindexing
renderer
renderingintent
repackager
replacer
repo
@@ -612,9 +576,6 @@ resetlogs
resizable
resize
resizeable
resourcefile
resx
resy
rethrow
rethrowing
rethrown
@@ -644,7 +605,6 @@ serializers
servererror
servlet
servlets
setcolor
severities
sfinae
sftp
@@ -694,7 +654,6 @@ sourcecode
sourceforge
spellchecker
spellchecking
spotcolorlookup
sqlcode
sqlerror
sqlexception
@@ -753,11 +712,6 @@ taglib
teamcity
templatemode
temptable
textformat
textrendering
textrise
textx
texty
thiscall
throwable
thymeleaf
@@ -776,7 +730,6 @@ toolset
toolsets
tooltip
tooltips
topdown
toplink
trebuchet
trie
@@ -797,8 +750,6 @@ uncommented
uncommenting
uncurry
undef
underlineposition
underlinewidth
underwave
undoable
undofile
@@ -815,8 +766,6 @@ uploader
upsource
urlencoded
urowid
usehypertextencoding
usercoordinates
username
utf
util
@@ -835,7 +784,6 @@ varray
vectorcall
verdana
versa
versioning
vertices
viewlet
viewport
@@ -856,7 +804,6 @@ wiki
wildcard
wildcards
wildfly
wordspacing
wordwrap
workflow
writeln