(no message)

This commit is contained in:
Alexey Kudravtsev
2005-02-17 13:02:03 +03:00
parent 41f86e06a4
commit 52af7c4e05
2 changed files with 41 additions and 30 deletions
@@ -105,34 +105,40 @@ public class SimplifyBooleanExpressionFix implements IntentionAction {
final Boolean rConstBoolean = getConstBoolean(rOperand);
if (lConstBoolean != null) {
if (JavaTokenType.ANDAND == tokenType || JavaTokenType.AND == tokenType) {
resultExpression = lConstBoolean.booleanValue() ? rOperand : falseExpression;
}
else if (JavaTokenType.OROR == tokenType || JavaTokenType.OR == tokenType) {
resultExpression = lConstBoolean.booleanValue() ? trueExpression : rOperand;
}
else if (JavaTokenType.EQEQ == tokenType) {
simplifyEquation(lConstBoolean, rOperand);
}
else if (JavaTokenType.NE == tokenType) {
resultExpression = createNegatedExpression(rOperand);
visitPrefixExpression((PsiPrefixExpression)resultExpression);
simplifyEquation(lConstBoolean, resultExpression);
}
simplifyBinary(tokenType, lConstBoolean, rOperand);
}
else if (rConstBoolean != null) {
if (JavaTokenType.ANDAND == tokenType || JavaTokenType.AND == tokenType) {
resultExpression = rConstBoolean.booleanValue() ? lOperand : falseExpression;
}
else if (JavaTokenType.OROR == tokenType || JavaTokenType.OR == tokenType) {
resultExpression = rConstBoolean.booleanValue() ? trueExpression : lOperand;
}
else if (JavaTokenType.EQEQ == tokenType) {
simplifyEquation(rConstBoolean, lOperand);
}
else if (JavaTokenType.NE == tokenType) {
simplifyEquation(rConstBoolean, createNegatedExpression(lOperand));
}
simplifyBinary(tokenType, rConstBoolean, lOperand);
//if (JavaTokenType.ANDAND == tokenType || JavaTokenType.AND == tokenType) {
// resultExpression = rConstBoolean.booleanValue() ? lOperand : falseExpression;
//}
//else if (JavaTokenType.OROR == tokenType || JavaTokenType.OR == tokenType) {
// resultExpression = rConstBoolean.booleanValue() ? trueExpression : lOperand;
//}
//else if (JavaTokenType.EQEQ == tokenType) {
// simplifyEquation(rConstBoolean, lOperand);
//}
//else if (JavaTokenType.NE == tokenType) {
// simplifyEquation(rConstBoolean, createNegatedExpression(lOperand));
//}
}
}
private void simplifyBinary(final IElementType tokenType, final Boolean lConstBoolean, final PsiExpression rOperand) {
if (JavaTokenType.ANDAND == tokenType || JavaTokenType.AND == tokenType) {
resultExpression = lConstBoolean.booleanValue() ? rOperand : falseExpression;
}
else if (JavaTokenType.OROR == tokenType || JavaTokenType.OR == tokenType) {
resultExpression = lConstBoolean.booleanValue() ? trueExpression : rOperand;
}
else if (JavaTokenType.EQEQ == tokenType) {
simplifyEquation(lConstBoolean, rOperand);
}
else if (JavaTokenType.NE == tokenType) {
final PsiPrefixExpression negatedExpression = createNegatedExpression(rOperand);
resultExpression = negatedExpression;
visitPrefixExpression(negatedExpression);
simplifyEquation(lConstBoolean, resultExpression);
}
}
@@ -147,6 +153,12 @@ public class SimplifyBooleanExpressionFix implements IntentionAction {
}
}
public void visitConditionalExpression(PsiConditionalExpression expression) {
final Boolean condition = getConstBoolean(expression.getCondition());
if (condition == null) return;
resultExpression = condition.booleanValue() ? expression.getThenExpression() : expression.getElseExpression();
}
private PsiPrefixExpression createNegatedExpression(final PsiExpression otherOperand) {
try {
return (PsiPrefixExpression)otherOperand.getManager().getElementFactory()
@@ -338,8 +338,6 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark
int yStartPosition = visibleLineToYPosition(visStartLine, myScrollBarHeight);
int yEndPosition = visibleLineToYPosition(visEndLine, myScrollBarHeight);
//final int height = Math.max(yEndPosition - yStartPosition, 2);
final ErrorMarkPile prevPile = list.size() == 0 ? null : list.get(list.size() - 1);
int prevPileEnd = prevPile == null ? -100 : prevPile.yEnd;
if (yStartPosition - prevPileEnd < getMinHeight()) {
@@ -376,15 +374,16 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark
}
}
private int getMinHeight() {
private static int getMinHeight() {
return DaemonCodeAnalyzerSettings.getInstance().getErrorStripeMarkMinHeight();
}
// number of error marks glued together
private class ErrorMarkPile {
private int yStart;
private int yEnd;
private List<RangeHighlighter> markers = new ArrayList<RangeHighlighter>();
private static final int MAX_TOOLTIP_LINES = 5;
private static final int MAX_TOOLTIP_LINES = 10;
public ErrorMarkPile(final int yStart) {
this.yStart = yStart;