Merge remote-tracking branch 'origin/master'

This commit is contained in:
Vladimir.Orlov
2015-02-02 14:46:31 +03:00
8 changed files with 111 additions and 4 deletions
@@ -216,7 +216,7 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
) {
DfaValue arrayVar = myFactory.createValue(((PsiArrayAccessExpression)lExpr).getArrayExpression());
if (arrayVar instanceof DfaVariableValue) {
addInstruction(new FlushVariableInstruction((DfaVariableValue)arrayVar));
addInstruction(new FlushVariableInstruction((DfaVariableValue)arrayVar, true));
}
}
}
@@ -690,6 +690,21 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
finishElement(switchStmt);
}
@Override
public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) {
startElement(expression);
PsiExpression qualifier = expression.getQualifierExpression();
if (qualifier != null) {
qualifier.accept(this);
addInstruction(new FieldReferenceInstruction(qualifier, "Method reference qualifier"));
}
addInstruction(new PushInstruction(myFactory.createTypeValue(expression.getFunctionalInterfaceType(), Nullness.NOT_NULL), expression));
finishElement(expression);
}
@Override public void visitSynchronizedStatement(PsiSynchronizedStatement statement) {
startElement(statement);
@@ -123,7 +123,14 @@ public abstract class InstructionVisitor {
public DfaInstructionState[] visitFlushVariable(FlushVariableInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
final DfaVariableValue variable = instruction.getVariable();
if (variable != null) {
memState.flushVariable(variable);
if (instruction.isDependentsOnly()) {
for (DfaVariableValue qualified : runner.getFactory().getVarFactory().getAllQualifiedBy(variable)) {
memState.flushVariable(qualified);
}
}
else {
memState.flushVariable(variable);
}
} else {
memState.flushFields();
}
@@ -29,9 +29,19 @@ import com.intellij.codeInspection.dataFlow.value.DfaVariableValue;
public class FlushVariableInstruction extends Instruction {
private final DfaVariableValue myVariable;
private final boolean myDependentsOnly;
public FlushVariableInstruction(DfaVariableValue expr) {
myVariable = expr;
this(expr, false);
}
public FlushVariableInstruction(DfaVariableValue variable, boolean dependentsOnly) {
myVariable = variable;
myDependentsOnly = dependentsOnly;
}
public boolean isDependentsOnly() {
return myDependentsOnly;
}
public DfaVariableValue getVariable() {
@@ -0,0 +1,18 @@
import org.jetbrains.annotations.Nullable;
class BrokenAlignment {
{
Runnable t = <warning descr="Dereference of 'getString()' may produce 'java.lang.NullPointerException'">getString()</warning>::length;
Runnable t2 = BrokenAlignment::getStringStatic;
}
@Nullable
private String getString() {
return null;
}
@Nullable
private static String getStringStatic() {
return null;
}
}
@@ -0,0 +1,53 @@
import org.jetbrains.annotations.*;
class Test {
@NotNull
public static int[] add(@Nullable final int[] ints, final int from, final int to) {
if (ints == null || ints.length == 0)
return new int[]{from, to};
for (int i = 0, j = 1; j < ints.length; i+=2, j+=2) {
final int intStart = ints[i];
final int intFinish = ints[j];
//check contained
if (intStart <= from && to <= intFinish)
return ints;
//try expand 'to' bound
if (intStart <= from && from <= intFinish) {
ints[j] = to;
return ints;
}
//try expand 'from' bound
if (intStart <= to && to <= intFinish) {
ints[i] = from;
return ints;
}
//if we add an interval that contains ors interval
//may produce duplicates
if (from <= intStart && intFinish <= to) {
ints[i] = from;
ints[j] = to;
return ints;
}
if (from == intFinish + 1) {
ints[j] = to;
return ints;
}
if (to == intStart - 1) {
ints[i] = from;
return ints;
}
}
//TODO: insert interval sorted?
final int[] newInts = new int[ints.length + 2];
System.arraycopy(ints, 0, newInts, 0, ints.length);
newInts[ints.length] = from;
newInts[ints.length+1] = to;
return newInts;
}}
@@ -76,6 +76,8 @@ public class DataFlowInspection8Test extends LightCodeInsightFixtureTestCase {
});
}
public void testMethodReferenceOnNullable() { doTest(); }
public void testNullableForeachVariable() {
setupCustomAnnotations();
doTest();
@@ -282,6 +282,8 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
public void testNumberComparisonsWhenValueIsKnown() { doTest(); }
public void testFloatComparisons() { doTest(); }
public void testNullableArray() { doTest(); }
public void testAccessingSameArrayElements() { doTest(); }
public void testParametersAreNonnullByDefault() {
@@ -757,7 +757,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
}
private boolean isTheAmountOfTextTooBig(final int textLength) {
return textLength > myBuffer.getCyclicBufferSize() / consoleTooMuchTextBufferRatio;
return myBuffer.isUseCyclicBuffer() && textLength > myBuffer.getCyclicBufferSize() / consoleTooMuchTextBufferRatio;
}
private void clearHyperlinkAndFoldings() {