Merge remote-tracking branch 'origin/master'

This commit is contained in:
Sergey Malenkov
2015-01-22 21:09:17 +03:00
17 changed files with 81 additions and 161 deletions
@@ -22,6 +22,8 @@ import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* @author Rustam Vishnyakov
*/
@@ -54,6 +56,14 @@ public abstract class FileIndentOptionsProvider {
return null;
}
/**
* @return The icon to be displayed in a notification message, can be <coe>null</coe> (no icon).
*/
@Nullable
public Icon getIcon() {
return null;
}
/**
* @return <code>True</code> if the provider can be disabled (default is <code>false</code>).
*/
@@ -80,6 +80,9 @@ public class DetectedIndentOptionsNotificationProvider extends EditorNotificatio
final EditorNotificationPanel panel =
new EditorNotificationPanel()
.text(ApplicationBundle.message("code.style.indents.detector.message", provider.getDisplayName()));
if (provider.getIcon() != null) {
panel.icon(provider.getIcon());
}
panel.createActionLabel(
ApplicationBundle.message("code.style.indents.detector.accept"),
new Runnable() {
@@ -195,6 +195,7 @@ public class BalloonImpl implements Balloon, IdeTooltip.Ui {
@Override
public boolean isInside(@NotNull RelativePoint target) {
if (myComp == null) return false;
Component cmp = target.getOriginalComponent();
if (!cmp.isShowing()) return true;
@@ -1,5 +1,6 @@
package org.jetbrains.io;
import com.intellij.util.ArrayUtil;
import com.intellij.util.SmartList;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
@@ -76,7 +77,7 @@ public class JsonUtil {
public static Object[] nextArray(JsonReaderEx reader) {
List<Object> list = nextList(reader);
return list.toArray(new Object[list.size()]);
return ArrayUtil.toObjectArray(list);
}
public static Map<String, Object> nextObject(JsonReaderEx reader) {
@@ -135,7 +135,7 @@ public class JsonRpcServer implements MessageServer {
if (reader.hasNext()) {
List<Object> list = new SmartList<Object>();
JsonUtil.readListBody(reader, list);
parameters = list.toArray(new Object[list.size()]);
parameters = ArrayUtil.toObjectArray(list);
}
else {
parameters = ArrayUtilRt.EMPTY_OBJECT_ARRAY;
@@ -360,7 +360,7 @@ public class JsonRpcServer implements MessageServer {
}
@Override
public T read(@SuppressWarnings("UnnecessaryFullyQualifiedName") com.google.gson.stream.JsonReader in) throws IOException {
public T read(com.google.gson.stream.JsonReader in) throws IOException {
throw new UnsupportedOperationException();
}
}
@@ -14,7 +14,7 @@ public abstract class Promise<T> {
public static final Promise<Void> REJECTED = new RejectedPromise<Void>(createError("rejected"));
@NotNull
public static Throwable createError(@NotNull String error) {
public static RuntimeException createError(@NotNull String error) {
return new MessageError(error);
}
@@ -173,7 +173,8 @@ public abstract class Promise<T> {
});
}
public static class MessageError extends Throwable {
@SuppressWarnings("ExceptionClassNameDoesntEndWithException")
public static class MessageError extends RuntimeException {
public MessageError(@NotNull String error) {
super(error);
}
@@ -110,6 +110,7 @@ public abstract class BreakpointManagerBase<T extends BreakpointBase<?>> impleme
return Promise.all(promises);
}
@NotNull
protected abstract Promise<Void> doClearBreakpoint(@NotNull T breakpoint);
@Override
@@ -25,6 +25,7 @@ public interface Script extends UserDataHolderEx, HasUrl {
@Nullable
SourceMap getSourceMap();
@Override
@NotNull
Url getUrl();
@@ -1,7 +1,5 @@
package org.jetbrains.debugger;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.AsyncResult;
import com.intellij.util.CommonProcessors;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NotNull;
@@ -43,5 +41,5 @@ public interface ScriptManager {
Script findScriptById(@NotNull String id);
@Nullable
ActionCallback getScriptSourceMapLoadCallback(@NotNull Script script);
Promise<Void> getScriptSourceMapPromise(@NotNull Script script);
}
@@ -1,6 +1,5 @@
package org.jetbrains.debugger;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.util.CommonProcessors;
import com.intellij.util.Processor;
import com.intellij.util.Url;
@@ -44,7 +43,7 @@ public abstract class ScriptManagerBase<SCRIPT extends ScriptBase> implements Sc
@Nullable
@Override
public ActionCallback getScriptSourceMapLoadCallback(@NotNull Script script) {
public Promise<Void> getScriptSourceMapPromise(@NotNull Script script) {
return null;
}
@@ -13,7 +13,10 @@ import org.jetbrains.debugger.sourcemap.SourceMap;
import java.util.Map;
public final class NameMapper {
private static final CharMatcher NAME_TRIMMER = CharMatcher.INVISIBLE.or(CharMatcher.anyOf(",()[]{}="));
public static final String S1 = ",()[]{}=";
private static final CharMatcher NAME_TRIMMER = CharMatcher.INVISIBLE.or(CharMatcher.anyOf(S1 + ".&"));
// don't trim trailing .& - could be part of expression
private static final CharMatcher OPERATOR_TRIMMER = CharMatcher.INVISIBLE.or(CharMatcher.anyOf(S1));
private final Document document;
private final Document generatedDocument;
@@ -41,7 +44,7 @@ public final class NameMapper {
MappingEntry sourceEntry = sourceMappings.get(line, offset - document.getLineStartOffset(line));
String sourceEntryName = sourceEntry == null ? null : sourceEntry.getName();
if (sourceEntry != null) {
String generatedName = trimName(getGeneratedName(generatedDocument, sourceMap, sourceEntry));
String generatedName = trimName(getGeneratedName(generatedDocument, sourceMap, sourceEntry), true);
if (!generatedName.isEmpty()) {
String sourceName = sourceEntryName;
if (sourceName == null) {
@@ -60,8 +63,8 @@ public final class NameMapper {
}
@NotNull
public static String trimName(@NotNull CharSequence rawGeneratedName) {
String generatedName = NAME_TRIMMER.trimFrom(rawGeneratedName);
public static String trimName(@NotNull CharSequence rawGeneratedName, boolean isLastToken) {
String generatedName = (isLastToken ? NAME_TRIMMER : OPERATOR_TRIMMER).trimFrom(rawGeneratedName);
// GWT - button_0_g$ = new Button_5_g$('Click me');
// so, we should remove all after "="
int i = generatedName.indexOf('=');
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,28 +34,15 @@ import org.jetbrains.annotations.Nullable;
* @see com.intellij.lang.LanguageStructureViewBuilder#getStructureViewBuilder(com.intellij.psi.PsiFile)
*/
public abstract class TreeBasedStructureViewBuilder implements StructureViewBuilder {
/**
* @deprecated Use createStructureViewModel(Editor editor)
*/
@NotNull
@Deprecated
public StructureViewModel createStructureViewModel() {
throw new AbstractMethodError();
}
/**
* Returns the structure view model defining the data displayed in the structure view
* for a specific file.
*
* todo This method must be abstract, but due to compatibility reasons we wait IDEA 13 release
*
* @return the structure view model instance.
* @see TextEditorBasedStructureViewModel
*/
@NotNull
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
return createStructureViewModel();
}
public abstract StructureViewModel createStructureViewModel(@Nullable Editor editor);
@Override
@NotNull
@@ -15,7 +15,6 @@
*/
package com.intellij.xdebugger.impl.breakpoints;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.components.ComponentSerializationUtil;
@@ -318,6 +317,7 @@ public class XBreakpointBase<Self extends XBreakpoint<P>, P extends XBreakpointP
return Collections.emptyList();
}
@NotNull
public String getDescription() {
@NonNls StringBuilder builder = StringBuilderSpinAllocator.alloc();
try {
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2013 Bas Leijdekkers
* Copyright 2011-2015 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -163,6 +163,9 @@ public class UnnecessaryExplicitNumericCastInspection extends BaseInspection {
return true;
}
if (PsiType.INT.equals(castType)) {
if (PsiType.CHAR.equals(operandType) && TypeUtils.getStringType(polyadicExpression).equals(polyadicExpression.getType())) {
return true;
}
return PsiType.LONG.equals(operandType) || PsiType.FLOAT.equals(operandType) || PsiType.DOUBLE.equals(operandType);
}
if (PsiType.LONG.equals(castType) || PsiType.FLOAT.equals(castType) || PsiType.DOUBLE.equals(castType)) {
@@ -6,32 +6,32 @@ package com.siyeh.igtest.numeric.unnecessary_explicit_numeric_cast;
public class UnnecessaryExplicitNumericCast {
void a(byte b) {
double d = (double) 1;
d = (double) 1.0f;
d = (double) b;
char c = (char) 1;
double d = (<warning descr="'1' unnecessarily cast to 'double'">double</warning>) 1;
d = (<warning descr="'1.0f' unnecessarily cast to 'double'">double</warning>) 1.0f;
d = (<warning descr="'b' unnecessarily cast to 'double'">double</warning>) b;
char c = (<warning descr="'1' unnecessarily cast to 'char'">char</warning>) 1;
b = (int)7;
}
double b(int a, byte b) {
return (double)a * (double) b;
return (<warning descr="'a' unnecessarily cast to 'double'">double</warning>)a * (<warning descr="'b' unnecessarily cast to 'double'">double</warning>) b;
}
public static void main(String[] args) {
int i = 10;
double d = 123.0 / (456.0 * (double) i);
double d = 123.0 / (456.0 * (<warning descr="'i' unnecessarily cast to 'double'">double</warning>) i);
}
void unary() {
byte b = 2;
int a[] = new int[(int)b];
final int c = a[((int) b)];
int[] a2 = new int[]{(int)b};
int[] a3 = {(int)b};
final int result = (int) b << 1;
c((int)b);
new UnnecessaryExplicitNumericCast((long)b);
int a[] = new int[(<warning descr="'b' unnecessarily cast to 'int'">int</warning>)b];
final int c = a[((<warning descr="'b' unnecessarily cast to 'int'">int</warning>) b)];
int[] a2 = new int[]{(<warning descr="'b' unnecessarily cast to 'int'">int</warning>)b};
int[] a3 = {(<warning descr="'b' unnecessarily cast to 'int'">int</warning>)b};
final int result = (<warning descr="'b' unnecessarily cast to 'int'">int</warning>) b << 1;
c((<warning descr="'b' unnecessarily cast to 'int'">int</warning>)b);
new UnnecessaryExplicitNumericCast((<warning descr="'b' unnecessarily cast to 'long'">long</warning>)b);
}
void c(int i) {}
@@ -43,7 +43,7 @@ public class UnnecessaryExplicitNumericCast {
void source() {
target((int)'a');
target2((int)'b');
target2((<warning descr="''b'' unnecessarily cast to 'int'">int</warning>)'b');
}
void target(int c) {}
void target(char c) {}
@@ -56,7 +56,7 @@ public class UnnecessaryExplicitNumericCast {
void a(float angleFromTo) {
float f = (float) Math.cos(0.5) * 1.0f; // necessary
final long l = (long) i() * 9L;
final long l = (<warning descr="'i()' unnecessarily cast to 'long'">long</warning>) i() * 9L;
float angle2 = angleFromTo + (float) (Math.PI / 2);
}
@@ -67,4 +67,19 @@ public class UnnecessaryExplicitNumericCast {
boolean redundantTypeCast(long l) {
return 0L == (long)l;
}
void necessary() {
char[] keyChar = {'\t', '\n', '\r', '\f', 'a', '0'};
for (char cc : keyChar) {
String result;
if (cc < 28) {
result = "Ascii " + (int)cc;
}
else {
result = "k " + cc + " (" + (int)cc + ')';
}
System.out.println(result);
}
}
}
@@ -1,110 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>9</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'1' unnecessarily cast to &lt;code&gt;double&lt;/code&gt;</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>10</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'1.0f' unnecessarily cast to &lt;code&gt;double&lt;/code&gt;</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>11</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'b' unnecessarily cast to &lt;code&gt;double&lt;/code&gt;</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>12</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'1' unnecessarily cast to &lt;code&gt;char&lt;/code&gt;</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>17</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'a' unnecessarily cast to &lt;code&gt;double&lt;/code&gt;</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>17</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'b' unnecessarily cast to &lt;code&gt;double&lt;/code&gt;</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>23</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'i' unnecessarily cast to &lt;code&gt;double&lt;/code&gt;</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>28</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'b' unnecessarily cast to &lt;code&gt;int&lt;/code&gt;</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>29</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'b' unnecessarily cast to &lt;code&gt;int&lt;/code&gt;</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>30</line> <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'b' unnecessarily cast to &lt;code&gt;int&lt;/code&gt;</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>31</line> <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'b' unnecessarily cast to &lt;code&gt;int&lt;/code&gt;</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>32</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'b' unnecessarily cast to &lt;code&gt;int&lt;/code&gt;</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>33</line> <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'b' unnecessarily cast to &lt;code&gt;int&lt;/code&gt;</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>34</line> <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'b' unnecessarily cast to &lt;code&gt;long&lt;/code&gt;</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>46</line>
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>''b'' unnecessarily cast to &lt;code&gt;int&lt;/code&gt; #loc</description>
</problem>
<problem>
<file>UnnecessaryExplicitNumericCast.java</file>
<line>59</line>
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unnecessary explicit numeric cast</problem_class>
<description>'i()' unnecessarily cast to &lt;code&gt;long&lt;/code&gt; #loc</description>
</problem>
</problems>
@@ -1,11 +1,18 @@
package com.siyeh.ig.numeric;
import com.siyeh.ig.IGInspectionTestCase;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.siyeh.ig.LightInspectionTestCase;
import org.jetbrains.annotations.Nullable;
public class UnnecessaryExplicitNumericCastInspectionTest extends IGInspectionTestCase {
public class UnnecessaryExplicitNumericCastInspectionTest extends LightInspectionTestCase {
public void test() throws Exception {
doTest("com/siyeh/igtest/numeric/unnecessary_explicit_numeric_cast",
new UnnecessaryExplicitNumericCastInspection());
public void testUnnecessaryExplicitNumericCast() throws Exception {
doTest();
}
@Nullable
@Override
protected InspectionProfileEntry getInspection() {
return new UnnecessaryExplicitNumericCastInspection();
}
}