diff --git a/.idea/inspectionProfiles/idea_default_no_spellchecker.xml b/.idea/inspectionProfiles/idea_default_no_spellchecker.xml index cbc6d13974c1..f22b5d38c38c 100644 --- a/.idea/inspectionProfiles/idea_default_no_spellchecker.xml +++ b/.idea/inspectionProfiles/idea_default_no_spellchecker.xml @@ -2,9 +2,15 @@ \ No newline at end of file diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java index 97ff076d4ee5..c0d6cd662bc3 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java @@ -318,6 +318,33 @@ public class EvaluatorBuilderImpl implements EvaluatorBuilder { myResult = createBinaryEvaluator(lResult, lOperand.getType(), rResult, rOperand.getType(), opType, expressionExpectedType); } + @Override + public void visitPolyadicExpression(PsiPolyadicExpression wideExpression) { + if (LOG.isDebugEnabled()) { + LOG.debug("visitPolyadicExpression " + wideExpression); + } + PsiExpression[] operands = wideExpression.getOperands(); + operands[0].accept(this); + Evaluator result = myResult; + PsiType lType = operands[0].getType(); + for (int i = 1; i < operands.length; i++) { + PsiExpression expression = operands[i]; + if (expression == null) { + throwEvaluateException(DebuggerBundle.message("evaluation.error.invalid.expression", wideExpression.getText())); + return; + } + expression.accept(this); + Evaluator rResult = myResult; + IElementType opType = wideExpression.getOperationTokenType(); + PsiType expressionExpectedType = expression.getType(); + if (expressionExpectedType == null) { + throwEvaluateException(DebuggerBundle.message("evaluation.error.unknown.expression.type", expression.getText())); + } + myResult = createBinaryEvaluator(result, lType, rResult, expression.getType(), opType, expressionExpectedType); + lType = TypeConversionUtil.calcTypeForBinaryExpression(lType, expressionExpectedType, opType, true); + result = myResult; + } + } // constructs binary evaluator handling unboxing and numeric promotion issues private static BinaryExpressionEvaluator createBinaryEvaluator( @@ -774,7 +801,7 @@ public class EvaluatorBuilderImpl implements EvaluatorBuilder { final Evaluator operandEvaluator = myResult; - final IElementType operation = expression.getOperationSign().getTokenType(); + final IElementType operation = expression.getOperationTokenType(); final PsiType operandType = operandExpression.getType(); @Nullable final PsiType unboxedOperandType = PsiPrimitiveType.getUnboxedType(operandType); @@ -810,7 +837,7 @@ public class EvaluatorBuilderImpl implements EvaluatorBuilder { @Nullable final PsiType unboxedOperandType = PsiPrimitiveType.getUnboxedType(operandType); - final IElementType operation = expression.getOperationSign().getTokenType(); + final IElementType operation = expression.getOperationTokenType(); if(operation == JavaTokenType.PLUSPLUS || operation == JavaTokenType.MINUSMINUS) { try { diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java index 047ca94375a5..e8d4facbe81b 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerManagerImpl.java @@ -15,10 +15,7 @@ */ package com.intellij.debugger.impl; -import com.intellij.debugger.DebuggerBundle; -import com.intellij.debugger.DebuggerManagerEx; -import com.intellij.debugger.NameMapper; -import com.intellij.debugger.PositionManager; +import com.intellij.debugger.*; import com.intellij.debugger.apiAdapters.TransportServiceWrapper; import com.intellij.debugger.engine.*; import com.intellij.debugger.settings.DebuggerSettings; @@ -41,6 +38,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.colors.EditorColorsListener; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; +import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.JavaSdk; import com.intellij.openapi.projectRoots.JavaSdkVersion; @@ -198,6 +196,12 @@ public class DebuggerManagerImpl extends DebuggerManagerEx { process.appendPositionManager(positionManager); } } + for(PositionManagerFactory factory: Extensions.getExtensions(PositionManagerFactory.EP_NAME, myProject)) { + final PositionManager manager = factory.create(debugProcess); + if (manager != null) { + process.appendPositionManager(manager); + } + } } public void processDetached(final DebugProcess process, final boolean closedByUser) { debugProcess.removeDebugProcessListener(this); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/DebuggerTreeBase.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/DebuggerTreeBase.java index c5f730109d16..7e81ee69ff54 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/DebuggerTreeBase.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/DebuggerTreeBase.java @@ -121,13 +121,16 @@ public class DebuggerTreeBase extends DnDAwareTree implements Disposable { } if (tipText.length() > 0) { - final StringTokenizer tokenizer = new StringTokenizer(tipText, "\n", true); + final StringTokenizer tokenizer = new StringTokenizer(tipText, "\n ", true); while (tokenizer.hasMoreElements()) { final String each = tokenizer.nextElement(); if ("\n".equals(each)) { tipBuilder.append("
"); } + else if (" ".equals(each)) { + tipBuilder.append("  "); + } else { tipBuilder.append(JDOMUtil.legalizeText(each)); } diff --git a/java/debugger/openapi/src/com/intellij/debugger/DebuggerManager.java b/java/debugger/openapi/src/com/intellij/debugger/DebuggerManager.java index c0f0bfede608..26b02c8e970f 100644 --- a/java/debugger/openapi/src/com/intellij/debugger/DebuggerManager.java +++ b/java/debugger/openapi/src/com/intellij/debugger/DebuggerManager.java @@ -46,6 +46,9 @@ public abstract class DebuggerManager implements ProjectComponent, JDOMExternali public abstract String getVMClassQualifiedName(PsiClass aClass); + /** + * @deprecated use PositionManagerFactory extension point instead + */ public abstract void registerPositionManagerFactory(Function factory); public abstract void unregisterPositionManagerFactory(Function factory); diff --git a/java/debugger/openapi/src/com/intellij/debugger/PositionManagerFactory.java b/java/debugger/openapi/src/com/intellij/debugger/PositionManagerFactory.java new file mode 100644 index 000000000000..12d01c08ed36 --- /dev/null +++ b/java/debugger/openapi/src/com/intellij/debugger/PositionManagerFactory.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2011 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.debugger; + +import com.intellij.debugger.engine.DebugProcess; +import com.intellij.openapi.extensions.ExtensionPointName; +import org.jetbrains.annotations.Nullable; + +/** + * @author yole + */ +public interface PositionManagerFactory { + ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.debugger.positionManagerFactory"); + + @Nullable + PositionManager create(DebugProcess process); +} diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java index 9e60a0c2dfa5..5c234c2ec104 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java @@ -417,7 +417,7 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel { downButton.setShortcut(KeyboardShortcut.fromString("alt DOWN")); myEntryTable.setBorder(new LineBorder(UIUtil.getBorderColor())); - final TableToolbarDecorator decorator = TableToolbarDecorator.createDecorator(myEntryTable); + final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myEntryTable); decorator .addExtraAction(addButton) .addExtraAction(removeButton) diff --git a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java index 3f818584c3d4..d4d8ae50edad 100644 --- a/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/ExpectedTypesProvider.java @@ -476,7 +476,7 @@ public class ExpectedTypesProvider { type = ((PsiAnonymousClass)resolved).getBaseClassType(); } } - final int kind = assignment.getOperationSign().getTokenType() != JavaTokenType.EQ + final int kind = assignment.getOperationTokenType() != JavaTokenType.EQ ? ExpectedTypeInfo.TYPE_STRICTLY : ExpectedTypeInfo.TYPE_OR_SUPERTYPE; ExpectedTypeInfoImpl info = createInfoImpl(type, kind, type, TailType.NONE); @@ -567,7 +567,6 @@ public class ExpectedTypesProvider { PsiExpression op1 = expr.getLOperand(); PsiExpression op2 = expr.getROperand(); - PsiJavaToken sign = expr.getOperationSign(); if (myForCompletion && op1.equals(myExpr)) { final MyParentVisitor visitor = new MyParentVisitor(expr, myForCompletion, myClassProvider, myVoidable, myUsedAfter); myExpr = (PsiExpression)myExpr.getParent(); @@ -583,7 +582,7 @@ public class ExpectedTypesProvider { PsiExpression anotherExpr = op1.equals(myExpr) ? op2 : op1; PsiType anotherType = anotherExpr != null ? anotherExpr.getType() : null; PsiElementFactory factory = JavaPsiFacade.getInstance(expr.getProject()).getElementFactory(); - IElementType i = sign.getTokenType(); + IElementType i = expr.getOperationTokenType(); if (i == JavaTokenType.MINUS || i == JavaTokenType.ASTERISK || i == JavaTokenType.DIV || @@ -689,8 +688,7 @@ public class ExpectedTypesProvider { } @Override public void visitPrefixExpression(PsiPrefixExpression expr) { - PsiJavaToken sign = expr.getOperationSign(); - IElementType i = sign.getTokenType(); + IElementType i = expr.getOperationTokenType(); final PsiType type = expr.getType(); final TailType tailType = expr.getParent() instanceof PsiAssignmentExpression && ((PsiAssignmentExpression) expr.getParent()).getRExpression() == expr ? getAssignmentRValueTailType((PsiAssignmentExpression) expr.getParent()) : diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 691dd3d4c1d2..00339413c87f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -1,3 +1,4 @@ + /* * Copyright 2000-2011 JetBrains s.r.o. * @@ -1088,15 +1089,24 @@ public class HighlightUtil { } @Nullable - static HighlightInfo checkBinaryOperatorApplicable(PsiBinaryExpression expression) { - PsiExpression lOperand = expression.getLOperand(); - PsiExpression rOperand = expression.getROperand(); - PsiJavaToken operationSign = expression.getOperationSign(); - if (!TypeConversionUtil.isBinaryOperatorApplicable(operationSign.getTokenType(), lOperand, rOperand, false)) { - String message = JavaErrorMessages - .message("binary.operator.not.applicable", operationSign.getText(), formatType(lOperand.getType()), formatType(rOperand.getType())); - return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, expression, message); + static HighlightInfo checkPolyadicOperatorApplicable(PsiPolyadicExpression expression) { + PsiExpression[] operands = expression.getOperands(); + + PsiType lType = operands[0].getType(); + IElementType operationSign = expression.getOperationTokenType(); + for (int i = 1; i < operands.length; i++) { + PsiExpression operand = operands[i]; + PsiType rType = operand.getType(); + if (!TypeConversionUtil.isBinaryOperatorApplicable(operationSign, lType, rType, false)) { + PsiJavaToken token = expression.getTokenBeforeOperand(operand); + String message = JavaErrorMessages.message("binary.operator.not.applicable", token.getText(), + formatType(lType), + formatType(rType)); + return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, expression, message); + } + lType = TypeConversionUtil.calcTypeForBinaryExpression(lType, rType, operationSign, true); } + return null; } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java index 555f9f518ff4..590814e2f9c3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java @@ -231,9 +231,10 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh if (!myHolder.hasErrorResults()) visitExpression(assignment); } - @Override public void visitBinaryExpression(PsiBinaryExpression expression) { - super.visitBinaryExpression(expression); - if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkBinaryOperatorApplicable(expression)); + @Override + public void visitPolyadicExpression(PsiPolyadicExpression expression) { + super.visitPolyadicExpression(expression); + if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkPolyadicOperatorApplicable(expression)); } @Override public void visitBreakStatement(PsiBreakStatement statement) { diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SimplifyBooleanExpressionFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SimplifyBooleanExpressionFix.java index 3d27c56a8dd6..a6de2c4f2a98 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SimplifyBooleanExpressionFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/SimplifyBooleanExpressionFix.java @@ -121,14 +121,14 @@ public class SimplifyBooleanExpressionFix implements IntentionAction { final PsiElement[] children = codeBlock.getChildren(); - if(children.length > 2){ - final PsiElement added = - parent.addRangeBefore( - children[1], - children[children.length - 2], - orig); - final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(orig.getManager()); - codeStyleManager.reformat(added); + if (children.length > 2) { + final PsiElement added = + parent.addRangeBefore( + children[1], + children[children.length - 2], + orig); + final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(orig.getManager()); + codeStyleManager.reformat(added); } orig.delete(); } @@ -142,7 +142,8 @@ public class SimplifyBooleanExpressionFix implements IntentionAction { final ExpressionVisitor expressionVisitor = new ExpressionVisitor(expression.getManager(), true); final IncorrectOperationException[] exception = {null}; result[0].accept(new JavaRecursiveElementVisitor() { - @Override public void visitElement(PsiElement element) { + @Override + public void visitElement(PsiElement element) { // read in all children in advance since due to Igorek's exercises element replace involves its siblings invalidation PsiElement[] children = element.getChildren(); for (PsiElement child : children) { @@ -150,7 +151,8 @@ public class SimplifyBooleanExpressionFix implements IntentionAction { } } - @Override public void visitExpression(PsiExpression expression) { + @Override + public void visitExpression(PsiExpression expression) { super.visitExpression(expression); expressionVisitor.clear(); expression.accept(expressionVisitor); @@ -176,19 +178,22 @@ public class SimplifyBooleanExpressionFix implements IntentionAction { PsiExpression newExpression = (PsiExpression)expression.replace(result[0]); simplifyIfStatement(newExpression); } + public static boolean canBeSimplified(@NotNull PsiExpression expression) { if (!(expression instanceof PsiConditionalExpression) && expression.getType() != PsiType.BOOLEAN) return false; final ExpressionVisitor expressionVisitor = new ExpressionVisitor(expression.getManager(), false); final Ref canBeSimplified = new Ref(Boolean.FALSE); expression.accept(new JavaRecursiveElementWalkingVisitor() { - @Override public void visitElement(PsiElement element) { + @Override + public void visitElement(PsiElement element) { if (!canBeSimplified.get().booleanValue()) { super.visitElement(element); } } - @Override public void visitExpression(PsiExpression expression) { + @Override + public void visitExpression(PsiExpression expression) { super.visitExpression(expression); expressionVisitor.clear(); expression.accept(expressionVisitor); @@ -228,19 +233,27 @@ public class SimplifyBooleanExpressionFix implements IntentionAction { return isCreateResult; } - @Override public void visitBinaryExpression(PsiBinaryExpression expression) { - PsiExpression lOperand = expression.getLOperand(); - PsiExpression rOperand = expression.getROperand(); - PsiJavaToken operationSign = expression.getOperationSign(); - IElementType tokenType = operationSign.getTokenType(); - Boolean lConstBoolean = getConstBoolean(lOperand); - Boolean rConstBoolean = getConstBoolean(rOperand); - - if (lConstBoolean != null) { - simplifyBinary(tokenType, lConstBoolean, rOperand); - } - else if (rConstBoolean != null) { - simplifyBinary(tokenType, rConstBoolean, lOperand); + @Override + public void visitPolyadicExpression(PsiPolyadicExpression expression) { + PsiExpression[] operands = expression.getOperands(); + PsiExpression lExpr = operands[0]; + IElementType tokenType = expression.getOperationTokenType(); + for (int i = 1; i < operands.length; i++) { + Boolean l = getConstBoolean(lExpr); + PsiExpression operand = operands[i]; + Boolean r = getConstBoolean(operand); + if (l != null) { + simplifyBinary(tokenType, l, operand); + } + else if (r != null) { + simplifyBinary(tokenType, r, lExpr); + } + else { + resultExpression = null; + } + if (resultExpression != null) { + lExpr = resultExpression; + } } } @@ -276,7 +289,8 @@ public class SimplifyBooleanExpressionFix implements IntentionAction { } } - @Override public void visitConditionalExpression(PsiConditionalExpression expression) { + @Override + public void visitConditionalExpression(PsiConditionalExpression expression) { Boolean condition = getConstBoolean(expression.getCondition()); if (condition == null) return; if (!markAndCheckCreateResult()) { @@ -285,7 +299,7 @@ public class SimplifyBooleanExpressionFix implements IntentionAction { resultExpression = condition.booleanValue() ? expression.getThenExpression() : expression.getElseExpression(); } - private static PsiPrefixExpression createNegatedExpression(PsiExpression otherOperand) { + private static PsiPrefixExpression createNegatedExpression(PsiExpression otherOperand) { PsiPrefixExpression expression = (PsiPrefixExpression)createExpression(otherOperand.getManager(), "!(xxx)"); try { expression.getOperand().replace(otherOperand); @@ -296,12 +310,12 @@ public class SimplifyBooleanExpressionFix implements IntentionAction { return expression; } - @Override public void visitPrefixExpression(PsiPrefixExpression expression) { + @Override + public void visitPrefixExpression(PsiPrefixExpression expression) { PsiExpression operand = expression.getOperand(); Boolean constBoolean = getConstBoolean(operand); if (constBoolean == null) return; - PsiJavaToken operationSign = expression.getOperationSign(); - IElementType tokenType = operationSign.getTokenType(); + IElementType tokenType = expression.getOperationTokenType(); if (JavaTokenType.EXCL == tokenType) { if (!markAndCheckCreateResult()) { return; @@ -311,7 +325,8 @@ public class SimplifyBooleanExpressionFix implements IntentionAction { } - @Override public void visitParenthesizedExpression(PsiParenthesizedExpression expression) { + @Override + public void visitParenthesizedExpression(PsiParenthesizedExpression expression) { PsiExpression subexpr = expression.getExpression(); Boolean constBoolean = getConstBoolean(subexpr); if (constBoolean == null) return; @@ -321,7 +336,8 @@ public class SimplifyBooleanExpressionFix implements IntentionAction { resultExpression = constBoolean.booleanValue() ? trueExpression : falseExpression; } - @Override public void visitReferenceExpression(PsiReferenceExpression expression) { + @Override + public void visitReferenceExpression(PsiReferenceExpression expression) { visitReferenceElement(expression); } @@ -341,4 +357,4 @@ public class SimplifyBooleanExpressionFix implements IntentionAction { public boolean startInWriteAction() { return true; } -} \ No newline at end of file +} diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/JavaSmartEnterProcessor.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/JavaSmartEnterProcessor.java index 57a79162cb4e..b94541a2c94b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/JavaSmartEnterProcessor.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/JavaSmartEnterProcessor.java @@ -86,6 +86,7 @@ public class JavaSmartEnterProcessor extends SmartEnterProcessor { } private int myFirstErrorOffset = Integer.MAX_VALUE; + private boolean mySkipEnter; private static final int MAX_ATTEMPTS = 20; private static final Key SMART_ENTER_TIMESTAMP = Key.create("smartEnterOriginalTimestamp"); @@ -99,6 +100,7 @@ public class JavaSmartEnterProcessor extends SmartEnterProcessor { try { editor.putUserData(SMART_ENTER_TIMESTAMP, editor.getDocument().getModificationStamp()); myFirstErrorOffset = Integer.MAX_VALUE; + mySkipEnter = false; process(project, editor, psiFile, 0); } catch (TooManyAttemptsException e) { @@ -191,6 +193,10 @@ public class JavaSmartEnterProcessor extends SmartEnterProcessor { reformat(atCaret); commit(editor); + if (mySkipEnter) { + return; + } + atCaret = CodeInsightUtil.findElementInRange(psiFile, rangeMarker.getStartOffset(), rangeMarker.getEndOffset(), atCaret.getClass()); for (EnterProcessor processor : ourEnterProcessors) { if(atCaret == null){ @@ -292,6 +298,10 @@ public class JavaSmartEnterProcessor extends SmartEnterProcessor { } } + public void setSkipEnter(boolean skipEnter) { + mySkipEnter = skipEnter; + } + protected static void plainEnter(@NotNull final Editor editor) { getEnterHandler().execute(editor, ((EditorEx) editor).getDataContext()); } diff --git a/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/MissingReturnExpressionFixer.java b/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/MissingReturnExpressionFixer.java index df86f53a19c0..8b1815410175 100644 --- a/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/MissingReturnExpressionFixer.java +++ b/java/java-impl/src/com/intellij/codeInsight/editorActions/smartEnter/MissingReturnExpressionFixer.java @@ -19,6 +19,8 @@ import com.intellij.openapi.editor.Editor; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Created by IntelliJ IDEA. @@ -29,31 +31,83 @@ import com.intellij.util.IncorrectOperationException; */ @SuppressWarnings({"HardCodedStringLiteral"}) public class MissingReturnExpressionFixer implements Fixer { - public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) - throws IncorrectOperationException { - if (psiElement instanceof PsiReturnStatement) { - PsiReturnStatement retStatement = (PsiReturnStatement) psiElement; - PsiExpression returnValue = retStatement.getReturnValue(); - if (returnValue != null && - lineNumber(editor, editor.getCaretModel().getOffset()) == lineNumber(editor, returnValue.getTextRange().getStartOffset())) { - return; - } + public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException { + if (!(psiElement instanceof PsiReturnStatement)) { + return; + } + if (!PsiTreeUtil.hasErrorElements(psiElement)) { + return; + } + + PsiReturnStatement retStatement = (PsiReturnStatement)psiElement; + if (fixMethodCallWithoutTrailingSemicolon(retStatement, editor, processor)) { + return; + } - PsiElement parent = PsiTreeUtil.getParentOfType(psiElement, PsiClassInitializer.class, PsiMethod.class); - if (parent instanceof PsiMethod) { - final PsiType returnType = ((PsiMethod) parent).getReturnType(); - if (returnType != null && returnType != PsiType.VOID) { - final int startOffset = retStatement.getTextRange().getStartOffset(); - if (returnValue != null) { - editor.getDocument().insertString(startOffset + "return".length(), ";"); - } + PsiExpression returnValue = retStatement.getReturnValue(); + if (returnValue != null + && lineNumber(editor, editor.getCaretModel().getOffset()) == lineNumber(editor, returnValue.getTextRange().getStartOffset())) + { + return; + } - processor.registerUnresolvedError(startOffset + "return".length()); + PsiElement parent = PsiTreeUtil.getParentOfType(psiElement, PsiClassInitializer.class, PsiMethod.class); + if (parent instanceof PsiMethod) { + final PsiType returnType = ((PsiMethod)parent).getReturnType(); + if (returnType != null && returnType != PsiType.VOID) { + final int startOffset = retStatement.getTextRange().getStartOffset(); + if (returnValue != null) { + editor.getDocument().insertString(startOffset + "return".length(), ";"); } + + processor.registerUnresolvedError(startOffset + "return".length()); } } } + private static boolean fixMethodCallWithoutTrailingSemicolon(@Nullable PsiReturnStatement returnStatement, @NotNull Editor editor, + @NotNull JavaSmartEnterProcessor processor) + { + if (returnStatement == null) { + return false; + } + final PsiElement lastChild = returnStatement.getLastChild(); + if (!(lastChild instanceof PsiErrorElement)) { + return false; + } + PsiElement prev = lastChild.getPrevSibling(); + if (prev instanceof PsiWhiteSpace) { + prev = prev.getPrevSibling(); + } + + if (!(prev instanceof PsiJavaToken)) { + int offset = returnStatement.getTextRange().getEndOffset(); + final PsiMethod method = PsiTreeUtil.getParentOfType(returnStatement, PsiMethod.class); + if (method != null && method.getReturnType() == PsiType.VOID) { + offset = returnStatement.getTextRange().getStartOffset() + "return".length(); + } + editor.getDocument().insertString(offset, ";"); + //processor.setSkipEnter(true); + return true; + } + + PsiJavaToken prevToken = (PsiJavaToken)prev; + if (prevToken.getTokenType() == JavaTokenType.SEMICOLON) { + return false; + } + + final int offset = returnStatement.getTextRange().getEndOffset(); + editor.getDocument().insertString(offset, ";"); + if (prevToken.getTokenType() == JavaTokenType.RETURN_KEYWORD) { + final PsiMethod method = PsiTreeUtil.getParentOfType(returnStatement, PsiMethod.class); + if (method != null && method.getReturnType() != PsiType.VOID) { + editor.getCaretModel().moveToOffset(offset); + processor.setSkipEnter(true); + } + } + return true; + } + private static int lineNumber(Editor editor, int offset) { return editor.getDocument().getLineNumber(offset); } diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java index eb0ea9d98b50..3316c448d652 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ConcatenationToMessageFormatAction.java @@ -20,11 +20,11 @@ import com.intellij.codeInsight.CodeInsightUtilBase; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; import com.intellij.psi.codeStyle.JavaCodeStyleManager; import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.util.PsiConcatenationUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; import com.intellij.util.IncorrectOperationException; @@ -51,7 +51,7 @@ public class ConcatenationToMessageFormatAction implements IntentionAction { public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { if (!CodeInsightUtilBase.prepareFileForWrite(file)) return; final PsiElement element = findElementAtCaret(editor, file); - PsiBinaryExpression concatenation = getEnclosingLiteralConcatenation(element); + PsiPolyadicExpression concatenation = getEnclosingLiteralConcatenation(element); if (concatenation == null) return; StringBuilder formatString = new StringBuilder(); List args = new ArrayList(); @@ -86,27 +86,8 @@ public class ConcatenationToMessageFormatAction implements IntentionAction { StringBuilder formatString, List args) throws IncorrectOperationException { - if (expression instanceof PsiBinaryExpression) { - final PsiType type = expression.getType(); - if (type != null && type.equalsToText("java.lang.String") - && ((PsiBinaryExpression)expression).getOperationTokenType() == JavaTokenType.PLUS) { - buildMessageFormatString(((PsiBinaryExpression)expression).getLOperand(), formatString, args); - final PsiExpression rhs = ((PsiBinaryExpression)expression).getROperand(); - if (rhs != null) { - buildMessageFormatString(rhs, formatString, args); - } - } - else { - appendArgument(args, expression, formatString); - } - } - else if (expression instanceof PsiLiteralExpression) { - final String text = String.valueOf(((PsiLiteralExpression)expression).getValue()); - formatString.append(StringUtil.escapeStringCharacters(text).replace("'", "''").replace("{", "'{'")); - } - else { - appendArgument(args, expression, formatString); - } + PsiConcatenationUtil.buildFormatString(expression, formatString, args, false); + } private static void appendArgument(List args, PsiExpression argument, StringBuilder formatString) throws IncorrectOperationException { @@ -117,52 +98,40 @@ public class ConcatenationToMessageFormatAction implements IntentionAction { private static PsiExpression getBoxedArgument(PsiExpression arg) throws IncorrectOperationException { arg = PsiUtil.deparenthesizeExpression(arg); assert arg != null; - if (!PsiUtil.isLanguageLevel5OrHigher(arg)) { - final PsiType type = arg.getType(); - if (type instanceof PsiPrimitiveType && !type.equals(PsiType.NULL)) { - final PsiPrimitiveType primitiveType = (PsiPrimitiveType)type; - final String boxedQName = primitiveType.getBoxedTypeName(); - if (boxedQName != null) { - final GlobalSearchScope resolveScope = arg.getResolveScope(); - final PsiElementFactory factory = JavaPsiFacade.getElementFactory(arg.getProject()); - final PsiJavaCodeReferenceElement ref = factory.createReferenceElementByFQClassName(boxedQName, resolveScope); - final PsiNewExpression newExpr = (PsiNewExpression)factory.createExpressionFromText("new A(b)", null); - final PsiElement classRef = newExpr.getClassReference(); - assert classRef != null; - classRef.replace(ref); - final PsiExpressionList argumentList = newExpr.getArgumentList(); - assert argumentList != null; - argumentList.getExpressions()[0].replace(arg); - return newExpr; - } - } + if (PsiUtil.isLanguageLevel5OrHigher(arg)) { + return arg; } - return arg; + final PsiType type = arg.getType(); + if (!(type instanceof PsiPrimitiveType) || type.equals(PsiType.NULL)) { + return arg; + } + final PsiPrimitiveType primitiveType = (PsiPrimitiveType)type; + final String boxedQName = primitiveType.getBoxedTypeName(); + if (boxedQName == null) { + return arg; + } + final GlobalSearchScope resolveScope = arg.getResolveScope(); + final PsiElementFactory factory = JavaPsiFacade.getElementFactory(arg.getProject()); + final PsiJavaCodeReferenceElement ref = factory.createReferenceElementByFQClassName(boxedQName, resolveScope); + final PsiNewExpression newExpr = (PsiNewExpression)factory.createExpressionFromText("new A(b)", null); + final PsiElement classRef = newExpr.getClassReference(); + assert classRef != null; + classRef.replace(ref); + final PsiExpressionList argumentList = newExpr.getArgumentList(); + assert argumentList != null; + argumentList.getExpressions()[0].replace(arg); + return newExpr; } public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { if (PsiUtil.getLanguageLevel(file).compareTo(LanguageLevel.JDK_1_4) < 0) return false; final PsiElement element = findElementAtCaret(editor, file); - PsiBinaryExpression binaryExpression = PsiTreeUtil.getParentOfType(element, PsiBinaryExpression.class, false, PsiMember.class); - if (binaryExpression == null) return false; - final PsiType type = binaryExpression.getType(); - if (type == null) return false; - if (!type.equalsToText("java.lang.String")) { - return false; - } - return !isInsideAnnotation(binaryExpression); + PsiPolyadicExpression binaryExpression = getEnclosingLiteralConcatenation(element); + return binaryExpression != null && !isInsideAnnotation(binaryExpression); } private static boolean isInsideAnnotation(PsiElement element) { - for (int i = 0; i < 20 && element instanceof PsiBinaryExpression; i++) { - // optimization: don't check deep string concatenations more than 20 levels up. - element = element.getParent(); - if (element instanceof PsiNameValuePair || - element instanceof PsiArrayInitializerMemberValue) { - return true; - } - } - return false; + return PsiTreeUtil.getParentOfType(element, PsiNameValuePair.class, PsiArrayInitializerMemberValue.class) != null; } @Nullable @@ -171,15 +140,15 @@ public class ConcatenationToMessageFormatAction implements IntentionAction { } @Nullable - private static PsiBinaryExpression getEnclosingLiteralConcatenation(final PsiElement element) { - PsiBinaryExpression binaryExpression = PsiTreeUtil.getParentOfType(element, PsiBinaryExpression.class, false, PsiMember.class); + private static PsiPolyadicExpression getEnclosingLiteralConcatenation(final PsiElement element) { + PsiPolyadicExpression binaryExpression = PsiTreeUtil.getParentOfType(element, PsiPolyadicExpression.class, false, PsiMember.class); if (binaryExpression == null) return null; final PsiClassType stringType = PsiType.getJavaLangString(element.getManager(), element.getResolveScope()); if (!stringType.equals(binaryExpression.getType())) return null; while (true) { final PsiElement parent = binaryExpression.getParent(); - if (!(parent instanceof PsiBinaryExpression)) return binaryExpression; - final PsiBinaryExpression parentBinaryExpression = (PsiBinaryExpression)parent; + if (!(parent instanceof PsiPolyadicExpression)) return binaryExpression; + PsiPolyadicExpression parentBinaryExpression = (PsiBinaryExpression)parent; if (!stringType.equals(parentBinaryExpression.getType())) return binaryExpression; binaryExpression = parentBinaryExpression; } diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/SplitIfAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/SplitIfAction.java index 15b9f6f66d48..ecabce5c2eb4 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/SplitIfAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/SplitIfAction.java @@ -36,20 +36,19 @@ public class SplitIfAction extends PsiElementBaseIntentionAction { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.intention.impl.SplitIfAction"); public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { - if (!(element instanceof PsiJavaToken)) { return false; } PsiJavaToken token = (PsiJavaToken)element; - if (!(token.getParent() instanceof PsiBinaryExpression)) return false; + if (!(token.getParent() instanceof PsiPolyadicExpression)) return false; - PsiBinaryExpression expression = (PsiBinaryExpression)token.getParent(); + PsiPolyadicExpression expression = (PsiPolyadicExpression)token.getParent(); boolean isAndExpression = expression.getOperationTokenType() == JavaTokenType.ANDAND; boolean isOrExpression = expression.getOperationTokenType() == JavaTokenType.OROR; if (!isAndExpression && !isOrExpression) return false; - while (expression.getParent() instanceof PsiBinaryExpression) { - expression = (PsiBinaryExpression)expression.getParent(); + while (expression.getParent() instanceof PsiPolyadicExpression) { + expression = (PsiPolyadicExpression)expression.getParent(); if (isAndExpression && expression.getOperationTokenType() != JavaTokenType.ANDAND) return false; if (isOrExpression && expression.getOperationTokenType() != JavaTokenType.OROR) return false; } @@ -80,16 +79,16 @@ public class SplitIfAction extends PsiElementBaseIntentionAction { PsiJavaToken token = (PsiJavaToken)file.findElementAt(offset); LOG.assertTrue(token.getTokenType() == JavaTokenType.ANDAND || token.getTokenType() == JavaTokenType.OROR); - PsiBinaryExpression expression = (PsiBinaryExpression)token.getParent(); + PsiPolyadicExpression expression = (PsiPolyadicExpression)token.getParent(); PsiIfStatement ifStatement = PsiTreeUtil.getParentOfType(expression, PsiIfStatement.class); LOG.assertTrue(PsiTreeUtil.isAncestor(ifStatement.getCondition(), expression, false)); if (token.getTokenType() == JavaTokenType.ANDAND) { - doAndSplit(ifStatement, expression, editor); + doAndSplit(ifStatement, expression, token, editor); } else if (token.getTokenType() == JavaTokenType.OROR) { - doOrSplit(ifStatement, expression, editor); + doOrSplit(ifStatement, expression, token, editor); } } catch (IncorrectOperationException e) { @@ -97,10 +96,9 @@ public class SplitIfAction extends PsiElementBaseIntentionAction { } } - private static void doAndSplit(PsiIfStatement ifStatement, PsiBinaryExpression expression, Editor editor) throws IncorrectOperationException { - PsiExpression lOperand = expression.getLOperand(); - PsiExpression rOperand = getROperand(expression); - + private static void doAndSplit(PsiIfStatement ifStatement, PsiPolyadicExpression expression, PsiJavaToken token, Editor editor) throws IncorrectOperationException { + PsiExpression lOperand = getLOperands(expression, token); + PsiExpression rOperand = getROperands(expression, token); PsiManager psiManager = ifStatement.getManager(); PsiIfStatement subIf = (PsiIfStatement)ifStatement.copy(); @@ -109,7 +107,8 @@ public class SplitIfAction extends PsiElementBaseIntentionAction { ifStatement.getCondition().replace(RefactoringUtil.unparenthesizeExpression(lOperand)); if (ifStatement.getThenBranch() instanceof PsiBlockStatement) { - PsiBlockStatement blockStmt = (PsiBlockStatement)JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory().createStatementFromText("{}", null); + PsiBlockStatement blockStmt = + (PsiBlockStatement)JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory().createStatementFromText("{}", null); blockStmt = (PsiBlockStatement)CodeStyleManager.getInstance(psiManager.getProject()).reformat(blockStmt); blockStmt = (PsiBlockStatement)ifStatement.getThenBranch().replace(blockStmt); blockStmt.getCodeBlock().add(subIf); @@ -125,17 +124,33 @@ public class SplitIfAction extends PsiElementBaseIntentionAction { editor.getSelectionModel().removeSelection(); } - private static PsiExpression getROperand(PsiBinaryExpression expression) throws IncorrectOperationException { - PsiElement e = expression; - while (!(e.getParent() instanceof PsiIfStatement)) e = e.getParent(); + private static PsiExpression getROperands(PsiPolyadicExpression expression, PsiJavaToken separator) throws IncorrectOperationException { + PsiElement next = separator.getNextSibling(); + if (next instanceof PsiWhiteSpace) next = next.getNextSibling(); + if (next == null) { + throw new IncorrectOperationException("Unable to split '"+expression.getText()+"' at '"+separator+"' (offset "+separator.getStartOffsetInParent()+")"); + } - return JavaPsiFacade.getInstance(expression.getProject()).getElementFactory().createExpressionFromText( - e.getText().substring(expression.getROperand().getTextRange().getStartOffset() - e.getTextRange().getStartOffset()), e.getParent()); + PsiElementFactory factory = JavaPsiFacade.getInstance(expression.getProject()).getElementFactory(); + String rOperands = expression.getText().substring(next.getStartOffsetInParent()); + return factory.createExpressionFromText(rOperands, expression.getParent()); } - private static void doOrSplit(PsiIfStatement ifStatement, PsiBinaryExpression expression, Editor editor) throws IncorrectOperationException { - PsiExpression lOperand = expression.getLOperand(); - PsiExpression rOperand = getROperand(expression); + private static PsiExpression getLOperands(PsiPolyadicExpression expression, PsiJavaToken separator) throws IncorrectOperationException { + PsiElement next = separator; + if (next.getPrevSibling() instanceof PsiWhiteSpace) next = next.getPrevSibling(); + if (next == null) { + throw new IncorrectOperationException("Unable to split '"+expression.getText()+"' left to '"+separator+"' (offset "+separator.getStartOffsetInParent()+")"); + } + + PsiElementFactory factory = JavaPsiFacade.getInstance(expression.getProject()).getElementFactory(); + String rOperands = expression.getText().substring(0, next.getStartOffsetInParent()); + return factory.createExpressionFromText(rOperands, expression.getParent()); + } + + private static void doOrSplit(PsiIfStatement ifStatement, PsiPolyadicExpression expression, PsiJavaToken token, Editor editor) throws IncorrectOperationException { + PsiExpression lOperand = getLOperands(expression, token); + PsiExpression rOperand = getROperands(expression, token); PsiIfStatement secondIf = (PsiIfStatement)ifStatement.copy(); diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java index 128980674a03..fed5428b22c2 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java @@ -33,10 +33,7 @@ import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; -import java.util.Stack; +import java.util.*; class ControlFlowAnalyzer extends JavaElementVisitor { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.dataFlow.ControlFlowAnalyzer"); @@ -170,7 +167,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor { } else if (op == JavaTokenType.XOREQ) { if (isBoolean) { - generateXorExpression(expression, lExpr, rExpr, type); + generateXorExpression(expression, new PsiExpression[]{lExpr, rExpr}, type); } else { generateDefaultBinop(lExpr, rExpr, type); @@ -873,69 +870,35 @@ class ControlFlowAnalyzer extends JavaElementVisitor { finishElement(expression); } - @Override public void visitBinaryExpression(PsiBinaryExpression expression) { + @Override + public void visitPolyadicExpression(PsiPolyadicExpression expression) { startElement(expression); try { DfaValue dfaValue = myFactory.create(expression); if (dfaValue != null) { addInstruction(new PushInstruction(dfaValue, expression)); + return; + } + IElementType op = expression.getOperationTokenType(); + + PsiExpression[] operands = expression.getOperands(); + if (operands.length <= 1) { + pushUnknown(); + return; + } + PsiType type = expression.getType(); + if (op == JavaTokenType.ANDAND) { + generateAndExpression(operands, type); + } + else if (op == JavaTokenType.OROR) { + generateOrExpression(operands, type); + } + else if (op == JavaTokenType.XOR && PsiType.BOOLEAN.equals(type)) { + generateXorExpression(expression, operands, type); } else { - IElementType op = expression.getOperationTokenType(); - PsiExpression lExpr = expression.getLOperand(); - PsiExpression rExpr = expression.getROperand(); - - if (rExpr == null) { - pushUnknown(); - return; - } - PsiType type = expression.getType(); - if (op == JavaTokenType.ANDAND) { - generateAndExpression(lExpr, rExpr, type); - } - else if (op == JavaTokenType.OROR) { - generateOrExpression(lExpr, rExpr, type); - } - else if (op == JavaTokenType.XOR && PsiType.BOOLEAN.equals(type)) { - generateXorExpression(expression, lExpr, rExpr, type); - } - else { - lExpr.accept(this); - boolean comparing = op == JavaTokenType.EQEQ || op == JavaTokenType.NE; - PsiType lType = lExpr.getType(); - PsiType rType = rExpr.getType(); - - boolean comparingRef = comparing - && !TypeConversionUtil.isPrimitiveAndNotNull(lType) - && !TypeConversionUtil.isPrimitiveAndNotNull(rType); - - boolean comparingPrimitiveNumerics = comparing && - TypeConversionUtil.isPrimitiveAndNotNull(lType) && - TypeConversionUtil.isPrimitiveAndNotNull(rType) && - TypeConversionUtil.isNumericType(lType) && - TypeConversionUtil.isNumericType(rType); - - PsiType castType = comparingPrimitiveNumerics ? PsiType.LONG : type; - - if (!comparingRef) { - generateBoxingUnboxingInstructionFor(lExpr,castType); - } - rExpr.accept(this); - if (!comparingRef) { - generateBoxingUnboxingInstructionFor(rExpr,castType); - } - - String opSign = expression.getOperationSign().getText(); - if ("+".equals(opSign)) { - if (type == null || !type.equalsToText("java.lang.String")) { - opSign = null; - } - } - - PsiElement psiAnchor = expression.isPhysical() ? expression : null; - addInstruction(new BinopInstruction(opSign, psiAnchor, expression.getProject())); - } + generateOther(expression, op, operands, type); } } finally { @@ -943,6 +906,55 @@ class ControlFlowAnalyzer extends JavaElementVisitor { } } + private void generateOther(PsiPolyadicExpression expression, + IElementType op, + PsiExpression[] operands, + PsiType type) { + boolean comparing = op == JavaTokenType.EQEQ || op == JavaTokenType.NE; + PsiExpression lExpr = operands[0]; + lExpr.accept(this); + PsiType lType = lExpr.getType(); + PsiExpression rExpr = operands[1]; + + for (int i = 1; i < operands.length; i++) { + rExpr = operands[i]; + PsiType rType = rExpr.getType(); + + boolean comparingRef = comparing + && !TypeConversionUtil.isPrimitiveAndNotNull(lType) + && !TypeConversionUtil.isPrimitiveAndNotNull(rType); + + boolean comparingPrimitiveNumerics = comparing && + TypeConversionUtil.isPrimitiveAndNotNull(lType) && + TypeConversionUtil.isPrimitiveAndNotNull(rType) && + TypeConversionUtil.isNumericType(lType) && + TypeConversionUtil.isNumericType(rType); + + PsiType castType = comparingPrimitiveNumerics ? PsiType.LONG : type; + + if (!comparingRef) { + generateBoxingUnboxingInstructionFor(lExpr,castType); + } + + lExpr = rExpr; + lType = rType; + + rExpr.accept(this); + if (!comparingRef) { + generateBoxingUnboxingInstructionFor(rExpr,castType); + } + + if (JavaTokenType.PLUS == op) { + if (type == null || !type.equalsToText("java.lang.String")) { + op = null; + } + } + + PsiElement psiAnchor = expression.isPhysical() ? expression : null; + addInstruction(new BinopInstruction(op, psiAnchor, expression.getProject())); + } + } + private void generateBoxingUnboxingInstructionFor(PsiExpression expression, PsiType expectedType) { PsiType exprType = expression.getType(); @@ -966,23 +978,31 @@ class ControlFlowAnalyzer extends JavaElementVisitor { } } - private void generateXorExpression(PsiExpression expression, PsiExpression lExpr, PsiExpression rExpr, final PsiType exprType) { - lExpr.accept(this); - generateBoxingUnboxingInstructionFor(lExpr,exprType); - rExpr.accept(this); - generateBoxingUnboxingInstructionFor(rExpr,exprType); - PsiElement psiAnchor = expression.isPhysical() ? expression : null; - addInstruction(new BinopInstruction("!=", psiAnchor, expression.getProject())); + private void generateXorExpression(PsiExpression expression, PsiExpression[] operands, final PsiType exprType) { + PsiExpression operand = operands[0]; + operand.accept(this); + generateBoxingUnboxingInstructionFor(operand, exprType); + for (int i = 1; i < operands.length; i++) { + operand = operands[i]; + operand.accept(this); + generateBoxingUnboxingInstructionFor(operand, exprType); + PsiElement psiAnchor = expression.isPhysical() ? expression : null; + addInstruction(new BinopInstruction(JavaTokenType.NE, psiAnchor, expression.getProject())); + } } - private void generateOrExpression(PsiExpression lExpr, PsiExpression rExpr, final PsiType exprType) { - lExpr.accept(this); - generateBoxingUnboxingInstructionFor(lExpr,exprType); - addInstruction(new ConditionalGotoInstruction(getStartOffset(rExpr), true, lExpr)); - addInstruction(new PushInstruction(myFactory.getConstFactory().getTrue(), null)); - addInstruction(new GotoInstruction(getEndOffset(rExpr))); - rExpr.accept(this); - generateBoxingUnboxingInstructionFor(rExpr,exprType); + private void generateOrExpression(PsiExpression[] operands, final PsiType exprType) { + for (int i = 0; i < operands.length; i++) { + PsiExpression operand = operands[i]; + operand.accept(this); + generateBoxingUnboxingInstructionFor(operand, exprType); + PsiExpression nextOperand = i == operands.length - 1 ? null : operands[i + 1]; + if (nextOperand != null) { + addInstruction(new ConditionalGotoInstruction(getStartOffset(nextOperand), true, operand)); + addInstruction(new PushInstruction(myFactory.getConstFactory().getTrue(), null)); + addInstruction(new GotoInstruction(getEndOffset(operands[operands.length - 1]))); + } + } } private void generateNonMaccartyExpression(boolean and, PsiExpression lExpression, PsiExpression rExpression, final PsiType exprType) { @@ -1008,21 +1028,30 @@ class ControlFlowAnalyzer extends JavaElementVisitor { overPushSuccess.setOffset(pushSuccess.getIndex() + 1); } - private void generateAndExpression(PsiExpression lExpr, PsiExpression rExpr, final PsiType exprType) { - lExpr.accept(this); - generateBoxingUnboxingInstructionFor(lExpr, exprType); - ConditionalGotoInstruction firstTrueGoto = new ConditionalGotoInstruction(-1, true, lExpr); - addInstruction(firstTrueGoto); - rExpr.accept(this); - generateBoxingUnboxingInstructionFor(rExpr, exprType); + private void generateAndExpression(PsiExpression[] operands, final PsiType exprType) { + List branchToFail = new ArrayList(); + for (int i = 0; i < operands.length; i++) { + PsiExpression operand = operands[i]; + operand.accept(this); + generateBoxingUnboxingInstructionFor(operand, exprType); + PsiExpression nextOperand = i == operands.length - 1 ? null : operands[i + 1]; - GotoInstruction overPushFalse = new GotoInstruction(-1); - addInstruction(overPushFalse); + if (nextOperand != null) { + ConditionalGotoInstruction onFail = new ConditionalGotoInstruction(-1, true, operand); + branchToFail.add(onFail); + addInstruction(onFail); + } + } + + GotoInstruction toSuccess = new GotoInstruction(-1); + addInstruction(toSuccess); PushInstruction pushFalse = new PushInstruction(myFactory.getConstFactory().getFalse(), null); addInstruction(pushFalse); + for (ConditionalGotoInstruction toFail : branchToFail) { + toFail.setOffset(pushFalse.getIndex()); + } + toSuccess.setOffset(pushFalse.getIndex()+1); - firstTrueGoto.setOffset(pushFalse.getIndex()); - overPushFalse.setOffset(pushFalse.getIndex() + 1); } @Override public void visitClassObjectAccessExpression(PsiClassObjectAccessExpression expression) { @@ -1196,7 +1225,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor { pushParameters(params, true, !testng); addInstruction(new PushInstruction(myFactory.getConstFactory().getNull(), null)); - addInstruction(new BinopInstruction("==", null, expression.getProject())); + addInstruction(new BinopInstruction(JavaTokenType.EQEQ, null, expression.getProject())); conditionalExit(exitPoint, false); return true; } @@ -1204,7 +1233,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor { pushParameters(params, true, !testng); addInstruction(new PushInstruction(myFactory.getConstFactory().getNull(), null)); - addInstruction(new BinopInstruction("==", null, expression.getProject())); + addInstruction(new BinopInstruction(JavaTokenType.EQEQ, null, expression.getProject())); conditionalExit(exitPoint, true); return true; } @@ -1370,7 +1399,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor { PsiType type = expression.getType(); PsiPrimitiveType unboxed = PsiPrimitiveType.getUnboxedType(type); generateBoxingUnboxingInstructionFor(operand, unboxed == null ? type : unboxed); - if (expression.getOperationSign().getTokenType() == JavaTokenType.EXCL) { + if (expression.getOperationTokenType() == JavaTokenType.EXCL) { addInstruction(new NotInstruction()); } else { diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java index 7cdb9aaaf144..ec33cc801cc1 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java @@ -27,6 +27,7 @@ package com.intellij.codeInspection.dataFlow; import com.intellij.codeInspection.dataFlow.value.*; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressManager; +import com.intellij.psi.JavaTokenType; import com.intellij.psi.PsiType; import com.intellij.psi.PsiVariable; import com.intellij.psi.util.TypeConversionUtil; @@ -261,16 +262,16 @@ public class DfaMemoryStateImpl implements DfaMemoryState { getVariableState(var).setValue(value); if (value instanceof DfaNotNullValue) { DfaTypeValue dfaType = myFactory.getTypeFactory().create(((DfaNotNullValue)value).getType()); - DfaRelationValue dfaInstanceof = myFactory.getRelationFactory().create(var, dfaType, "instanceof", false); + DfaRelationValue dfaInstanceof = myFactory.getRelationFactory().create(var, dfaType, JavaTokenType.INSTANCEOF_KEYWORD, false); applyCondition(dfaInstanceof); applyCondition(compareToNull(var, true)); } else if (value instanceof DfaTypeValue) { - DfaRelationValue dfaInstanceof = myFactory.getRelationFactory().create(var, value, "instanceof", false); + DfaRelationValue dfaInstanceof = myFactory.getRelationFactory().create(var, value, JavaTokenType.INSTANCEOF_KEYWORD, false); applyInstanceofOrNull(dfaInstanceof); } else { - DfaRelationValue dfaEqual = myFactory.getRelationFactory().create(var, value, "==", false); + DfaRelationValue dfaEqual = myFactory.getRelationFactory().create(var, value, JavaTokenType.EQEQ, false); if (dfaEqual == null) return; applyCondition(dfaEqual); @@ -514,7 +515,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState { DfaVariableValue dfaNormalVar = isNegated ? (DfaVariableValue)dfaVar.createNegated() : dfaVar; DfaConstValue dfaTrue = myFactory.getConstFactory().getTrue(); final DfaValue boxedTrue = myFactory.getBoxedFactory().createBoxed(dfaTrue); - DfaRelationValue dfaEqualsTrue = myFactory.getRelationFactory().create(dfaNormalVar, boxedTrue, "==", isNegated); + DfaRelationValue dfaEqualsTrue = myFactory.getRelationFactory().create(dfaNormalVar, boxedTrue, JavaTokenType.EQEQ, isNegated); return applyCondition(dfaEqualsTrue); } @@ -523,7 +524,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState { boolean isNegated = dfaVar.isNegated(); DfaVariableValue dfaNormalVar = isNegated ? (DfaVariableValue)dfaVar.createNegated() : dfaVar; DfaConstValue dfaTrue = myFactory.getConstFactory().getTrue(); - DfaRelationValue dfaEqualsTrue = myFactory.getRelationFactory().create(dfaNormalVar, dfaTrue, "==", isNegated); + DfaRelationValue dfaEqualsTrue = myFactory.getRelationFactory().create(dfaNormalVar, dfaTrue, JavaTokenType.EQEQ, isNegated); return applyCondition(dfaEqualsTrue); } @@ -643,7 +644,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState { @Nullable private DfaRelationValue compareToNull(DfaValue dfaVar, boolean negated) { DfaConstValue dfaNull = myFactory.getConstFactory().getNull(); - return myFactory.getRelationFactory().create(dfaVar, dfaNull, "==", negated); + return myFactory.getRelationFactory().create(dfaVar, dfaNull, JavaTokenType.EQEQ, negated); } public DfaVariableState getVariableState(DfaVariableValue dfaVar) { diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaUtil.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaUtil.java index f9d05fd30278..6b3e025cb79b 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaUtil.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaUtil.java @@ -15,6 +15,11 @@ */ package com.intellij.codeInspection.dataFlow; +import com.intellij.codeInspection.dataFlow.instructions.AssignInstruction; +import com.intellij.codeInspection.dataFlow.instructions.Instruction; +import com.intellij.codeInspection.dataFlow.instructions.PushInstruction; +import com.intellij.codeInspection.dataFlow.value.DfaValue; +import com.intellij.codeInspection.dataFlow.value.DfaVariableValue; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.MultiValuesMap; import com.intellij.openapi.util.Ref; @@ -28,14 +33,10 @@ import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.NullableFunction; import com.intellij.util.containers.ContainerUtil; -import com.intellij.codeInspection.dataFlow.instructions.PushInstruction; -import com.intellij.codeInspection.dataFlow.instructions.AssignInstruction; -import com.intellij.codeInspection.dataFlow.instructions.Instruction; -import com.intellij.codeInspection.dataFlow.value.DfaVariableValue; -import com.intellij.codeInspection.dataFlow.value.DfaValue; +import com.intellij.util.containers.Stack; import gnu.trove.THashSet; -import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; @@ -213,16 +214,14 @@ public class DfaUtil { if (expression == null) return false; if (expression instanceof PsiLiteralExpression) return true; if (expression instanceof PsiBinaryExpression) { - final LinkedList stack = new LinkedList(); + Stack stack = new Stack(); stack.add(expression); while (!stack.isEmpty()) { - final PsiExpression psiExpression = stack.removeFirst(); - if (psiExpression instanceof PsiBinaryExpression) { - final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)psiExpression; - stack.addLast(binaryExpression.getLOperand()); - final PsiExpression right = binaryExpression.getROperand(); - if (right != null) { - stack.addLast(right); + PsiExpression psiExpression = stack.pop(); + if (psiExpression instanceof PsiPolyadicExpression) { + PsiPolyadicExpression binaryExpression = (PsiPolyadicExpression)psiExpression; + for (PsiExpression op : binaryExpression.getOperands()) { + stack.push(op); } } else if (!(psiExpression instanceof PsiLiteralExpression)) { diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/InstructionFactory.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/InstructionFactory.java index f0b8fd770126..dd618ae606e7 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/InstructionFactory.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/InstructionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.codeInspection.dataFlow; /** - * @author Gregory.Shrago + * User: cdr */ public class InstructionFactory { - } diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardDataFlowRunner.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardDataFlowRunner.java index 7ae9a281bbea..3ed81ec2dc72 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardDataFlowRunner.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardDataFlowRunner.java @@ -43,11 +43,11 @@ import java.util.Set; public class StandardDataFlowRunner extends AnnotationsAwareDataFlowRunner { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.dataFlow.DataFlowRunner"); - private final HashSet myNPEInstructions = new HashSet(); - private final HashSet myCCEInstructions = new HashSet(); - private final HashSet myNullableArguments = new HashSet(); - private final HashSet myNullableAssignments = new HashSet(); - private final HashSet myNullableReturns = new HashSet(); + private final Set myNPEInstructions = new HashSet(); + private final Set myCCEInstructions = new HashSet(); + private final Set myNullableArguments = new HashSet(); + private final Set myNullableAssignments = new HashSet(); + private final Set myNullableReturns = new HashSet(); private final boolean mySuggestNullableAnnotations; private boolean myInNullableMethod = false; diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java index 02cce92a84ea..1d0c8aef988e 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java @@ -20,6 +20,7 @@ import com.intellij.codeInsight.NullableNotNullManager; import com.intellij.codeInspection.dataFlow.instructions.*; import com.intellij.codeInspection.dataFlow.value.*; import com.intellij.psi.*; +import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.TypeConversionUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.FactoryMap; @@ -136,7 +137,7 @@ public class StandardInstructionVisitor extends InstructionVisitor { DfaValue dfaExpr = factory.create(instruction.getCasted()); if (dfaExpr != null) { DfaTypeValue dfaType = factory.getTypeFactory().create(instruction.getCastTo()); - DfaRelationValue dfaInstanceof = factory.getRelationFactory().create(dfaExpr, dfaType, "instanceof", false); + DfaRelationValue dfaInstanceof = factory.getRelationFactory().create(dfaExpr, dfaType, JavaTokenType.INSTANCEOF_KEYWORD, false); if (dfaInstanceof != null && !memState.applyInstanceofOrNull(dfaInstanceof)) { onInstructionProducesCCE(instruction, runner); } @@ -239,12 +240,12 @@ public class StandardInstructionVisitor extends InstructionVisitor { DfaValue dfaRight = memState.pop(); DfaValue dfaLeft = memState.pop(); - final String opSign = instruction.getOperationSign(); + final IElementType opSign = instruction.getOperationSign(); if (opSign != null) { final DfaValueFactory factory = runner.getFactory(); - if (("==".equals(opSign) || "!=".equals(opSign)) && + if ((JavaTokenType.EQEQ == opSign || JavaTokenType.NE == opSign) && dfaLeft instanceof DfaConstValue && dfaRight instanceof DfaConstValue) { - boolean negated = "!=".equals(opSign) ^ (memState.canBeNaN(dfaLeft) || memState.canBeNaN(dfaRight)); + boolean negated = (JavaTokenType.NE == opSign) ^ (memState.canBeNaN(dfaLeft) || memState.canBeNaN(dfaRight)); if (dfaLeft == dfaRight ^ negated) { memState.push(factory.getConstFactory().getTrue()); instruction.setTrueReachable(); @@ -282,7 +283,7 @@ public class StandardInstructionVisitor extends InstructionVisitor { return states.toArray(new DfaInstructionState[states.size()]); } - else if ("+".equals(opSign)) { + else if (JavaTokenType.PLUS == opSign) { memState.push(instruction.getNonNullStringValue(factory)); instruction.setTrueReachable(); // Not a branching instruction actually. instruction.setFalseReachable(); diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/BinopInstruction.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/BinopInstruction.java index 3f79ddd4dd90..5e13d70118f2 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/BinopInstruction.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/BinopInstruction.java @@ -31,21 +31,18 @@ import com.intellij.codeInspection.dataFlow.InstructionVisitor; import com.intellij.codeInspection.dataFlow.value.DfaValue; import com.intellij.codeInspection.dataFlow.value.DfaValueFactory; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiClassType; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiManager; -import com.intellij.psi.PsiType; +import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; -import org.jetbrains.annotations.NonNls; +import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; public class BinopInstruction extends BranchingInstruction { - private final String myOperationSign; + private final IElementType myOperationSign; private final Project myProject; - public BinopInstruction(@NonNls String opSign, PsiElement psiAnchor, @NotNull Project project) { + public BinopInstruction(IElementType opSign, PsiElement psiAnchor, @NotNull Project project) { myProject = project; - if (opSign != null && ("==".equals(opSign) || "!=".equals(opSign) || "instanceof".equals(opSign) || "+".equals(opSign))) { + if (JavaTokenType.EQEQ == opSign || JavaTokenType.NE == opSign || JavaTokenType.INSTANCEOF_KEYWORD == opSign || JavaTokenType.PLUS == opSign) { myOperationSign = opSign; } else { @@ -71,7 +68,7 @@ public class BinopInstruction extends BranchingInstruction { return "BINOP " + myOperationSign; } - public String getOperationSign() { + public IElementType getOperationSign() { return myOperationSign; } } diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/ConditionalGotoInstruction.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/ConditionalGotoInstruction.java index ccd3a3f247b9..4459c35d1b40 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/ConditionalGotoInstruction.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/ConditionalGotoInstruction.java @@ -51,7 +51,7 @@ public class ConditionalGotoInstruction extends BranchingInstruction { } public String toString() { - return "cond_goto " + myOffset; + return (isNegated() ? "!":"") + "cond?_goto " + myOffset; } public int getOffset() { diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/InstanceofInstruction.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/InstanceofInstruction.java index 1f3e65810772..68a8282a5135 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/InstanceofInstruction.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/InstanceofInstruction.java @@ -20,10 +20,7 @@ import com.intellij.codeInspection.dataFlow.DfaInstructionState; import com.intellij.codeInspection.dataFlow.DfaMemoryState; import com.intellij.codeInspection.dataFlow.InstructionVisitor; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiExpression; -import com.intellij.psi.PsiKeyword; -import com.intellij.psi.PsiType; +import com.intellij.psi.*; import org.jetbrains.annotations.NotNull; /** @@ -34,7 +31,7 @@ public class InstanceofInstruction extends BinopInstruction { @NotNull private final PsiType myCastType; public InstanceofInstruction(PsiElement psiAnchor, @NotNull Project project, PsiExpression left, PsiType castType) { - super(PsiKeyword.INSTANCEOF, psiAnchor, project); + super(JavaTokenType.INSTANCEOF_KEYWORD, psiAnchor, project); myLeft = left; myCastType = castType; } diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/value/DfaRelationValue.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/value/DfaRelationValue.java index 63246a6f20f8..9a25452431cd 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/value/DfaRelationValue.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/value/DfaRelationValue.java @@ -25,6 +25,8 @@ package com.intellij.codeInspection.dataFlow.value; import com.intellij.openapi.util.Comparing; +import com.intellij.psi.JavaTokenType; +import com.intellij.psi.tree.IElementType; import com.intellij.util.containers.HashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; @@ -34,7 +36,7 @@ import java.util.ArrayList; public class DfaRelationValue extends DfaValue { private DfaValue myLeftOperand; private DfaValue myRightOperand; - private String myRelation; + private IElementType myRelation; private boolean myIsNegated; public static class Factory { @@ -49,9 +51,9 @@ public class DfaRelationValue extends DfaValue { } @Nullable - public DfaRelationValue create(DfaValue dfaLeft, DfaValue dfaRight, @NonNls String relation, boolean negated) { - if (dfaRight instanceof DfaTypeValue && !"instanceof".equals(relation)) return null; - if ("+".equals(relation)) return null; + public DfaRelationValue create(DfaValue dfaLeft, DfaValue dfaRight, IElementType relation, boolean negated) { + if (dfaRight instanceof DfaTypeValue && JavaTokenType.INSTANCEOF_KEYWORD != relation) return null; + if (JavaTokenType.PLUS == relation) return null; if (dfaLeft instanceof DfaVariableValue || dfaLeft instanceof DfaBoxedValue || dfaLeft instanceof DfaUnboxedValue || dfaRight instanceof DfaVariableValue || dfaRight instanceof DfaBoxedValue || dfaRight instanceof DfaUnboxedValue) { @@ -72,21 +74,21 @@ public class DfaRelationValue extends DfaValue { } } - private DfaRelationValue createCanonicalRelation(String relation, + private DfaRelationValue createCanonicalRelation(IElementType relation, boolean negated, final DfaValue dfaLeft, final DfaValue dfaRight) { // To canonical form. - if ("!=".equals(relation)) { - relation = "=="; + if (JavaTokenType.NE == relation) { + relation = JavaTokenType.EQEQ; negated = !negated; } - else if ("<".equals(relation)) { - relation = ">="; + else if (JavaTokenType.LT == relation) { + relation = JavaTokenType.GE; negated = !negated; } - else if ("<=".equals(relation)) { - relation = ">"; + else if (JavaTokenType.LE == relation) { + relation = JavaTokenType.GT; negated = !negated; } @@ -112,18 +114,18 @@ public class DfaRelationValue extends DfaValue { return result; } - private static String getSymmetricOperation(String sign) { - if ("<".equals(sign)) { - return ">"; + private static IElementType getSymmetricOperation(IElementType sign) { + if (JavaTokenType.LT == sign) { + return JavaTokenType.GT; } - else if (">=".equals(sign)) { - return "<="; + else if (JavaTokenType.GE == sign) { + return JavaTokenType.LE; } - else if (">".equals(sign)) { - return "<"; + else if (JavaTokenType.GT == sign) { + return JavaTokenType.LT; } - else if ("<=".equals(sign)) { - return ">="; + else if (JavaTokenType.LE == sign) { + return JavaTokenType.GE; } return sign; @@ -134,7 +136,7 @@ public class DfaRelationValue extends DfaValue { super(factory); } - private DfaRelationValue(DfaValue myLeftOperand, DfaValue myRightOperand, String myRelation, boolean myIsNegated, + private DfaRelationValue(DfaValue myLeftOperand, DfaValue myRightOperand, IElementType myRelation, boolean myIsNegated, DfaValueFactory factory) { super(factory); this.myLeftOperand = myLeftOperand; @@ -161,9 +163,9 @@ public class DfaRelationValue extends DfaValue { private boolean hardEquals(DfaRelationValue rel) { return Comparing.equal(rel.myLeftOperand,myLeftOperand) - && Comparing.equal(rel.myRightOperand,myRightOperand) && - rel.myRelation.equals(myRelation) && - rel.myIsNegated == myIsNegated; + && Comparing.equal(rel.myRightOperand,myRightOperand) && + rel.myRelation == myRelation && + rel.myIsNegated == myIsNegated; } @NonNls public String toString() { diff --git a/java/java-impl/src/com/intellij/lang/java/parser/ExpressionParser.java b/java/java-impl/src/com/intellij/lang/java/parser/ExpressionParser.java index ee6cb3bac458..8c8642e46870 100644 --- a/java/java-impl/src/com/intellij/lang/java/parser/ExpressionParser.java +++ b/java/java-impl/src/com/intellij/lang/java/parser/ExpressionParser.java @@ -171,28 +171,34 @@ public class ExpressionParser { @Nullable private static PsiBuilder.Marker parseBinary(final PsiBuilder builder, final ExprType type, final TokenSet ops) { - PsiBuilder.Marker left = parseExpression(builder, type); - if (left == null) return null; + PsiBuilder.Marker result = parseExpression(builder, type); + if (result == null) return null; + int operandCount = 1; + IElementType tokenType = getGtTokenType(builder); + IElementType currentExprTokenType = tokenType; while (true) { - final IElementType tokenType = getGtTokenType(builder); if (tokenType == null || !ops.contains(tokenType)) break; - final PsiBuilder.Marker binary = left.precede(); advanceGtToken(builder, tokenType); final PsiBuilder.Marker right = parseExpression(builder, type); - if (right == null) { - error(builder, JavaErrorMessages.message("expected.expression")); - binary.done(JavaElementType.BINARY_EXPRESSION); - return binary; + operandCount++; + tokenType = getGtTokenType(builder); + if (tokenType == null || !ops.contains(tokenType) || tokenType != currentExprTokenType || right == null) { + // save + result = result.precede(); + if (right == null) { + error(builder, JavaErrorMessages.message("expected.expression")); + } + result.done(operandCount > 2 ? JavaElementType.POLYADIC_EXPRESSION : JavaElementType.BINARY_EXPRESSION); + if (right == null) break; + currentExprTokenType = tokenType; + operandCount = 1; } - - binary.done(JavaElementType.BINARY_EXPRESSION); - left = binary; } - return left; + return result; } @Nullable diff --git a/java/java-impl/src/com/intellij/psi/NonClasspathClassFinder.java b/java/java-impl/src/com/intellij/psi/NonClasspathClassFinder.java index dd60aefb5a3e..74c154d87d24 100644 --- a/java/java-impl/src/com/intellij/psi/NonClasspathClassFinder.java +++ b/java/java-impl/src/com/intellij/psi/NonClasspathClassFinder.java @@ -41,14 +41,16 @@ public abstract class NonClasspathClassFinder extends PsiElementFinder { private final AtomicLong myLastStamp = new AtomicLong(); protected final Project myProject; private volatile List myCache; + private final PsiManager myManager; public NonClasspathClassFinder(Project project) { myProject = project; + myManager = PsiManager.getInstance(myProject); } protected List getClassRoots() { List cache = myCache; - long stamp = PsiManager.getInstance(myProject).getModificationTracker().getModificationCount(); + long stamp = myManager.getModificationTracker().getModificationCount(); if (myLastStamp.get() != stamp) { cache = null; } @@ -84,7 +86,7 @@ public abstract class NonClasspathClassFinder extends PsiElementFinder { LOG.error("Invalid child of valid parent: " + classFile.getPath() + "; " + classRoot.isValid() + " path=" + classRoot.getPath()); return null; } - final PsiFile file = PsiManager.getInstance(myProject).findFile(classFile); + final PsiFile file = myManager.findFile(classFile); if (file instanceof PsiClassOwner) { final PsiClass[] classes = ((PsiClassOwner)file).getClasses(); if (classes.length == 1) { @@ -115,7 +117,7 @@ public abstract class NonClasspathClassFinder extends PsiElementFinder { if (dir != null && dir.isDirectory()) { for (final VirtualFile file : dir.getChildren()) { if (!file.isDirectory()) { - final PsiFile psi = PsiManager.getInstance(myProject).findFile(file); + final PsiFile psi = myManager.findFile(file); if (psi instanceof PsiClassOwner) { ContainerUtil.addAll(result, ((PsiClassOwner)psi).getClasses()); } @@ -169,7 +171,7 @@ public abstract class NonClasspathClassFinder extends PsiElementFinder { } private PsiPackageImpl createPackage(String qualifiedName) { - return new PsiPackageImpl((PsiManagerEx)PsiManager.getInstance(myProject), qualifiedName); + return new PsiPackageImpl((PsiManagerEx)myManager, qualifiedName); } @Override diff --git a/java/java-impl/src/com/intellij/psi/controlFlow/ControlFlowAnalyzer.java b/java/java-impl/src/com/intellij/psi/controlFlow/ControlFlowAnalyzer.java index 858707bacaf9..65985651c7e8 100644 --- a/java/java-impl/src/com/intellij/psi/controlFlow/ControlFlowAnalyzer.java +++ b/java/java-impl/src/com/intellij/psi/controlFlow/ControlFlowAnalyzer.java @@ -1278,7 +1278,7 @@ class ControlFlowAnalyzer extends JavaJspElementVisitor { if (myAssignmentTargetsAreElements) startElement(lExpr); - if (expression.getOperationSign().getTokenType() != JavaTokenType.EQ) { + if (expression.getOperationTokenType() != JavaTokenType.EQ) { generateReadInstruction(variable); } generateWriteInstruction(variable); @@ -1301,58 +1301,71 @@ class ControlFlowAnalyzer extends JavaJspElementVisitor { finishElement(expression); } - @Override public void visitBinaryExpression(PsiBinaryExpression expression) { - startElement(expression); + private static enum Shortcut { + NO_SHORTCUT, // a || b + SKIP_CURRENT_OPERAND, // false || a + STOP_EXPRESSION // true || a + } - final PsiExpression lOperand = expression.getLOperand(); - final PsiExpression rOperand = expression.getROperand(); + @Override + public void visitPolyadicExpression(PsiPolyadicExpression expression) { + startElement(expression); IElementType signTokenType = expression.getOperationTokenType(); boolean isAndAnd = signTokenType == JavaTokenType.ANDAND; boolean isOrOr = signTokenType == JavaTokenType.OROR; - if ((isAndAnd || isOrOr) && myEnabledShortCircuit) { - Object exprValue = myConstantEvaluationHelper.computeConstantExpression(lOperand); - Boolean lvalue = null; - if (exprValue instanceof Boolean) { - myCurrentFlow.setConstantConditionOccurred(true); - lvalue = shouldCalculateConstantExpression(expression) ? (Boolean)exprValue : null; - } - exprValue = myConstantEvaluationHelper.computeConstantExpression(rOperand); - Boolean rvalue = null; - if (exprValue instanceof Boolean) { - myCurrentFlow.setConstantConditionOccurred(true); - rvalue = shouldCalculateConstantExpression(expression) ? (Boolean)exprValue : null; - } - Boolean doShortcut; - if (lvalue != null) { - doShortcut = lvalue.booleanValue() != isAndAnd; - } - else if (rvalue != null && rvalue.booleanValue() != isAndAnd) { - doShortcut = Boolean.TRUE; - } - else { - doShortcut = null; - } - - generateLOperand(lOperand, rOperand, signTokenType); - BranchingInstruction.Role role = isAndAnd ? myEndJumpRoles.peek() : myStartJumpRoles.peek(); - PsiElement gotoElement = isAndAnd ? myEndStatementStack.peekElement() : myStartStatementStack.peekElement(); - boolean gotoIsAtStart = isAndAnd ? myEndStatementStack.peekAtStart() : myStartStatementStack.peekAtStart(); - if (doShortcut == null) { - myCurrentFlow.addInstruction(new ConditionalGoToInstruction(0, role, lOperand)); - addElementOffsetLater(gotoElement, gotoIsAtStart); - } - else if (doShortcut.booleanValue()) { - myCurrentFlow.addInstruction(new GoToInstruction(0, role)); - addElementOffsetLater(gotoElement, gotoIsAtStart); - } - } - else { - generateLOperand(lOperand, rOperand, signTokenType); - } - if (rOperand != null) { - rOperand.accept(this); + PsiExpression[] operands = expression.getOperands(); + Boolean lValue = isAndAnd; + PsiExpression lOperand = null; + Boolean rValue = null; + for (int i = 0; i < operands.length; i++) { + PsiExpression rOperand = operands[i]; + if ((isAndAnd || isOrOr) && myEnabledShortCircuit) { + Object exprValue = myConstantEvaluationHelper.computeConstantExpression(rOperand); + if (exprValue instanceof Boolean) { + myCurrentFlow.setConstantConditionOccurred(true); + rValue = shouldCalculateConstantExpression(expression) ? (Boolean)exprValue : null; + } + + BranchingInstruction.Role role = isAndAnd ? myEndJumpRoles.peek() : myStartJumpRoles.peek(); + PsiElement gotoElement = isAndAnd ? myEndStatementStack.peekElement() : myStartStatementStack.peekElement(); + boolean gotoIsAtStart = isAndAnd ? myEndStatementStack.peekAtStart() : myStartStatementStack.peekAtStart(); + + Shortcut shortcut; + if (lValue != null) { + shortcut = lValue.booleanValue() == isOrOr ? Shortcut.STOP_EXPRESSION : Shortcut.SKIP_CURRENT_OPERAND; + } + else if (rValue != null && rValue.booleanValue() == isOrOr) { + shortcut = Shortcut.STOP_EXPRESSION; + } + else { + shortcut = Shortcut.NO_SHORTCUT; + } + + switch (shortcut) { + case NO_SHORTCUT: + assert lOperand != null; + myCurrentFlow.addInstruction(new ConditionalGoToInstruction(0, role, lOperand)); + addElementOffsetLater(gotoElement, gotoIsAtStart); + + break; + case STOP_EXPRESSION: + if (lOperand != null) { + myCurrentFlow.addInstruction(new GoToInstruction(0, role)); + addElementOffsetLater(gotoElement, gotoIsAtStart); + } + break; + case SKIP_CURRENT_OPERAND: + break; + } + + if (shortcut == Shortcut.STOP_EXPRESSION) break; + } + generateLOperand(rOperand, i == operands.length-1 ? null : operands[i+1],signTokenType); + + lOperand = rOperand; + lValue = rValue; } finishElement(expression); @@ -1475,7 +1488,7 @@ class ControlFlowAnalyzer extends JavaJspElementVisitor { @Override public void visitPostfixExpression(PsiPostfixExpression expression) { startElement(expression); - IElementType op = expression.getOperationSign().getTokenType(); + IElementType op = expression.getOperationTokenType(); PsiExpression operand = expression.getOperand(); operand.accept(this); if (op == JavaTokenType.PLUSPLUS || op == JavaTokenType.MINUSMINUS) { @@ -1495,7 +1508,7 @@ class ControlFlowAnalyzer extends JavaJspElementVisitor { PsiExpression operand = expression.getOperand(); if (operand != null) { - IElementType operationSign = expression.getOperationSign().getTokenType(); + IElementType operationSign = expression.getOperationTokenType(); if (operationSign == JavaTokenType.EXCL) { // negation inverts jump targets PsiElement topStartStatement = myStartStatementStack.peekElement(); diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java b/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java index 2606eb6d768c..fa7ab1ee9ef0 100644 --- a/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java +++ b/java/java-impl/src/com/intellij/psi/formatter/java/AbstractJavaBlock.java @@ -323,7 +323,8 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo @Nullable protected Alignment createChildAlignment() { - final IElementType nodeType = myNode.getElementType(); + IElementType nodeType = myNode.getElementType(); + if (nodeType == JavaElementType.POLYADIC_EXPRESSION) nodeType = JavaElementType.BINARY_EXPRESSION; if (nodeType == JavaElementType.ASSIGNMENT_EXPRESSION) { if (myNode.getTreeParent() != null && myNode.getTreeParent().getElementType() == JavaElementType.ASSIGNMENT_EXPRESSION @@ -368,7 +369,6 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo else if (nodeType == JavaElementType.MODIFIER_LIST || nodeType == JavaElementType.NEW_EXPRESSION) { return myAlignment; } - else { return null; } @@ -407,10 +407,10 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo } private boolean shouldInheritAlignment() { - if (myNode.getElementType() == JavaElementType.BINARY_EXPRESSION) { + if (myNode instanceof PsiPolyadicExpression) { final ASTNode treeParent = myNode.getTreeParent(); - if (treeParent != null && treeParent.getElementType() == JavaElementType.BINARY_EXPRESSION) { - return FormattingAstUtil.binaryExpressionHasTheSamePriority(myNode, treeParent); + if (treeParent instanceof PsiPolyadicExpression) { + return FormattingAstUtil.areSamePriorityBinaryExpressions(myNode, treeParent); } } return false; @@ -452,7 +452,8 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo arrangeChildAlignment(child, alignmentStrategy))); } else { - final IElementType nodeType = myNode.getElementType(); + IElementType nodeType = myNode.getElementType(); + if (nodeType == JavaElementType.POLYADIC_EXPRESSION) nodeType = JavaElementType.BINARY_EXPRESSION; if (childType == JavaTokenType.LBRACE && nodeType == JavaElementType.ARRAY_INITIALIZER_EXPRESSION) { final Wrap wrap = Wrap.createWrap(getWrapType(mySettings.ARRAY_INITIALIZER_WRAP), false); @@ -524,7 +525,7 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo child = processField(result, child, alignmentStrategy, defaultWrap, childIndent); } else if (childType == JavaElementType.LOCAL_VARIABLE - || (childType == JavaElementType.DECLARATION_STATEMENT && myNode.getElementType() == JavaElementType.METHOD)) + || childType == JavaElementType.DECLARATION_STATEMENT && myNode.getElementType() == JavaElementType.METHOD) { result.add(new SimpleJavaBlock(child, defaultWrap, alignmentStrategy, childIndent, mySettings)); } @@ -545,8 +546,8 @@ public abstract class AbstractJavaBlock extends AbstractBlock implements JavaBlo if (block instanceof AbstractJavaBlock) { final AbstractJavaBlock javaBlock = (AbstractJavaBlock)block; - if ((nodeType == JavaElementType.METHOD_CALL_EXPRESSION && childType == JavaElementType.REFERENCE_EXPRESSION) - || (nodeType == JavaElementType.REFERENCE_EXPRESSION && childType == JavaElementType.METHOD_CALL_EXPRESSION)) + if (nodeType == JavaElementType.METHOD_CALL_EXPRESSION && childType == JavaElementType.REFERENCE_EXPRESSION + || nodeType == JavaElementType.REFERENCE_EXPRESSION && childType == JavaElementType.METHOD_CALL_EXPRESSION) { javaBlock.setReservedWrap(getReservedWrap(nodeType), nodeType); javaBlock.setReservedWrap(getReservedWrap(childType), childType); diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/FormattingAstUtil.java b/java/java-impl/src/com/intellij/psi/formatter/java/FormattingAstUtil.java index 2d7c70271602..b39ab7499d35 100644 --- a/java/java-impl/src/com/intellij/psi/formatter/java/FormattingAstUtil.java +++ b/java/java-impl/src/com/intellij/psi/formatter/java/FormattingAstUtil.java @@ -16,9 +16,8 @@ package com.intellij.psi.formatter.java; import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiBinaryExpression; +import com.intellij.psi.PsiPolyadicExpression; import com.intellij.psi.TokenType; -import com.intellij.psi.impl.source.SourceTreeToPsiMap; import com.intellij.psi.impl.source.tree.JavaElementType; import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; @@ -136,23 +135,23 @@ public class FormattingAstUtil { } /** - * Allows to check if given AST nodes refer to binary expressions and have the same priority. + * Allows to check if given AST nodes refer to binary expressions which have the same priority. * * @param node1 node to check * @param node2 node to check * @return true if given nodes are binary expressions and have the same priority; * false otherwise */ - public static boolean binaryExpressionHasTheSamePriority(ASTNode node1, ASTNode node2) { + public static boolean areSamePriorityBinaryExpressions(ASTNode node1, ASTNode node2) { if (node1 == null || node2 == null) { return false; } - if (node1.getElementType() != JavaElementType.BINARY_EXPRESSION || node2.getElementType() != JavaElementType.BINARY_EXPRESSION) { + if (!(node1 instanceof PsiPolyadicExpression) || !(node2 instanceof PsiPolyadicExpression)) { return false; } - PsiBinaryExpression expression1 = (PsiBinaryExpression)SourceTreeToPsiMap.treeElementToPsi(node1); - PsiBinaryExpression expression2 = (PsiBinaryExpression)SourceTreeToPsiMap.treeElementToPsi(node2); + PsiPolyadicExpression expression1 = (PsiPolyadicExpression)node1; + PsiPolyadicExpression expression2 = (PsiPolyadicExpression)node2; return expression1.getOperationTokenType() == expression2.getOperationTokenType(); } } diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java b/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java index 0f3f7cb93e7b..a20263688e1f 100644 --- a/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java +++ b/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java @@ -889,10 +889,10 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor { } } - @Override public void visitBinaryExpression(PsiBinaryExpression expression) { - PsiJavaToken sign = expression.getOperationSign(); - IElementType i = sign.getTokenType(); + @Override + public void visitPolyadicExpression(PsiPolyadicExpression expression) { if (myRole1 == ChildRole.OPERATION_SIGN || myRole2 == ChildRole.OPERATION_SIGN) { + IElementType i = expression.getOperationTokenType(); if (i == JavaTokenType.OROR || i == JavaTokenType.ANDAND) { createSpaceInCode(mySettings.SPACE_AROUND_LOGICAL_OPERATORS); } diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/wrap/impl/JavaChildBlockWrapFactory.java b/java/java-impl/src/com/intellij/psi/formatter/java/wrap/impl/JavaChildBlockWrapFactory.java index 8bcf0e7d4dfa..31fef7db5ef3 100644 --- a/java/java-impl/src/com/intellij/psi/formatter/java/wrap/impl/JavaChildBlockWrapFactory.java +++ b/java/java-impl/src/com/intellij/psi/formatter/java/wrap/impl/JavaChildBlockWrapFactory.java @@ -19,6 +19,7 @@ import com.intellij.formatting.ASTBlock; import com.intellij.formatting.Wrap; import com.intellij.formatting.WrapType; import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiPolyadicExpression; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.formatter.java.FormattingAstUtil; import com.intellij.psi.formatter.java.wrap.ReservedWrapsProvider; @@ -55,17 +56,17 @@ public class JavaChildBlockWrapFactory { if (nodeType == JavaElementType.EXTENDS_LIST || nodeType == JavaElementType.IMPLEMENTS_LIST) { return Wrap.createWrap(settings.EXTENDS_LIST_WRAP, false); } - else if (nodeType == JavaElementType.BINARY_EXPRESSION) { + else if (node instanceof PsiPolyadicExpression) { Wrap actualWrap = wrap != null ? wrap : reservedWrapsProvider.getReservedWrap(JavaElementType.BINARY_EXPRESSION); if (actualWrap == null) { return Wrap.createWrap(settings.BINARY_OPERATION_WRAP, false); } else { - if (!FormattingAstUtil.binaryExpressionHasTheSamePriority(node, node.getTreeParent())) { - return Wrap.createChildWrap(actualWrap, WrapType.byLegacyRepresentation(settings.BINARY_OPERATION_WRAP), false); + if (FormattingAstUtil.areSamePriorityBinaryExpressions(node, node.getTreeParent())) { + return actualWrap; } else { - return actualWrap; + return Wrap.createChildWrap(actualWrap, WrapType.byLegacyRepresentation(settings.BINARY_OPERATION_WRAP), false); } } } diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/wrap/impl/JavaChildWrapArranger.java b/java/java-impl/src/com/intellij/psi/formatter/java/wrap/impl/JavaChildWrapArranger.java index c6bd33d4ce1a..2caaf432705c 100644 --- a/java/java-impl/src/com/intellij/psi/formatter/java/wrap/impl/JavaChildWrapArranger.java +++ b/java/java-impl/src/com/intellij/psi/formatter/java/wrap/impl/JavaChildWrapArranger.java @@ -19,6 +19,7 @@ import com.intellij.formatting.Wrap; import com.intellij.formatting.WrapType; import com.intellij.lang.ASTNode; import com.intellij.psi.JavaTokenType; +import com.intellij.psi.PsiPolyadicExpression; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.formatter.java.FormattingAstUtil; import com.intellij.psi.formatter.java.wrap.JavaWrapManager; @@ -27,6 +28,7 @@ import com.intellij.psi.impl.source.tree.ChildRole; import com.intellij.psi.impl.source.tree.CompositeElement; import com.intellij.psi.impl.source.tree.JavaElementType; import com.intellij.psi.tree.IElementType; +import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.Nullable; /** @@ -61,15 +63,14 @@ public class JavaChildWrapArranger { */ @SuppressWarnings({"MethodMayBeStatic"}) @Nullable - public Wrap arrange(ASTNode child, ASTNode parent, CodeStyleSettings settings, Wrap suggestedWrap, - ReservedWrapsProvider reservedWrapsProvider) - { - final ASTNode directParent = child.getTreeParent(); + public Wrap arrange(ASTNode child, ASTNode parent, CodeStyleSettings settings, Wrap suggestedWrap, ReservedWrapsProvider reservedWrapsProvider) { + ASTNode directParent = child.getTreeParent(); int role = ((CompositeElement)directParent).getChildRole(child); final IElementType nodeType = parent.getElementType(); - if (nodeType == JavaElementType.BINARY_EXPRESSION) { + if (parent instanceof PsiPolyadicExpression) { if (role == ChildRole.OPERATION_SIGN && !settings.BINARY_OPERATION_SIGN_ON_NEXT_LINE) return null; - if (role == ChildRole.ROPERAND && settings.BINARY_OPERATION_SIGN_ON_NEXT_LINE) return null; + boolean rOperand = ArrayUtil.indexOf(((PsiPolyadicExpression)parent).getOperands(), child.getPsi()) > 0; + if (settings.BINARY_OPERATION_SIGN_ON_NEXT_LINE && rOperand) return null; return suggestedWrap; } final IElementType childType = child.getElementType(); diff --git a/java/java-impl/src/com/intellij/psi/impl/ConstantExpressionVisitor.java b/java/java-impl/src/com/intellij/psi/impl/ConstantExpressionVisitor.java index 6555f82162c2..60fadca3a733 100644 --- a/java/java-impl/src/com/intellij/psi/impl/ConstantExpressionVisitor.java +++ b/java/java-impl/src/com/intellij/psi/impl/ConstantExpressionVisitor.java @@ -105,26 +105,39 @@ class ConstantExpressionVisitor extends JavaElementVisitor implements PsiConstan } @Override - public void visitBinaryExpression(PsiBinaryExpression expression) { - Object lOperandValue = getStoredValue(expression.getLOperand()); - if (lOperandValue == null) { + public void visitPolyadicExpression(PsiPolyadicExpression expression) { + PsiExpression[] operands = expression.getOperands(); + Object lValue = getStoredValue(operands[0]); + if (lValue == null) { myResult = null; return; } - - Object rOperandValue = getStoredValue(expression.getROperand()); - if (rOperandValue == null) { - myResult = null; - return; + IElementType tokenType = expression.getOperationTokenType(); + for (int i = 1; i < operands.length; i++) { + PsiExpression operand = operands[i]; + Object rValue = getStoredValue(operand); + if (rValue == null) { + myResult = null; + break; + } + myResult = compute(lValue, rValue, tokenType, expression); + if (myResult == null) { + break; + } + lValue = myResult; } + if (myResult instanceof String) { + myResult = myInterner.intern((String)myResult); + } + } - PsiJavaToken operationSign = expression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); - + private Object compute(Object lOperandValue, Object rOperandValue, IElementType tokenType, PsiElement expression) { Object value = null; if (tokenType == JavaTokenType.PLUS) { if (lOperandValue instanceof String || rOperandValue instanceof String) { - value = myInterner.intern(lOperandValue.toString() + rOperandValue.toString()); + String l = lOperandValue.toString(); + String r = rOperandValue.toString(); + value = l + r; } else { if (lOperandValue instanceof Character) lOperandValue = Integer.valueOf(((Character)lOperandValue).charValue()); @@ -182,27 +195,23 @@ class ConstantExpressionVisitor extends JavaElementVisitor implements PsiConstan } else if (tokenType == JavaTokenType.ANDAND) { if (lOperandValue instanceof Boolean && !((Boolean)lOperandValue).booleanValue()) { - myResult = Boolean.FALSE; - return; + value = Boolean.FALSE; } - if (rOperandValue instanceof Boolean && !((Boolean)rOperandValue).booleanValue()) { - myResult = Boolean.FALSE; - return; + else if (rOperandValue instanceof Boolean && !((Boolean)rOperandValue).booleanValue()) { + value = Boolean.FALSE; } - if (lOperandValue instanceof Boolean && rOperandValue instanceof Boolean) { + else if (lOperandValue instanceof Boolean && rOperandValue instanceof Boolean) { value = Boolean.valueOf(((Boolean)lOperandValue).booleanValue() && ((Boolean)rOperandValue).booleanValue()); } } else if (tokenType == JavaTokenType.OROR) { if (lOperandValue instanceof Boolean && ((Boolean)lOperandValue).booleanValue()) { - myResult = Boolean.TRUE; - return; + value = Boolean.TRUE; } - if (rOperandValue instanceof Boolean && ((Boolean)rOperandValue).booleanValue()) { - myResult = Boolean.TRUE; - return; + else if (rOperandValue instanceof Boolean && ((Boolean)rOperandValue).booleanValue()) { + value = Boolean.TRUE; } - if (lOperandValue instanceof Boolean && rOperandValue instanceof Boolean) { + else if (lOperandValue instanceof Boolean && rOperandValue instanceof Boolean) { value = Boolean.valueOf(((Boolean)lOperandValue).booleanValue() || ((Boolean)rOperandValue).booleanValue()); } } @@ -421,8 +430,7 @@ class ConstantExpressionVisitor extends JavaElementVisitor implements PsiConstan value = Boolean.valueOf(((Boolean)lOperandValue).booleanValue() ^ ((Boolean)rOperandValue).booleanValue()); } } - - myResult = value; + return value; } @Override public void visitPrefixExpression(PsiPrefixExpression expression) { @@ -432,7 +440,7 @@ class ConstantExpressionVisitor extends JavaElementVisitor implements PsiConstan myResult = null; return; } - IElementType tokenType = expression.getOperationSign().getTokenType(); + IElementType tokenType = expression.getOperationTokenType(); Object value = null; if (tokenType == JavaTokenType.MINUS) { if (operandValue instanceof Character) operandValue = Integer.valueOf(((Character)operandValue).charValue()); @@ -543,13 +551,13 @@ class ConstantExpressionVisitor extends JavaElementVisitor implements PsiConstan return o instanceof Long || o instanceof Integer || o instanceof Short || o instanceof Byte || o instanceof Character; } - private void checkDivisionOverflow(long l, final long r, long minValue, PsiBinaryExpression expression) { + private void checkDivisionOverflow(long l, final long r, long minValue, PsiElement expression) { if (!myThrowExceptionOnOverflow) return; if (r == 0) throw new ConstantEvaluationOverflowException(expression); if (r == -1 && l == minValue) throw new ConstantEvaluationOverflowException(expression); } - private void checkMultiplicationOverflow(long result, long l, long r, PsiExpression expression) { + private void checkMultiplicationOverflow(long result, long l, long r, PsiElement expression) { if (!myThrowExceptionOnOverflow) return; if (r == 0 || l == 0) return; if (result / r != l || ((l < 0) ^ (r < 0) != (result < 0))) throw new ConstantEvaluationOverflowException(expression); @@ -557,7 +565,7 @@ class ConstantExpressionVisitor extends JavaElementVisitor implements PsiConstan private void checkAdditionOverflow(boolean resultPositive, boolean lPositive, - boolean rPositive, PsiBinaryExpression expression) { + boolean rPositive, PsiElement expression) { if (!myThrowExceptionOnOverflow) return; boolean overflow = lPositive == rPositive && lPositive != resultPositive; if (overflow) throw new ConstantEvaluationOverflowException(expression); @@ -565,7 +573,7 @@ class ConstantExpressionVisitor extends JavaElementVisitor implements PsiConstan private void checkRealNumberOverflow(Object result, Object lOperandValue, - Object rOperandValue, PsiExpression expression) { + Object rOperandValue, PsiElement expression) { if (!myThrowExceptionOnOverflow) return; if (lOperandValue instanceof Float && ((Float) lOperandValue).isInfinite()) return; if (lOperandValue instanceof Double && ((Double) lOperandValue).isInfinite()) return; diff --git a/java/java-impl/src/com/intellij/psi/impl/compiled/ClsBinaryExpressionImpl.java b/java/java-impl/src/com/intellij/psi/impl/compiled/ClsBinaryExpressionImpl.java index 92c3e9b56653..929d8e787302 100644 --- a/java/java-impl/src/com/intellij/psi/impl/compiled/ClsBinaryExpressionImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/compiled/ClsBinaryExpressionImpl.java @@ -114,6 +114,11 @@ public class ClsBinaryExpressionImpl extends ClsElementImpl implements PsiBinary return myOperation.getTokenType(); } + @Override + public PsiJavaToken getTokenBeforeOperand(@NotNull PsiExpression operand) { + return getOperationSign(); + } + @Override public PsiType getType() { return myLOperand.getType(); @@ -123,4 +128,9 @@ public class ClsBinaryExpressionImpl extends ClsElementImpl implements PsiBinary public String toString() { return "PsiBinaryExpression:" + getText(); } + @NotNull + @Override + public PsiExpression[] getOperands() { + return new PsiExpression[]{getLOperand(), getROperand()}; + } } diff --git a/java/java-impl/src/com/intellij/psi/impl/source/JavaFileStubBuilder.java b/java/java-impl/src/com/intellij/psi/impl/source/JavaFileStubBuilder.java index 5e63fe652986..376e8823634b 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/JavaFileStubBuilder.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/JavaFileStubBuilder.java @@ -25,6 +25,7 @@ import com.intellij.psi.stubs.DefaultStubBuilder; import com.intellij.psi.stubs.StubElement; import com.intellij.psi.tree.IElementType; import com.intellij.util.io.StringRef; +import org.jetbrains.annotations.NotNull; /** * @author max @@ -34,7 +35,7 @@ public class JavaFileStubBuilder extends DefaultStubBuilder { private static final StubBuilder LIGHT_BUILDER = new JavaLightStubBuilder(); @Override - protected StubElement createStubForFile(final PsiFile file) { + protected StubElement createStubForFile(@NotNull final PsiFile file) { if (file instanceof PsiJavaFile) { final PsiJavaFile javaFile = (PsiJavaFile)file; return new PsiJavaFileStubImpl(javaFile, StringRef.fromString(javaFile.getPackageName()), false); @@ -44,7 +45,7 @@ public class JavaFileStubBuilder extends DefaultStubBuilder { } @Override - protected boolean skipChildProcessingWhenBuildingStubs(final PsiElement element, final PsiElement child) { + protected boolean skipChildProcessingWhenBuildingStubs(@NotNull final PsiElement element, @NotNull final PsiElement child) { final ASTNode node = element.getNode(); if (node == null) return false; final ASTNode childNode = child.getNode(); @@ -56,4 +57,4 @@ public class JavaFileStubBuilder extends DefaultStubBuilder { public boolean skipChildProcessingWhenBuildingStubs(final ASTNode parent, final IElementType childType) { return LIGHT_BUILDER.skipChildProcessingWhenBuildingStubs(parent, childType); } -} \ No newline at end of file +} diff --git a/java/java-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java b/java/java-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java index cc16aef88444..a79a5d9381c7 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/resolve/JavaResolveCache.java @@ -24,15 +24,14 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.NotNullLazyKey; -import com.intellij.psi.PsiEllipsisType; import com.intellij.psi.PsiExpression; import com.intellij.psi.PsiType; import com.intellij.psi.PsiVariable; import com.intellij.psi.impl.PsiManagerEx; +import com.intellij.psi.util.TypeConversionUtil; import com.intellij.util.ConcurrencyUtil; import com.intellij.util.Function; import com.intellij.util.containers.ConcurrentWeakHashMap; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -56,16 +55,6 @@ public class JavaResolveCache { private final Map myVarToConstValueMap2; private static final Object NULL = Key.create("NULL"); - public static final PsiType NULL_TYPE = new PsiEllipsisType(PsiType.NULL){ - public boolean isValid() { - return true; - } - - @NonNls - public String getPresentableText() { - return "FAKE TYPE"; - } - }; public JavaResolveCache(PsiManagerEx manager) { ResolveCache cache = manager.getResolveCache(); @@ -93,7 +82,7 @@ public class JavaResolveCache { if (type == null) { type = f.fun(expr); if (type == null) { - type = NULL_TYPE; + type = TypeConversionUtil.NULL_TYPE; } type = ConcurrencyUtil.cacheOrGet(myCalculatedTypes, expr, type); } @@ -105,7 +94,7 @@ public class JavaResolveCache { LOG.error("Expression: '"+expr+"' is invalid, must not be used for getType()"); } } - return type == NULL_TYPE ? null : type; + return type == TypeConversionUtil.NULL_TYPE ? null : type; } @Nullable diff --git a/java/java-impl/src/com/intellij/psi/impl/source/tree/ElementType.java b/java/java-impl/src/com/intellij/psi/impl/source/tree/ElementType.java index 2a6fd9d6af5f..94ad273d8bd3 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/tree/ElementType.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/tree/ElementType.java @@ -53,7 +53,7 @@ public interface ElementType extends JavaTokenType, JavaDocTokenType, TokenSet EXPRESSION_BIT_SET = TokenSet.create( REFERENCE_EXPRESSION, LITERAL_EXPRESSION, THIS_EXPRESSION, SUPER_EXPRESSION, PARENTH_EXPRESSION, METHOD_CALL_EXPRESSION, - TYPE_CAST_EXPRESSION, PREFIX_EXPRESSION, POSTFIX_EXPRESSION, BINARY_EXPRESSION, CONDITIONAL_EXPRESSION, ASSIGNMENT_EXPRESSION, + TYPE_CAST_EXPRESSION, PREFIX_EXPRESSION, POSTFIX_EXPRESSION, BINARY_EXPRESSION, POLYADIC_EXPRESSION, CONDITIONAL_EXPRESSION, ASSIGNMENT_EXPRESSION, NEW_EXPRESSION, ARRAY_ACCESS_EXPRESSION, ARRAY_INITIALIZER_EXPRESSION, INSTANCE_OF_EXPRESSION, CLASS_OBJECT_ACCESS_EXPRESSION, EMPTY_EXPRESSION); @@ -62,7 +62,7 @@ public interface ElementType extends JavaTokenType, JavaDocTokenType, TokenSet ARRAY_DIMENSION_BIT_SET = TokenSet.create( REFERENCE_EXPRESSION, LITERAL_EXPRESSION, THIS_EXPRESSION, SUPER_EXPRESSION, PARENTH_EXPRESSION, METHOD_CALL_EXPRESSION, - TYPE_CAST_EXPRESSION, PREFIX_EXPRESSION, POSTFIX_EXPRESSION, BINARY_EXPRESSION, CONDITIONAL_EXPRESSION, ASSIGNMENT_EXPRESSION, + TYPE_CAST_EXPRESSION, PREFIX_EXPRESSION, POSTFIX_EXPRESSION, BINARY_EXPRESSION, POLYADIC_EXPRESSION, CONDITIONAL_EXPRESSION, ASSIGNMENT_EXPRESSION, NEW_EXPRESSION, ARRAY_ACCESS_EXPRESSION, INSTANCE_OF_EXPRESSION, CLASS_OBJECT_ACCESS_EXPRESSION, EMPTY_EXPRESSION); TokenSet JAVA_STATEMENT_BIT_SET = TokenSet.create( diff --git a/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java b/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java index 9060dfdc225e..2e86b41548dd 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/tree/JavaElementType.java @@ -98,6 +98,7 @@ public interface JavaElementType { IElementType PREFIX_EXPRESSION = new JavaCompositeElementType("PREFIX_EXPRESSION", PsiPrefixExpressionImpl.class); IElementType POSTFIX_EXPRESSION = new JavaCompositeElementType("POSTFIX_EXPRESSION", PsiPostfixExpressionImpl.class); IElementType BINARY_EXPRESSION = new JavaCompositeElementType("BINARY_EXPRESSION", PsiBinaryExpressionImpl.class); + IElementType POLYADIC_EXPRESSION = new JavaCompositeElementType("POLYADIC_EXPRESSION", PsiPolyadicExpressionImpl.class); IElementType CONDITIONAL_EXPRESSION = new JavaCompositeElementType("CONDITIONAL_EXPRESSION", PsiConditionalExpressionImpl.class); IElementType ASSIGNMENT_EXPRESSION = new JavaCompositeElementType("ASSIGNMENT_EXPRESSION", PsiAssignmentExpressionImpl.class); IElementType NEW_EXPRESSION = new JavaCompositeElementType("NEW_EXPRESSION", PsiNewExpressionImpl.class); diff --git a/java/java-impl/src/com/intellij/psi/impl/source/tree/injected/JavaConcatenationInjectorManager.java b/java/java-impl/src/com/intellij/psi/impl/source/tree/injected/JavaConcatenationInjectorManager.java index ca0416a603e1..8c53cbb84aa6 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/tree/injected/JavaConcatenationInjectorManager.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/tree/injected/JavaConcatenationInjectorManager.java @@ -74,8 +74,8 @@ public class JavaConcatenationInjectorManager implements ModificationTracker { public CachedValueProvider.Result compute(PsiElement context) { PsiElement element = context; PsiElement parent = context.getParent(); - while (parent instanceof PsiBinaryExpression && ((PsiBinaryExpression)parent).getOperationSign().getTokenType() == JavaTokenType.PLUS - || parent instanceof PsiAssignmentExpression && ((PsiAssignmentExpression)parent).getOperationSign().getTokenType() == JavaTokenType.PLUSEQ + while (parent instanceof PsiPolyadicExpression && ((PsiPolyadicExpression)parent).getOperationTokenType() == JavaTokenType.PLUS + || parent instanceof PsiAssignmentExpression && ((PsiAssignmentExpression)parent).getOperationTokenType() == JavaTokenType.PLUSEQ || parent instanceof PsiConditionalExpression && ((PsiConditionalExpression)parent).getCondition() != element || parent instanceof PsiTypeCastExpression || parent instanceof PsiParenthesizedExpression) { @@ -85,9 +85,9 @@ public class JavaConcatenationInjectorManager implements ModificationTracker { PsiElement[] operands; PsiElement anchor; - if (element instanceof PsiBinaryExpression || element instanceof PsiAssignmentExpression) { + if (element instanceof PsiPolyadicExpression || element instanceof PsiAssignmentExpression) { List operandList = new ArrayList(); - collectOperands(element, operandList); + collectOperands((PsiExpression)element, operandList); operands = PsiUtilBase.toPsiElementArray(operandList); anchor = element; } @@ -105,18 +105,22 @@ public class JavaConcatenationInjectorManager implements ModificationTracker { CachedValueProvider.Result result = CachedValueProvider.Result.create(registrar, PsiModificationTracker.MODIFICATION_COUNT, concatenationInjectorManager); + ParameterizedCachedValue cachedValue; if (registrar.result != null) { // store this everywhere - ParameterizedCachedValue cachedValue = - CachedValuesManager.getManager(context.getProject()).createParameterizedCachedValue(this, false); + cachedValue = CachedValuesManager.getManager(context.getProject()).createParameterizedCachedValue(this, false); ((PsiParameterizedCachedValue)cachedValue).setValue(result); - for (PsiElement operand : operands) { - operand.putUserData(INJECTED_PSI_IN_CONCATENATION, cachedValue); - } - anchor.putUserData(INJECTED_PSI_IN_CONCATENATION, cachedValue); - context.putUserData(INJECTED_PSI_IN_CONCATENATION, cachedValue); } + else { + cachedValue = InjectedLanguageUtil.NULL_VALUE; + } + for (PsiElement operand : operands) { + operand.putUserData(INJECTED_PSI_IN_CONCATENATION, cachedValue); + } + anchor.putUserData(INJECTED_PSI_IN_CONCATENATION, cachedValue); + context.putUserData(INJECTED_PSI_IN_CONCATENATION, cachedValue); + return result; } @@ -156,15 +160,28 @@ public class JavaConcatenationInjectorManager implements ModificationTracker { } } - private static void collectOperands(PsiElement expression, List operands) { - if (expression instanceof PsiBinaryExpression) { - final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression; - collectOperands(binaryExpression.getLOperand(), operands); - collectOperands(binaryExpression.getROperand(), operands); - } - else if (expression != null) { - operands.add(expression); - } + private static void collectOperands(PsiExpression expression, final List operands) { + expression.accept(new JavaRecursiveElementWalkingVisitor() { + @Override + public void visitPolyadicExpression(PsiPolyadicExpression expression) { + super.visitElement(expression); + } + + @Override + public void visitExpression(PsiExpression expression) { + operands.add(expression); // add leaf expression to the operand list + } + + @Override + public void visitReferenceExpression(PsiReferenceExpression expression) { + visitExpression(expression); + } + + @Override + public void visitElement(PsiElement element) { + // do not go deeper + } + }); } private final List myConcatenationInjectors = ContainerUtil.createEmptyCOWList(); diff --git a/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiBinaryExpressionImpl.java b/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiBinaryExpressionImpl.java index 934fb03dd616..beab7d3daa1c 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiBinaryExpressionImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiBinaryExpressionImpl.java @@ -29,13 +29,15 @@ import com.intellij.psi.tree.TokenSet; import com.intellij.psi.util.TypeConversionUtil; import com.intellij.util.Function; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public class PsiBinaryExpressionImpl extends ExpressionPsiElement implements PsiBinaryExpression { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.PsiBinaryExpressionImpl"); public PsiBinaryExpressionImpl() { - super(JavaElementType.BINARY_EXPRESSION); + this(JavaElementType.BINARY_EXPRESSION); + } + protected PsiBinaryExpressionImpl(@NotNull IElementType elementType) { + super(elementType); } @NotNull @@ -57,15 +59,20 @@ public class PsiBinaryExpressionImpl extends ExpressionPsiElement implements Psi return getOperationSign().getTokenType(); } + @Override + public PsiJavaToken getTokenBeforeOperand(@NotNull PsiExpression operand) { + return getOperationSign(); + } + private static PsiType doGetType(PsiBinaryExpressionImpl param) { PsiExpression lOperand = param.getLOperand(); PsiExpression rOperand = param.getROperand(); if (rOperand == null) return null; PsiType rType = rOperand.getType(); - IElementType sign = param.getOperationSign().getNode().getElementType(); + IElementType sign = param.getOperationTokenType(); // optimization: if we can calculate type based on right type only - PsiType type = calcTypeForBinaryExpression(null, rType, sign, false); - if (type != JavaResolveCache.NULL_TYPE) return type; + PsiType type = TypeConversionUtil.calcTypeForBinaryExpression(null, rType, sign, false); + if (type != TypeConversionUtil.NULL_TYPE) return type; if (lOperand instanceof PsiBinaryExpressionImpl && !JavaResolveCache.getInstance(param.getProject()).isTypeCached(lOperand)) { // cache all intermediate expression types from bottom up @@ -86,7 +93,7 @@ public class PsiBinaryExpressionImpl extends ExpressionPsiElement implements Psi }); } PsiType lType = lOperand.getType(); - return calcTypeForBinaryExpression(lType, rType, sign, true); + return TypeConversionUtil.calcTypeForBinaryExpression(lType, rType, sign, true); } private static final Function MY_TYPE_EVALUATOR = new Function() { @@ -147,60 +154,11 @@ public class PsiBinaryExpressionImpl extends ExpressionPsiElement implements Psi return "PsiBinaryExpression:" + getText(); } - @Nullable - public static PsiType calcTypeForBinaryExpression(PsiType lType, PsiType rType, IElementType sign, boolean accessLType) { - if (sign == JavaTokenType.PLUS) { - // evaluate right argument first, since '+-/*%' is left associative and left operand tends to be bigger - if (rType == null) return null; - if (rType.equalsToText("java.lang.String")) { - return rType; - } - if (!accessLType) return JavaResolveCache.NULL_TYPE; - if (lType == null) return null; - if (lType.equalsToText("java.lang.String")) { - return lType; - } - return TypeConversionUtil.unboxAndBalanceTypes(lType, rType); - } - if (sign == JavaTokenType.MINUS || sign == JavaTokenType.ASTERISK || sign == JavaTokenType.DIV || sign == JavaTokenType.PERC) { - if (rType == null) return null; - if (!accessLType) return JavaResolveCache.NULL_TYPE; - if (lType == null) return null; - return TypeConversionUtil.unboxAndBalanceTypes(lType, rType); - } - if (sign == JavaTokenType.LTLT || sign == JavaTokenType.GTGT || sign == JavaTokenType.GTGTGT) { - if (!accessLType) return JavaResolveCache.NULL_TYPE; - if (PsiType.BYTE.equals(lType) || PsiType.CHAR.equals(lType) || PsiType.SHORT.equals(lType)) { - return PsiType.INT; - } - if (lType instanceof PsiClassType) lType = PsiPrimitiveType.getUnboxedType(lType); - return lType; - } - if (sign == JavaTokenType.EQEQ || - sign == JavaTokenType.NE || - sign == JavaTokenType.LT || - sign == JavaTokenType.GT || - sign == JavaTokenType.LE || - sign == JavaTokenType.GE || - sign == JavaTokenType.OROR || - sign == JavaTokenType.ANDAND) { - return PsiType.BOOLEAN; - } - if (sign == JavaTokenType.OR || sign == JavaTokenType.XOR || sign == JavaTokenType.AND) { - if (rType instanceof PsiClassType) rType = PsiPrimitiveType.getUnboxedType(rType); - - if (lType instanceof PsiClassType) lType = PsiPrimitiveType.getUnboxedType(lType); - - if (rType == null) return null; - if (PsiType.BOOLEAN.equals(rType)) return PsiType.BOOLEAN; - if (!accessLType) return JavaResolveCache.NULL_TYPE; - if (lType == null) return null; - if (PsiType.BOOLEAN.equals(lType)) return PsiType.BOOLEAN; - if (PsiType.LONG.equals(lType) || PsiType.LONG.equals(rType)) return PsiType.LONG; - return PsiType.INT; - } - LOG.error("Unknown token: "+sign); - return null; + @NotNull + @Override + public PsiExpression[] getOperands() { + PsiExpression rOperand = getROperand(); + return rOperand == null ? new PsiExpression[]{getLOperand()} : new PsiExpression[]{getLOperand(), rOperand}; } } diff --git a/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiPolyadicExpressionImpl.java b/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiPolyadicExpressionImpl.java new file mode 100644 index 000000000000..af90b3a334d8 --- /dev/null +++ b/java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiPolyadicExpressionImpl.java @@ -0,0 +1,127 @@ +/* + * Copyright 2000-2011 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.psi.impl.source.tree.java; + +import com.intellij.lang.ASTNode; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.psi.*; +import com.intellij.psi.impl.source.Constants; +import com.intellij.psi.impl.source.resolve.JavaResolveCache; +import com.intellij.psi.impl.source.tree.ChildRole; +import com.intellij.psi.impl.source.tree.ElementType; +import com.intellij.psi.impl.source.tree.JavaElementType; +import com.intellij.psi.tree.ChildRoleBase; +import com.intellij.psi.tree.IElementType; +import com.intellij.psi.tree.TokenSet; +import com.intellij.psi.util.TypeConversionUtil; +import com.intellij.util.Function; +import org.jetbrains.annotations.NotNull; + +public class PsiPolyadicExpressionImpl extends ExpressionPsiElement implements PsiPolyadicExpression { + private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.PsiPolyadicExpressionImpl"); + + public PsiPolyadicExpressionImpl() { + super(JavaElementType.POLYADIC_EXPRESSION); + } + + @NotNull + public IElementType getOperationTokenType() { + return ((PsiJavaToken)findChildByRoleAsPsiElement(ChildRole.OPERATION_SIGN)).getTokenType(); + } + + @Override + public PsiJavaToken getTokenBeforeOperand(@NotNull PsiExpression operand) { + PsiElement element = operand; + while(element != null) { + if (getChildRole(element.getNode()) == ChildRole.OPERATION_SIGN) return (PsiJavaToken)element; + element = element.getPrevSibling(); + } + return null; + } + + public PsiType getType() { + return JavaResolveCache.getInstance(getProject()).getType(this, MY_TYPE_EVALUATOR); + } + private static final Function MY_TYPE_EVALUATOR = new Function() { + public PsiType fun(PsiPolyadicExpressionImpl expression) { + return doGetType(expression); + } + }; + + private static PsiType doGetType(PsiPolyadicExpressionImpl param) { + PsiExpression[] operands = param.getOperands(); + PsiType lType = null; + + IElementType sign = param.getOperationTokenType(); + for (int i=1; i classMemberRefs) { @@ -138,10 +149,10 @@ public class Util { PsiElement element = reference.getElement(); boolean stillCanBeRemoved = false; if (element != null) { - stillCanBeRemoved = PsiTreeUtil.isAncestor(expr, element, false) || PsiUtil.isInsideJavadocComment(element); + stillCanBeRemoved = isAncestor(expr, element, false) || PsiUtil.isInsideJavadocComment(getPhysical(element)); if (!stillCanBeRemoved && occurences != null) { for (PsiExpression occurence : occurences) { - if (PsiTreeUtil.isAncestor(occurence, element, false)) { + if (isAncestor(occurence, element, false)) { stillCanBeRemoved = true; break; } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java index 7236cb19437f..d77b16db97ab 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java @@ -219,10 +219,9 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase impleme } /** - * @return can return NotNull value thought extraction should fail: reason could be retrieved from {@link #getErrorMessage(PsiExpression)} + * @return can return NotNull value although extraction will fail: reason could be retrieved from {@link #getErrorMessage(PsiExpression)} */ public static PsiExpression getSelectedExpression(final Project project, final PsiFile file, int startOffset, int endOffset) { - PsiElement elementAtStart = file.findElementAt(startOffset); if (elementAtStart == null || elementAtStart instanceof PsiWhiteSpace || elementAtStart instanceof PsiComment) { elementAtStart = PsiTreeUtil.skipSiblingsForward(elementAtStart, PsiWhiteSpace.class, PsiComment.class); diff --git a/java/java-impl/src/com/intellij/refactoring/psi/PropertyUtils.java b/java/java-impl/src/com/intellij/refactoring/psi/PropertyUtils.java index dc1b741c2717..679172ac0ec8 100644 --- a/java/java-impl/src/com/intellij/refactoring/psi/PropertyUtils.java +++ b/java/java-impl/src/com/intellij/refactoring/psi/PropertyUtils.java @@ -148,8 +148,7 @@ public class PropertyUtils { return null; } final PsiAssignmentExpression assignment = (PsiAssignmentExpression)possibleAssignment; - final PsiJavaToken sign = assignment.getOperationSign(); - if (!JavaTokenType.EQ.equals(sign.getTokenType())) { + if (!JavaTokenType.EQ.equals(assignment.getOperationTokenType())) { return null; } final PsiExpression lhs = assignment.getLExpression(); diff --git a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeEvaluator.java b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeEvaluator.java index 86a6aced41c1..ae23a44bef9c 100644 --- a/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeEvaluator.java +++ b/java/java-impl/src/com/intellij/refactoring/typeMigration/TypeEvaluator.java @@ -21,7 +21,6 @@ import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.impl.PsiImplUtil; -import com.intellij.psi.impl.source.tree.java.PsiBinaryExpressionImpl; import com.intellij.psi.util.InheritanceUtil; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; @@ -150,9 +149,9 @@ public class TypeEvaluator { else if (expr instanceof PsiBinaryExpression) { final PsiExpression lOperand = ((PsiBinaryExpression)expr).getLOperand(); final PsiExpression rOperand = ((PsiBinaryExpression)expr).getROperand(); - final PsiJavaToken operationSign = ((PsiBinaryExpression)expr).getOperationSign(); - return PsiBinaryExpressionImpl.calcTypeForBinaryExpression(evaluateType(lOperand), evaluateType(rOperand), operationSign.getTokenType(), - true); + return TypeConversionUtil.calcTypeForBinaryExpression(evaluateType(lOperand), evaluateType(rOperand), + ((PsiBinaryExpression)expr).getOperationTokenType(), + true); } else if (expr instanceof PsiPostfixExpression) { return evaluateType(((PsiPostfixExpression)expr).getOperand()); diff --git a/java/java-impl/src/com/intellij/refactoring/util/ParameterTablePanel.java b/java/java-impl/src/com/intellij/refactoring/util/ParameterTablePanel.java index 9a62af29cda8..b5f68d7b399e 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/ParameterTablePanel.java +++ b/java/java-impl/src/com/intellij/refactoring/util/ParameterTablePanel.java @@ -23,8 +23,8 @@ import com.intellij.refactoring.ui.TypeSelectorManager; import com.intellij.refactoring.ui.TypeSelectorManagerImpl; import com.intellij.ui.BooleanTableCellRenderer; import com.intellij.ui.EditableModel; -import com.intellij.ui.TableToolbarDecorator; import com.intellij.ui.TableUtil; +import com.intellij.ui.ToolbarDecorator; import com.intellij.ui.components.JBComboBoxLabel; import com.intellij.ui.components.editors.JBComboBoxTableCellEditorComponent; import com.intellij.ui.table.JBTable; @@ -252,7 +252,7 @@ public abstract class ParameterTablePanel extends JPanel { }); - JPanel listPanel = TableToolbarDecorator.createDecorator(myTable).disableAddAction().disableRemoveAction().createPanel(); + JPanel listPanel = ToolbarDecorator.createDecorator(myTable).disableAddAction().disableRemoveAction().createPanel(); add(listPanel, BorderLayout.CENTER); if (getVariableData().length > 1) { diff --git a/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java b/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java index db3cac864a2d..21bd51728f26 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/util/RefactoringUtil.java @@ -528,8 +528,8 @@ public class RefactoringUtil { public static boolean isPlusPlusOrMinusMinus(PsiElement element) { if (element instanceof PsiPrefixExpression) { - PsiJavaToken operandSign = ((PsiPrefixExpression)element).getOperationSign(); - return operandSign.getTokenType() == JavaTokenType.PLUSPLUS || operandSign.getTokenType() == JavaTokenType.MINUSMINUS; + return ((PsiPrefixExpression)element).getOperationTokenType() == JavaTokenType.PLUSPLUS || + ((PsiPrefixExpression)element).getOperationTokenType() == JavaTokenType.MINUSMINUS; } else if (element instanceof PsiPostfixExpression) { IElementType operandTokenType = ((PsiPostfixExpression)element).getOperationTokenType(); diff --git a/java/java-tests/testData/codeInsight/completeStatement/CompleteMethodCallAtReturn.java b/java/java-tests/testData/codeInsight/completeStatement/CompleteMethodCallAtReturn.java new file mode 100644 index 000000000000..f22901282204 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completeStatement/CompleteMethodCallAtReturn.java @@ -0,0 +1,7 @@ +public class Foo { + public String foo() { + return String.valueOf( + 1 + ) + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completeStatement/CompleteMethodCallAtReturn_after.java b/java/java-tests/testData/codeInsight/completeStatement/CompleteMethodCallAtReturn_after.java new file mode 100644 index 000000000000..da1db3a40ba7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completeStatement/CompleteMethodCallAtReturn_after.java @@ -0,0 +1,7 @@ +public class Foo { + public String foo() { + return String.valueOf( + 1 + ); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/numericOverflow/simple/expected.xml b/java/java-tests/testData/inspection/numericOverflow/simple/expected.xml index 197b87606e12..78d22bf6d352 100644 --- a/java/java-tests/testData/inspection/numericOverflow/simple/expected.xml +++ b/java/java-tests/testData/inspection/numericOverflow/simple/expected.xml @@ -639,18 +639,12 @@ Foo.java - 73 - + 72 + Numeric overflow in expression - - Foo.java - 73 - - Numeric overflow in expression - diff --git a/java/java-tests/testData/inspection/numericOverflow/simple/src/Foo.java b/java/java-tests/testData/inspection/numericOverflow/simple/src/Foo.java index 153606c89b08..1aed3c6bcf46 100644 --- a/java/java-tests/testData/inspection/numericOverflow/simple/src/Foo.java +++ b/java/java-tests/testData/inspection/numericOverflow/simple/src/Foo.java @@ -69,8 +69,8 @@ class c { l1 = LONG_MIN_VALUE / -1; l1 = 30 * 24 * 60 * 60 * 1000; - l1 = 30000000 * 243232323 - * (LONG_MAX_VALUE +3) / 5; + l1 = 30000000 * 243232323 * (LONG_MAX_VALUE +3) / 5; + System.out.println(l1); diff --git a/java/java-tests/testData/psi/controlFlow/flowAnd2.txt b/java/java-tests/testData/psi/controlFlow/flowAnd2.txt index 3e23cd10adf3..203f5b69b5f5 100644 --- a/java/java-tests/testData/psi/controlFlow/flowAnd2.txt +++ b/java/java-tests/testData/psi/controlFlow/flowAnd2.txt @@ -1,6 +1,6 @@ 0: EMPTY 1: READ file -2: COND_GOTO [END] 9 +2: COND_GOTO [ELSE] 9 3: READ b1 4: COND_GOTO [ELSE] 9 5: READ b2 @@ -9,4 +9,4 @@ 8: GOTO [END] 10 9: WRITE highlighter 10: READ highlighter -11: GOTO [END] 12 RETURN \ No newline at end of file +11: GOTO [END] 12 RETURN diff --git a/java/java-tests/testData/psi/parser-full/expressionParsing/And0.txt b/java/java-tests/testData/psi/parser-full/expressionParsing/And0.txt index 1cd5533086ac..26388a9a9608 100644 --- a/java/java-tests/testData/psi/parser-full/expressionParsing/And0.txt +++ b/java/java-tests/testData/psi/parser-full/expressionParsing/And0.txt @@ -24,19 +24,18 @@ PsiJavaFile:And0.java PsiReturnStatement PsiKeyword:return('return') PsiWhiteSpace(' ') - PsiBinaryExpression:a & b & c - PsiBinaryExpression:a & b - PsiReferenceExpression:a - PsiReferenceParameterList - - PsiIdentifier:a('a') - PsiWhiteSpace(' ') - PsiJavaToken:AND('&') - PsiWhiteSpace(' ') - PsiReferenceExpression:b - PsiReferenceParameterList - - PsiIdentifier:b('b') + PsiPolyadicExpression: a & b & c + PsiReferenceExpression:a + PsiReferenceParameterList + + PsiIdentifier:a('a') + PsiWhiteSpace(' ') + PsiJavaToken:AND('&') + PsiWhiteSpace(' ') + PsiReferenceExpression:b + PsiReferenceParameterList + + PsiIdentifier:b('b') PsiWhiteSpace(' ') PsiJavaToken:AND('&') PsiWhiteSpace(' ') @@ -48,4 +47,4 @@ PsiJavaFile:And0.java PsiWhiteSpace('\n ') PsiJavaToken:RBRACE('}') PsiWhiteSpace('\n') - PsiJavaToken:RBRACE('}') \ No newline at end of file + PsiJavaToken:RBRACE('}') diff --git a/java/java-tests/testData/psi/parser-full/expressionParsing/CondAnd0.txt b/java/java-tests/testData/psi/parser-full/expressionParsing/CondAnd0.txt index f09a0448ecd6..383e71055e40 100644 --- a/java/java-tests/testData/psi/parser-full/expressionParsing/CondAnd0.txt +++ b/java/java-tests/testData/psi/parser-full/expressionParsing/CondAnd0.txt @@ -24,19 +24,18 @@ PsiJavaFile:CondAnd0.java PsiReturnStatement PsiKeyword:return('return') PsiWhiteSpace(' ') - PsiBinaryExpression:a && b && c - PsiBinaryExpression:a && b - PsiReferenceExpression:a - PsiReferenceParameterList - - PsiIdentifier:a('a') - PsiWhiteSpace(' ') - PsiJavaToken:ANDAND('&&') - PsiWhiteSpace(' ') - PsiReferenceExpression:b - PsiReferenceParameterList - - PsiIdentifier:b('b') + PsiPolyadicExpression: a && b && c + PsiReferenceExpression:a + PsiReferenceParameterList + + PsiIdentifier:a('a') + PsiWhiteSpace(' ') + PsiJavaToken:ANDAND('&&') + PsiWhiteSpace(' ') + PsiReferenceExpression:b + PsiReferenceParameterList + + PsiIdentifier:b('b') PsiWhiteSpace(' ') PsiJavaToken:ANDAND('&&') PsiWhiteSpace(' ') @@ -48,4 +47,4 @@ PsiJavaFile:CondAnd0.java PsiWhiteSpace('\n ') PsiJavaToken:RBRACE('}') PsiWhiteSpace('\n') - PsiJavaToken:RBRACE('}') \ No newline at end of file + PsiJavaToken:RBRACE('}') diff --git a/java/java-tests/testData/psi/parser-full/expressionParsing/CondOr0.txt b/java/java-tests/testData/psi/parser-full/expressionParsing/CondOr0.txt index 7bfdcfb60596..926a8bfe4d62 100644 --- a/java/java-tests/testData/psi/parser-full/expressionParsing/CondOr0.txt +++ b/java/java-tests/testData/psi/parser-full/expressionParsing/CondOr0.txt @@ -24,19 +24,18 @@ PsiJavaFile:CondOr0.java PsiReturnStatement PsiKeyword:return('return') PsiWhiteSpace(' ') - PsiBinaryExpression:a || b || c - PsiBinaryExpression:a || b - PsiReferenceExpression:a - PsiReferenceParameterList - - PsiIdentifier:a('a') - PsiWhiteSpace(' ') - PsiJavaToken:OROR('||') - PsiWhiteSpace(' ') - PsiReferenceExpression:b - PsiReferenceParameterList - - PsiIdentifier:b('b') + PsiPolyadicExpression: a || b || c + PsiReferenceExpression:a + PsiReferenceParameterList + + PsiIdentifier:a('a') + PsiWhiteSpace(' ') + PsiJavaToken:OROR('||') + PsiWhiteSpace(' ') + PsiReferenceExpression:b + PsiReferenceParameterList + + PsiIdentifier:b('b') PsiWhiteSpace(' ') PsiJavaToken:OROR('||') PsiWhiteSpace(' ') @@ -48,4 +47,4 @@ PsiJavaFile:CondOr0.java PsiWhiteSpace('\n ') PsiJavaToken:RBRACE('}') PsiWhiteSpace('\n') - PsiJavaToken:RBRACE('}') \ No newline at end of file + PsiJavaToken:RBRACE('}') diff --git a/java/java-tests/testData/psi/parser-full/expressionParsing/Or0.txt b/java/java-tests/testData/psi/parser-full/expressionParsing/Or0.txt index 386ba8fb8ffb..d53ef8a225e1 100644 --- a/java/java-tests/testData/psi/parser-full/expressionParsing/Or0.txt +++ b/java/java-tests/testData/psi/parser-full/expressionParsing/Or0.txt @@ -24,19 +24,18 @@ PsiJavaFile:Or0.java PsiReturnStatement PsiKeyword:return('return') PsiWhiteSpace(' ') - PsiBinaryExpression:a | b | c - PsiBinaryExpression:a | b - PsiReferenceExpression:a - PsiReferenceParameterList - - PsiIdentifier:a('a') - PsiWhiteSpace(' ') - PsiJavaToken:OR('|') - PsiWhiteSpace(' ') - PsiReferenceExpression:b - PsiReferenceParameterList - - PsiIdentifier:b('b') + PsiPolyadicExpression: a | b | c + PsiReferenceExpression:a + PsiReferenceParameterList + + PsiIdentifier:a('a') + PsiWhiteSpace(' ') + PsiJavaToken:OR('|') + PsiWhiteSpace(' ') + PsiReferenceExpression:b + PsiReferenceParameterList + + PsiIdentifier:b('b') PsiWhiteSpace(' ') PsiJavaToken:OR('|') PsiWhiteSpace(' ') @@ -48,4 +47,4 @@ PsiJavaFile:Or0.java PsiWhiteSpace('\n ') PsiJavaToken:RBRACE('}') PsiWhiteSpace('\n') - PsiJavaToken:RBRACE('}') \ No newline at end of file + PsiJavaToken:RBRACE('}') diff --git a/java/java-tests/testData/psi/parser-full/expressionParsing/Xor0.txt b/java/java-tests/testData/psi/parser-full/expressionParsing/Xor0.txt index 04d8e9d6a7e4..bd93036fdfa2 100644 --- a/java/java-tests/testData/psi/parser-full/expressionParsing/Xor0.txt +++ b/java/java-tests/testData/psi/parser-full/expressionParsing/Xor0.txt @@ -24,19 +24,18 @@ PsiJavaFile:Xor0.java PsiReturnStatement PsiKeyword:return('return') PsiWhiteSpace(' ') - PsiBinaryExpression:a ^ b ^ c - PsiBinaryExpression:a ^ b - PsiReferenceExpression:a - PsiReferenceParameterList - - PsiIdentifier:a('a') - PsiWhiteSpace(' ') - PsiJavaToken:XOR('^') - PsiWhiteSpace(' ') - PsiReferenceExpression:b - PsiReferenceParameterList - - PsiIdentifier:b('b') + PsiPolyadicExpression: a ^ b ^ c + PsiReferenceExpression:a + PsiReferenceParameterList + + PsiIdentifier:a('a') + PsiWhiteSpace(' ') + PsiJavaToken:XOR('^') + PsiWhiteSpace(' ') + PsiReferenceExpression:b + PsiReferenceParameterList + + PsiIdentifier:b('b') PsiWhiteSpace(' ') PsiJavaToken:XOR('^') PsiWhiteSpace(' ') @@ -48,4 +47,4 @@ PsiJavaFile:Xor0.java PsiWhiteSpace('\n ') PsiJavaToken:RBRACE('}') PsiWhiteSpace('\n') - PsiJavaToken:RBRACE('}') \ No newline at end of file + PsiJavaToken:RBRACE('}') diff --git a/java/java-tests/testData/psi/parser-partial/expressions/CondOr0.txt b/java/java-tests/testData/psi/parser-partial/expressions/CondOr0.txt index a2405e24d608..45df89dd19ad 100644 --- a/java/java-tests/testData/psi/parser-partial/expressions/CondOr0.txt +++ b/java/java-tests/testData/psi/parser-partial/expressions/CondOr0.txt @@ -1,21 +1,20 @@ PsiJavaFile:CondOr0.java - PsiBinaryExpression:a || b || c - PsiBinaryExpression:a || b - PsiReferenceExpression:a - PsiReferenceParameterList - - PsiIdentifier:a('a') - PsiWhiteSpace(' ') - PsiJavaToken:OROR('||') - PsiWhiteSpace(' ') - PsiReferenceExpression:b - PsiReferenceParameterList - - PsiIdentifier:b('b') + PsiPolyadicExpression: a || b || c + PsiReferenceExpression:a + PsiReferenceParameterList + + PsiIdentifier:a('a') + PsiWhiteSpace(' ') + PsiJavaToken:OROR('||') + PsiWhiteSpace(' ') + PsiReferenceExpression:b + PsiReferenceParameterList + + PsiIdentifier:b('b') PsiWhiteSpace(' ') PsiJavaToken:OROR('||') PsiWhiteSpace(' ') PsiReferenceExpression:c PsiReferenceParameterList - PsiIdentifier:c('c') + PsiIdentifier:c('c') \ No newline at end of file diff --git a/java/java-tests/testData/psi/parser-partial/expressions/Or0.txt b/java/java-tests/testData/psi/parser-partial/expressions/Or0.txt index 20bd74839bdd..56cf4e01ead1 100644 --- a/java/java-tests/testData/psi/parser-partial/expressions/Or0.txt +++ b/java/java-tests/testData/psi/parser-partial/expressions/Or0.txt @@ -1,21 +1,20 @@ PsiJavaFile:Or0.java - PsiBinaryExpression:a | b | c - PsiBinaryExpression:a | b - PsiReferenceExpression:a - PsiReferenceParameterList - - PsiIdentifier:a('a') - PsiWhiteSpace(' ') - PsiJavaToken:OR('|') - PsiWhiteSpace(' ') - PsiReferenceExpression:b - PsiReferenceParameterList - - PsiIdentifier:b('b') + PsiPolyadicExpression: a | b | c + PsiReferenceExpression:a + PsiReferenceParameterList + + PsiIdentifier:a('a') + PsiWhiteSpace(' ') + PsiJavaToken:OR('|') + PsiWhiteSpace(' ') + PsiReferenceExpression:b + PsiReferenceParameterList + + PsiIdentifier:b('b') PsiWhiteSpace(' ') PsiJavaToken:OR('|') PsiWhiteSpace(' ') PsiReferenceExpression:c PsiReferenceParameterList - PsiIdentifier:c('c') + PsiIdentifier:c('c') \ No newline at end of file diff --git a/java/java-tests/testData/psi/resolve/method/generics/RawInheritanceConflict.java b/java/java-tests/testData/psi/resolve/method/generics/RawInheritanceConflict.java new file mode 100644 index 000000000000..8a6de04eff10 --- /dev/null +++ b/java/java-tests/testData/psi/resolve/method/generics/RawInheritanceConflict.java @@ -0,0 +1,10 @@ +class XX { + public static String foo(Properties p, String s, boolean b){return null;} + public static String foo(Map p, String s, boolean b){return null;} +} +class UU { + void bar() { + Properties p = new Properties(); + XX.foo(p, "xxx", false); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java index cd8c8c1ce58f..8d9fac724365 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/CompleteStatementTest.java @@ -228,6 +228,8 @@ public class CompleteStatementTest extends EditorActionTestCase { public void testLastJavadocParameterDescriptionToReturn() throws Exception { doTest(); } + public void testCompleteMethodCallAtReturn() throws Exception { doTest(); } + private void doTestBracesNextLineStyle() throws Exception { CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()); settings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE; diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/RecursiveVisitorTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/RecursiveVisitorTest.java index c8d7facfa0da..fbd79b495bea 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/RecursiveVisitorTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/RecursiveVisitorTest.java @@ -10,8 +10,8 @@ import com.intellij.util.ThrowableRunnable; */ public class RecursiveVisitorTest extends LightDaemonAnalyzerTestCase{ public void testHugeConcatenationVisitingPerformance() throws IncorrectOperationException { - StringBuilder text = new StringBuilder("String s = \"xxx\""); - final int N = 2; + StringBuilder text = new StringBuilder("String s = null"); + final int N = 20000; for (int i = 0; i < N; i++) { text.append("+\"xxx\""); } @@ -19,26 +19,26 @@ public class RecursiveVisitorTest extends LightDaemonAnalyzerTestCase{ final PsiElement expression = JavaPsiFacade.getInstance(getProject()).getElementFactory().createStatementFromText(text.toString(), null); final int[] n = {0}; - PlatformTestUtil.startPerformanceTest(getTestName(false), 20, new ThrowableRunnable() { + PlatformTestUtil.startPerformanceTest(getTestName(false), 100, new ThrowableRunnable() { @Override public void run() throws Exception { n[0] = 0; expression.accept(new JavaRecursiveElementWalkingVisitor() { @Override - public void visitBinaryExpression(final PsiBinaryExpression expression) { - PsiExpression s = expression.getLOperand(); - super.visitBinaryExpression(expression); + public void visitExpression(PsiExpression expression) { + PsiExpression s = expression; + super.visitExpression(expression); s.hashCode(); //hold on stack n[0]++; } }); - assertEquals(N, n[0]); + assertEquals(N+2, n[0]); } }).cpuBound().assertTiming(); } public void testHugeMethodChainingVisitingPerformance() throws IncorrectOperationException { StringBuilder text = new StringBuilder("Object s = new StringBuilder()"); - final int N = 1500; + final int N = 20000; for (int i = 0; i < N; i++) { text.append(".append(\"xxx\")"); } @@ -46,7 +46,7 @@ public class RecursiveVisitorTest extends LightDaemonAnalyzerTestCase{ final PsiElement expression = JavaPsiFacade.getInstance(getProject()).getElementFactory().createStatementFromText(text.toString(), null); final int[] n = {0}; - PlatformTestUtil.startPerformanceTest(getTestName(false), 100, new ThrowableRunnable() { + PlatformTestUtil.startPerformanceTest(getTestName(false), 200, new ThrowableRunnable() { @Override public void run() throws Exception { n[0] = 0; diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/BlockIndentOnPasteTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/BlockIndentOnPasteTest.groovy index 27c90b0fcaf0..5fdbc7c1c108 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/BlockIndentOnPasteTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/editorActions/BlockIndentOnPasteTest.groovy @@ -38,7 +38,7 @@ class Test { def toPaste = '''\ -foo(); + foo(); foo();\ ''' @@ -48,7 +48,7 @@ class Test { void test() { if (true) { foo(); - foo(); + foo(); } } }\ @@ -56,6 +56,48 @@ class Test { doTest(before, toPaste, expected) } + void testJavaComplexBlockWithDecreasedIndent() { + def before = '''\ +class Test { + void test() { + if (true) { + i = 1; + } else { + i = 2; + } + + } +}\ +''' + + def toPaste = + '''\ + if (true) { + i = 1; + } else { + i = 2; + }\ +''' + + def expected = '''\ +class Test { + void test() { + if (true) { + i = 1; + } else { + i = 2; + } + if (true) { + i = 1; + } else { + i = 2; + } + } +}\ +''' + doTest(before, toPaste, expected) + } + void testJavaBlockIncreasedIndentOnTwoLinesPasting() { def before = '''\ class Test { @@ -70,7 +112,7 @@ class Test { def toPaste = '''\ foo(); - foo();\ + foo();\ ''' @@ -79,7 +121,7 @@ class Test { void test() { if (true) { foo(); - foo(); + foo(); } } }\ @@ -100,7 +142,7 @@ class Test { def toPaste = '''\ -foo(); + foo(); foo();\ ''' @@ -110,7 +152,7 @@ class Test { void test() { if (true) { foo(); - foo(); + foo(); } } }\ @@ -131,7 +173,7 @@ class Test { def toPaste = '''\ -foo(); + foo(); foo(); foo();\ ''' @@ -175,8 +217,8 @@ class Test { void test() { if (true) { foo(); - foo(); - foo(); + foo(); + foo(); } } }\ @@ -229,20 +271,20 @@ class Test { def toPaste = '''\ - // this is a comment - foo(); - foo(); - foo();\ +// this is a comment + foo(); + foo(); +foo();\ ''' def expected = '''\ class Test { void test() { - if (true) { // this is a comment - foo(); + if (true) {// this is a comment foo(); - foo(); + foo(); + foo(); } } }\ @@ -250,6 +292,88 @@ class Test { doTest(before, toPaste, expected) } + void testPasteAtZeroColumnAfterBlankLineWithWhiteSpaces() { + def before = '''\ +class Test { + void test() { + if (true) { + } + } +} + +\ +''' + + def toPaste = + '''\ +class Test { + void test() { + if (true) { + } + } +}\ +''' + + + def expected = '''\ +class Test { + void test() { + if (true) { + } + } +} + +class Test { + void test() { + if (true) { + } + } +}\ +''' + doTest(before, toPaste, expected) + } + + void testPasteAtNonZeroColumnAfterBlankLineWithWhiteSpaces() { + def before = '''\ +class Test { + void test() { + if (true) { + } + } +} + + \ +''' + + def toPaste = + '''\ +class Test { + void test() { + if (true) { + } + } +}\ +''' + + + def expected = '''\ +class Test { + void test() { + if (true) { + } + } +} + +class Test { + void test() { + if (true) { + } + } +}\ +''' + doTest(before, toPaste, expected) + } + def testPlainTextPaste() { def before = '''\ line1 diff --git a/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/ExpressionParserTest.java b/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/ExpressionParserTest.java index ec8531d4a16c..4316a5c12c5d 100644 --- a/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/ExpressionParserTest.java +++ b/java/java-tests/testSrc/com/intellij/lang/java/parser/partial/ExpressionParserTest.java @@ -19,6 +19,7 @@ import com.intellij.lang.PsiBuilder; import com.intellij.lang.java.parser.ExpressionParser; import com.intellij.lang.java.parser.JavaParsingTestCase; import com.intellij.pom.java.LanguageLevel; +import org.jetbrains.annotations.NonNls; public class ExpressionParserTest extends JavaParsingTestCase { @@ -115,7 +116,7 @@ public class ExpressionParserTest extends JavaParsingTestCase { public void testChainedClassObjectAccess() { doParserTest("A.class.B.class"); } public void testChainedThisObjectAccess() { doParserTest("A.this.B.this"); } - private void doParserTest(final String text) { + private void doParserTest(@NonNls final String text) { doParserTest(text, new TestParser() { @Override public void parse(final PsiBuilder builder) { diff --git a/java/java-tests/testSrc/com/intellij/psi/JavaSOEOnReparseTest.java b/java/java-tests/testSrc/com/intellij/psi/JavaSOEOnReparseTest.java index 1920c4a08dce..39f8461a1eea 100644 --- a/java/java-tests/testSrc/com/intellij/psi/JavaSOEOnReparseTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/JavaSOEOnReparseTest.java @@ -15,16 +15,15 @@ */ package com.intellij.psi; +import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.testFramework.LightCodeInsightTestCase; -public class JavaSOEOnReparseTest extends LightCodeInsightTestCase { - private static final String HUGE_EXPR; +public class JavaSOEOnReparseTest extends LightDaemonAnalyzerTestCase { + private static final StringBuilder HUGE_EXPR; static { - final StringBuilder sb = new StringBuilder("\"-\""); - for (int i = 0; i < 10000; i++) sb.append("+\"b\""); - HUGE_EXPR = sb.toString(); + HUGE_EXPR = new StringBuilder("\"-\""); + for (int i = 0; i < 100000; i++) HUGE_EXPR.append("+\"b\""); } public void testOnHugeBinaryExprInFile() throws Exception { @@ -37,7 +36,7 @@ public class JavaSOEOnReparseTest extends LightCodeInsightTestCase { doTest(); } - private static void doTest() { + private void doTest() { final int pos = getEditor().getDocument().getText().indexOf("\"\""); // replace small expression with huge binary one @@ -45,23 +44,27 @@ public class JavaSOEOnReparseTest extends LightCodeInsightTestCase { getEditor().getDocument().replaceString(pos, pos + 2, HUGE_EXPR); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); }}); + doTestConfiguredFile(false, false); // modify huge binary expression (1) ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { getEditor().getDocument().insertString(pos, "\".\"+"); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); }}); + doTestConfiguredFile(false, false); // modify huge binary expression (2) ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { getEditor().getDocument().replaceString(pos, pos + 4, ""); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); }}); + doTestConfiguredFile(false, false); // replace huge binary expression with small one ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { getEditor().getDocument().replaceString(pos, pos + HUGE_EXPR.length(), "\".\""); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); }}); + doTestConfiguredFile(false, false); } } diff --git a/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java b/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java index 45a08cbf7b46..222941f69cb9 100644 --- a/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/JavaStubBuilderTest.java @@ -26,6 +26,7 @@ import com.intellij.psi.stubs.StubElement; import com.intellij.testFramework.LightIdeaTestCase; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.util.ThrowableRunnable; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; import java.io.File; @@ -36,7 +37,6 @@ public class JavaStubBuilderTest extends LightIdeaTestCase { @SuppressWarnings("deprecation") private static final StubBuilder OLD_BUILDER = new com.intellij.psi.impl.source.JavaFileStubBuilder(); private static final StubBuilder NEW_BUILDER = new JavaLightStubBuilder(); - private static final int SOE_TEST_DEPTH = 20000; @Override public void setUp() throws Exception { @@ -330,7 +330,8 @@ public class JavaStubBuilderTest extends LightIdeaTestCase { final StringBuilder sb = new StringBuilder(); final SecureRandom random = new SecureRandom(); sb.append("class SOE_test {\n BigInteger BIG = new BigInteger(\n"); - for (int i = 0; i < SOE_TEST_DEPTH; i++) { + int i; + for (i = 0; i < 100000; i++) { sb.append(" \"").append(Math.abs(random.nextInt())).append("\" +\n"); } sb.append(" \"\");\n}"); @@ -349,7 +350,7 @@ public class JavaStubBuilderTest extends LightIdeaTestCase { " FIELD:PsiFieldStub[BIG:BigInteger=;INITIALIZER_NOT_STORED;]\n" + " MODIFIER_LIST:PsiModifierListStub[mask=4096]\n", DebugUtil.stubTreeToString(tree)); - System.out.println("SOE depth=" + SOE_TEST_DEPTH + ", time=" + t + "ms"); + System.out.println("SOE depth=" + i + ", time=" + t + "ms"); } public void testPerformance() throws Exception { @@ -365,7 +366,7 @@ public class JavaStubBuilderTest extends LightIdeaTestCase { }).cpuBound().assertTiming(); } - private static void doTest(final String source, @Nullable final String tree) { + private static void doTest(@NonNls final String source, @NonNls @Nullable final String tree) { final PsiJavaFile file = (PsiJavaFile)createLightFile("test.java", source); final FileASTNode fileNode = file.getNode(); assertNotNull(fileNode); diff --git a/java/java-tests/testSrc/com/intellij/psi/resolve/ResolveMethod15Test.java b/java/java-tests/testSrc/com/intellij/psi/resolve/ResolveMethod15Test.java index a2534061db84..5e6753b69347 100644 --- a/java/java-tests/testSrc/com/intellij/psi/resolve/ResolveMethod15Test.java +++ b/java/java-tests/testSrc/com/intellij/psi/resolve/ResolveMethod15Test.java @@ -509,6 +509,12 @@ public class ResolveMethod15Test extends Resolve15TestCase { assertResolvesToMethodInClass(result, "A"); } + public void testRawInheritanceConflict() throws Exception { + PsiJavaReference ref = (PsiJavaReference)configureByFile(); + final JavaResolveResult[] result = ref.multiResolve(false); + assertEquals("False ambiguity", 1, result.length); + } + public void testRawVsGenericConflictInCaseOfOverride() throws Exception{ PsiJavaReference ref = (PsiJavaReference) configureByFile(); final JavaResolveResult result = ref.advancedResolve(true); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java index 0eff3ae90c2f..653e997218ea 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java @@ -11,11 +11,13 @@ package com.intellij.refactoring; import com.intellij.JavaTestUtil; import com.intellij.codeInsight.CodeInsightUtil; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.util.Pass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiExpression; import com.intellij.psi.PsiLocalVariable; import com.intellij.psi.PsiMethod; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.refactoring.introduceField.ElementToWorkOn; import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; import com.intellij.refactoring.introduceParameter.IntroduceParameterProcessor; import com.intellij.refactoring.introduceParameter.Util; @@ -317,24 +319,25 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase { final boolean removeUnusedParameters, final boolean generateDelegate, int enclosingLevel) { - int startOffset = myEditor.getSelectionModel().getSelectionStart(); - int endOffset = myEditor.getSelectionModel().getSelectionEnd(); + final ElementToWorkOn[] elementToWorkOn = new ElementToWorkOn[1]; + ElementToWorkOn + .processElementToWorkOn(myEditor, myFile, "INtr param", HelpID.INTRODUCE_PARAMETER, getProject(), new Pass() { + @Override + public void pass(final ElementToWorkOn e) { + if (e == null) return; - PsiExpression expr = CodeInsightUtil.findExpressionInRange(myFile, startOffset, endOffset); + elementToWorkOn[0] = e; + } + }); - PsiLocalVariable localVariable = null; - if (expr == null) { - PsiElement element = CodeInsightUtil.findElementInRange(myFile, startOffset, endOffset, PsiElement.class); - localVariable = PsiTreeUtil.getParentOfType(element, PsiLocalVariable.class); - if (localVariable == null) { - return false; - } - } - PsiElement context = expr == null ? localVariable : expr; + final PsiExpression expr = elementToWorkOn[0].getExpression(); + final PsiLocalVariable localVar = elementToWorkOn[0].getLocalVariable(); + + PsiElement context = expr == null ? localVar : expr; PsiMethod method = Util.getContainingMethod(context); if (method == null) return false; - final List methods = IntroduceParameterHandler.getEnclosingMethods(method); + final List methods = com.intellij.refactoring.introduceParameter.IntroduceParameterHandler.getEnclosingMethods(method); assertTrue(methods.size() > enclosingLevel); method = methods.get(enclosingLevel); @@ -345,11 +348,11 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase { else { methodToSearchFor = method; } - PsiExpression[] occurences = null; + PsiExpression[] occurences; PsiExpression initializer; if (expr == null) { - initializer = localVariable.getInitializer(); - occurences = CodeInsightUtil.findReferenceExpressions(method, localVariable); + initializer = localVar.getInitializer(); + occurences = CodeInsightUtil.findReferenceExpressions(method, localVar); } else { initializer = expr; @@ -357,7 +360,7 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase { } TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, initializer, occurences) : new TIntArrayList(); new IntroduceParameterProcessor( - getProject(), method, methodToSearchFor, initializer, expr, localVariable, true, parameterName, replaceAllOccurences, + getProject(), method, methodToSearchFor, initializer, expr, localVar, true, parameterName, replaceAllOccurences, replaceFieldsWithGetters, declareFinal, generateDelegate, null, parametersToRemove).run(); diff --git a/java/openapi/src/com/intellij/codeInsight/CodeInsightServicesUtil.java b/java/openapi/src/com/intellij/codeInsight/CodeInsightServicesUtil.java index f18999049d9b..5bac063e4730 100644 --- a/java/openapi/src/com/intellij/codeInsight/CodeInsightServicesUtil.java +++ b/java/openapi/src/com/intellij/codeInsight/CodeInsightServicesUtil.java @@ -26,7 +26,7 @@ import com.intellij.util.IncorrectOperationException; public class CodeInsightServicesUtil { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.CodeInsightServicesUtil"); - private static final IElementType[] ourTokenMap = new IElementType[]{ + private static final IElementType[] ourTokenMap = { JavaTokenType.EQEQ, JavaTokenType.NE, JavaTokenType.LT, JavaTokenType.GE, JavaTokenType.LE, JavaTokenType.GT, @@ -36,39 +36,45 @@ public class CodeInsightServicesUtil { public static PsiExpression invertCondition(PsiExpression booleanExpression) throws IncorrectOperationException { PsiElementFactory factory = JavaPsiFacade.getInstance(booleanExpression.getProject()).getElementFactory(); - if (booleanExpression instanceof PsiBinaryExpression) { - PsiBinaryExpression expression = (PsiBinaryExpression) booleanExpression; - PsiJavaToken operationSign = expression.getOperationSign(); + if (booleanExpression instanceof PsiPolyadicExpression) { + PsiPolyadicExpression expression = (PsiPolyadicExpression)booleanExpression; + IElementType operationSign = expression.getOperationTokenType(); for (int i = 0; i < ourTokenMap.length; i++) { IElementType tokenType = ourTokenMap[i]; - if (operationSign.getTokenType() == tokenType) { + if (operationSign == tokenType) { expression = (PsiBinaryExpression)expression.copy(); - expression.getOperationSign().replace(createOperationToken(factory, ourTokenMap[i + (i % 2 == 0 ? 1 : -1)])); - if (tokenType == JavaTokenType.OROR || tokenType == JavaTokenType.ANDAND) { - expression.getLOperand().replace(invertCondition(expression.getLOperand())); - expression.getROperand().replace(invertCondition(expression.getROperand())); + PsiExpression[] operands = expression.getOperands(); + for (int o = 0; o < operands.length; o++) { + PsiExpression op = operands[o]; + if (o != 0) { + expression.getTokenBeforeOperand(op).replace(createOperationToken(factory, ourTokenMap[i + (i % 2 == 0 ? 1 : -1)])); + } + if (tokenType == JavaTokenType.OROR || tokenType == JavaTokenType.ANDAND) { + op.replace(invertCondition(op)); + } } return expression; } } - } else if (booleanExpression instanceof PsiPrefixExpression) { - PsiPrefixExpression expression = (PsiPrefixExpression) booleanExpression; - PsiJavaToken operationSign = expression.getOperationSign(); - if (operationSign.getTokenType() == JavaTokenType.EXCL) { + } + else if (booleanExpression instanceof PsiPrefixExpression) { + PsiPrefixExpression expression = (PsiPrefixExpression)booleanExpression; + if (expression.getOperationTokenType() == JavaTokenType.EXCL) { PsiExpression operand = expression.getOperand(); if (operand instanceof PsiParenthesizedExpression) { - operand = ((PsiParenthesizedExpression) operand).getExpression(); + operand = ((PsiParenthesizedExpression)operand).getExpression(); } return operand; } - } else if (booleanExpression instanceof PsiLiteralExpression) { + } + else if (booleanExpression instanceof PsiLiteralExpression) { return booleanExpression.getText().equals("true") ? factory.createExpressionFromText("false", null) : factory.createExpressionFromText("true", null); } if (booleanExpression instanceof PsiParenthesizedExpression) { - PsiExpression operand = ((PsiParenthesizedExpression) booleanExpression).getExpression(); + PsiExpression operand = ((PsiParenthesizedExpression)booleanExpression).getExpression(); operand.replace(invertCondition(operand)); return booleanExpression; } @@ -76,8 +82,9 @@ public class CodeInsightServicesUtil { PsiPrefixExpression result = (PsiPrefixExpression)factory.createExpressionFromText("!(a)", null); if (!(booleanExpression instanceof PsiBinaryExpression)) { result.getOperand().replace(booleanExpression); - } else { - PsiParenthesizedExpression e = (PsiParenthesizedExpression) result.getOperand(); + } + else { + PsiParenthesizedExpression e = (PsiParenthesizedExpression)result.getOperand(); e.getExpression().replace(booleanExpression); } @@ -115,7 +122,7 @@ public class CodeInsightServicesUtil { s = "=="; } - PsiBinaryExpression expression = (PsiBinaryExpression) factory.createExpressionFromText("a" + s + "b", null); + PsiBinaryExpression expression = (PsiBinaryExpression)factory.createExpressionFromText("a" + s + "b", null); return expression.getOperationSign(); } } diff --git a/java/openapi/src/com/intellij/psi/JavaElementVisitor.java b/java/openapi/src/com/intellij/psi/JavaElementVisitor.java index cce2a7916ded..7ece4a6065ae 100644 --- a/java/openapi/src/com/intellij/psi/JavaElementVisitor.java +++ b/java/openapi/src/com/intellij/psi/JavaElementVisitor.java @@ -41,7 +41,7 @@ public abstract class JavaElementVisitor extends PsiElementVisitor { } public void visitBinaryExpression(PsiBinaryExpression expression) { - visitExpression(expression); + visitPolyadicExpression(expression); } public void visitBlockStatement(PsiBlockStatement statement) { @@ -367,4 +367,8 @@ public abstract class JavaElementVisitor extends PsiElementVisitor { public void visitCodeFragment(JavaCodeFragment codeFragment) { visitFile(codeFragment); } + + public void visitPolyadicExpression(PsiPolyadicExpression expression) { + visitExpression(expression); + } } diff --git a/java/openapi/src/com/intellij/psi/PsiBinaryExpression.java b/java/openapi/src/com/intellij/psi/PsiBinaryExpression.java index f97dcd7451c9..242c47d4223c 100644 --- a/java/openapi/src/com/intellij/psi/PsiBinaryExpression.java +++ b/java/openapi/src/com/intellij/psi/PsiBinaryExpression.java @@ -21,8 +21,10 @@ import com.intellij.psi.tree.IElementType; /** * Represents a Java binary expression (addition, multiplication and so on). + * @deprecated Use {@link PsiPolyadicExpression} instead. */ -public interface PsiBinaryExpression extends PsiExpression { +@Deprecated +public interface PsiBinaryExpression extends PsiExpression, PsiPolyadicExpression { /** * Returns the left operand of the expression. * diff --git a/java/openapi/src/com/intellij/psi/PsiPolyadicExpression.java b/java/openapi/src/com/intellij/psi/PsiPolyadicExpression.java new file mode 100644 index 000000000000..c1b40d0968e7 --- /dev/null +++ b/java/openapi/src/com/intellij/psi/PsiPolyadicExpression.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2011 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.psi; + +import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; + +/** + * User: cdr + */ +public interface PsiPolyadicExpression extends PsiExpression { + @NotNull PsiExpression[] getOperands(); + + @NotNull + IElementType getOperationTokenType(); + PsiJavaToken getTokenBeforeOperand(@NotNull PsiExpression operand); +} diff --git a/java/openapi/src/com/intellij/psi/util/IsConstantExpressionVisitor.java b/java/openapi/src/com/intellij/psi/util/IsConstantExpressionVisitor.java index 79723f2a7462..bbed9e3d747d 100644 --- a/java/openapi/src/com/intellij/psi/util/IsConstantExpressionVisitor.java +++ b/java/openapi/src/com/intellij/psi/util/IsConstantExpressionVisitor.java @@ -82,20 +82,11 @@ public class IsConstantExpressionVisitor extends JavaElementVisitor { myIsConstant = false; } - @Override public void visitBinaryExpression(PsiBinaryExpression expression) { - while (true) { - // check right operand first since it tends to be shorter - PsiExpression rOperand = expression.getROperand(); - if (rOperand == null) return; - rOperand.accept(this); + @Override + public void visitPolyadicExpression(PsiPolyadicExpression expression) { + for (PsiExpression operand : expression.getOperands()) { + operand.accept(this); if (!myIsConstant) return; - - PsiExpression lOperand = expression.getLOperand(); - if (!(lOperand instanceof PsiBinaryExpression)) { - lOperand.accept(this); - break; - } - expression = (PsiBinaryExpression)lOperand; } } diff --git a/java/openapi/src/com/intellij/psi/util/PsiConcatenationUtil.java b/java/openapi/src/com/intellij/psi/util/PsiConcatenationUtil.java new file mode 100644 index 000000000000..9b60456845ac --- /dev/null +++ b/java/openapi/src/com/intellij/psi/util/PsiConcatenationUtil.java @@ -0,0 +1,138 @@ +/* + * Copyright 2000-2011 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.psi.util; + +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.*; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.util.IncorrectOperationException; + +import java.util.List; + +/** + * User: cdr + */ +public class PsiConcatenationUtil { + public static void buildFormatString( + PsiExpression expression, StringBuilder formatString, + List formatParameters, boolean printfFormat) { + if (expression instanceof PsiLiteralExpression) { + final PsiLiteralExpression literalExpression = + (PsiLiteralExpression) expression; + final String text = String.valueOf(literalExpression.getValue()); + final String formatText; + if (printfFormat) { + formatText = StringUtil.escapeStringCharacters(text) + .replace("%", "%%").replace("\\'", "'"); + } + else { + formatText = StringUtil.escapeStringCharacters(text) + .replace("'", "''").replace("{", "'{").replace("}", "'}"); + } + formatString.append(formatText); + } else if (expression instanceof PsiPolyadicExpression) { + final PsiType type = expression.getType(); + if (type != null && type.equalsToText("java.lang.String")) { + final PsiPolyadicExpression binaryExpression = + (PsiPolyadicExpression) expression; + PsiExpression[] operands = binaryExpression.getOperands(); + PsiType left = operands[0].getType(); + boolean stringStarted = left != null && left.equalsToText("java.lang.String"); + if (stringStarted) { + buildFormatString(operands[0], formatString, formatParameters, printfFormat); + } + for (int i = 1; i < operands.length; i++) { + PsiExpression op = operands[i]; + PsiType optype = op.getType(); + PsiType r = TypeConversionUtil.calcTypeForBinaryExpression(left, optype, binaryExpression.getOperationTokenType(), true); + if (r != null && r.equalsToText("java.lang.String") && !stringStarted) { + stringStarted = true; + PsiElement element = binaryExpression.getTokenBeforeOperand(op); + if (element.getPrevSibling() instanceof PsiWhiteSpace) element = element.getPrevSibling(); + String text = binaryExpression.getText().substring(0, element.getStartOffsetInParent()); + PsiExpression subExpression = JavaPsiFacade.getInstance(binaryExpression.getProject()).getElementFactory() + .createExpressionFromText(text, binaryExpression); + addFormatParameter(subExpression, formatString, formatParameters, printfFormat); + } + if (stringStarted) { + if (optype != null && (optype.equalsToText("java.lang.String") || optype == PsiType.CHAR)) { + buildFormatString(op, formatString, formatParameters, printfFormat); + } + else { + addFormatParameter(op, formatString, formatParameters, printfFormat); + } + } + left = r; + } + } + else { + addFormatParameter(expression, formatString, formatParameters, printfFormat); + } + } + else { + addFormatParameter(expression, formatString, formatParameters, printfFormat); + } + } + + private static void addFormatParameter(PsiExpression expression, + StringBuilder formatString, + List formatParameters, boolean printfFormat) { + final PsiType type = expression.getType(); + if (!printfFormat) { + formatString.append("{" + formatParameters.size() + "}"); + } + else if (type != null && + (type.equalsToText("long") || + type.equalsToText("int") || + type.equalsToText("java.lang.Long") || + type.equalsToText("java.lang.Integer"))) { + formatString.append("%d"); + } + else { + formatString.append("%s"); + } + formatParameters.add(getBoxedArgument(expression)); + } + + private static PsiExpression getBoxedArgument(PsiExpression arg) throws IncorrectOperationException { + arg = PsiUtil.deparenthesizeExpression(arg); + assert arg != null; + if (PsiUtil.isLanguageLevel5OrHigher(arg)) { + return arg; + } + final PsiType type = arg.getType(); + if (!(type instanceof PsiPrimitiveType) || type.equals(PsiType.NULL)) { + return arg; + } + final PsiPrimitiveType primitiveType = (PsiPrimitiveType)type; + final String boxedQName = primitiveType.getBoxedTypeName(); + if (boxedQName == null) { + return arg; + } + final GlobalSearchScope resolveScope = arg.getResolveScope(); + final PsiElementFactory factory = JavaPsiFacade.getElementFactory(arg.getProject()); + final PsiJavaCodeReferenceElement ref = factory.createReferenceElementByFQClassName(boxedQName, resolveScope); + final PsiNewExpression newExpr = (PsiNewExpression)factory.createExpressionFromText("new A(b)", null); + final PsiElement classRef = newExpr.getClassReference(); + assert classRef != null; + classRef.replace(ref); + final PsiExpressionList argumentList = newExpr.getArgumentList(); + assert argumentList != null; + argumentList.getExpressions()[0].replace(arg); + return newExpr; + } + +} diff --git a/java/openapi/src/com/intellij/psi/util/PsiExpressionTrimRenderer.java b/java/openapi/src/com/intellij/psi/util/PsiExpressionTrimRenderer.java index 1e82ddd1319a..73a87a08b14b 100644 --- a/java/openapi/src/com/intellij/psi/util/PsiExpressionTrimRenderer.java +++ b/java/openapi/src/com/intellij/psi/util/PsiExpressionTrimRenderer.java @@ -94,12 +94,15 @@ public class PsiExpressionTrimRenderer extends JavaRecursiveElementWalkingVisito } @Override - public void visitBinaryExpression(final PsiBinaryExpression expression) { - expression.getLOperand().accept(this); - myBuf.append(" ").append(expression.getOperationSign().getText()).append(" "); - final PsiExpression rOperand = expression.getROperand(); - if (rOperand != null) { - rOperand.accept(this); + public void visitPolyadicExpression(PsiPolyadicExpression expression) { + PsiExpression[] operands = expression.getOperands(); + for (int i = 0; i < operands.length; i++) { + PsiExpression operand = operands[i]; + operand.accept(this); + if (i != 0) { + PsiJavaToken token = expression.getTokenBeforeOperand(operand); + myBuf.append(" ").append(token.getText()).append(" "); + } } } diff --git a/java/openapi/src/com/intellij/psi/util/RedundantCastUtil.java b/java/openapi/src/com/intellij/psi/util/RedundantCastUtil.java index 15f928500624..8ac58847d456 100644 --- a/java/openapi/src/com/intellij/psi/util/RedundantCastUtil.java +++ b/java/openapi/src/com/intellij/psi/util/RedundantCastUtil.java @@ -136,25 +136,29 @@ public class RedundantCastUtil { super.visitReturnStatement(statement); } - @Override public void visitBinaryExpression(PsiBinaryExpression expression) { - PsiExpression rExpr = deparenthesizeExpression(expression.getLOperand()); - PsiExpression lExpr = deparenthesizeExpression(expression.getROperand()); - - if (rExpr != null && lExpr != null) { - final IElementType binaryToken = expression.getOperationTokenType(); - processBinaryExpressionOperand(lExpr, rExpr, binaryToken); - processBinaryExpressionOperand(rExpr, lExpr, binaryToken); + @Override + public void visitPolyadicExpression(PsiPolyadicExpression expression) { + IElementType tokenType = expression.getOperationTokenType(); + PsiExpression[] operands = expression.getOperands(); + if (operands.length >= 2) { + PsiType lType = operands[0].getType(); + processBinaryExpressionOperand(deparenthesizeExpression(operands[0]), operands[1].getType(), tokenType); + for (int i = 1; i < operands.length; i++) { + PsiExpression operand = deparenthesizeExpression(operands[i]); + processBinaryExpressionOperand(operand, lType, tokenType); + lType = TypeConversionUtil.calcTypeForBinaryExpression(lType, operand.getType(), tokenType, true); + } } - super.visitBinaryExpression(expression); + super.visitPolyadicExpression(expression); } private void processBinaryExpressionOperand(final PsiExpression operand, - final PsiExpression otherOperand, + final PsiType otherType, final IElementType binaryToken) { if (operand instanceof PsiTypeCastExpression) { PsiTypeCastExpression typeCast = (PsiTypeCastExpression)operand; PsiExpression toCast = typeCast.getOperand(); - if (toCast != null && TypeConversionUtil.isBinaryOperatorApplicable(binaryToken, toCast, otherOperand, false)) { + if (toCast != null && TypeConversionUtil.isBinaryOperatorApplicable(binaryToken, toCast.getType(), otherType, false)) { addToResults(typeCast); } } diff --git a/java/openapi/src/com/intellij/psi/util/TypeConversionUtil.java b/java/openapi/src/com/intellij/psi/util/TypeConversionUtil.java index eff8f437a258..139030a835ff 100644 --- a/java/openapi/src/com/intellij/psi/util/TypeConversionUtil.java +++ b/java/openapi/src/com/intellij/psi/util/TypeConversionUtil.java @@ -29,6 +29,7 @@ import com.intellij.util.containers.HashMap; import gnu.trove.THashMap; import gnu.trove.THashSet; import gnu.trove.TObjectIntHashMap; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -62,6 +63,16 @@ public class TypeConversionUtil { private static final int BOOL_RANK = 10; private static final int STRING_RANK = 100; private static final int MAX_NUMERIC_RANK = DOUBLE_RANK; + public static final PsiType NULL_TYPE = new PsiEllipsisType(PsiType.NULL){ + public boolean isValid() { + return true; + } + + @NonNls + public String getPresentableText() { + return "FAKE TYPE"; + } + }; static { TYPE_TO_RANK_MAP.put(PsiType.BYTE, BYTE_RANK); @@ -1269,6 +1280,62 @@ public class TypeConversionUtil { return opSign; } + @Nullable + public static PsiType calcTypeForBinaryExpression(PsiType lType, PsiType rType, IElementType sign, boolean accessLType) { + if (sign == JavaTokenType.PLUS) { + // evaluate right argument first, since '+-/*%' is left associative and left operand tends to be bigger + if (rType == null) return null; + if (rType.equalsToText("java.lang.String")) { + return rType; + } + if (!accessLType) return NULL_TYPE; + if (lType == null) return null; + if (lType.equalsToText("java.lang.String")) { + return lType; + } + return unboxAndBalanceTypes(lType, rType); + } + if (sign == JavaTokenType.MINUS || sign == JavaTokenType.ASTERISK || sign == JavaTokenType.DIV || sign == JavaTokenType.PERC) { + if (rType == null) return null; + if (!accessLType) return NULL_TYPE; + if (lType == null) return null; + return unboxAndBalanceTypes(lType, rType); + } + if (sign == JavaTokenType.LTLT || sign == JavaTokenType.GTGT || sign == JavaTokenType.GTGTGT) { + if (!accessLType) return NULL_TYPE; + if (PsiType.BYTE.equals(lType) || PsiType.CHAR.equals(lType) || PsiType.SHORT.equals(lType)) { + return PsiType.INT; + } + if (lType instanceof PsiClassType) lType = PsiPrimitiveType.getUnboxedType(lType); + return lType; + } + if (sign == JavaTokenType.EQEQ || + sign == JavaTokenType.NE || + sign == JavaTokenType.LT || + sign == JavaTokenType.GT || + sign == JavaTokenType.LE || + sign == JavaTokenType.GE || + sign == JavaTokenType.OROR || + sign == JavaTokenType.ANDAND) { + return PsiType.BOOLEAN; + } + if (sign == JavaTokenType.OR || sign == JavaTokenType.XOR || sign == JavaTokenType.AND) { + if (rType instanceof PsiClassType) rType = PsiPrimitiveType.getUnboxedType(rType); + + if (lType instanceof PsiClassType) lType = PsiPrimitiveType.getUnboxedType(lType); + + if (rType == null) return null; + if (PsiType.BOOLEAN.equals(rType)) return PsiType.BOOLEAN; + if (!accessLType) return NULL_TYPE; + if (lType == null) return null; + if (PsiType.BOOLEAN.equals(lType)) return PsiType.BOOLEAN; + if (PsiType.LONG.equals(lType) || PsiType.LONG.equals(rType)) return PsiType.LONG; + return PsiType.INT; + } + LOG.error("Unknown token: "+sign); + return null; + } + private interface Caster { Object cast(Object operand); } diff --git a/lib/ant/KEYS b/lib/ant/KEYS index 6e88d7397384..26260e0f9a60 100644 --- a/lib/ant/KEYS +++ b/lib/ant/KEYS @@ -174,46 +174,6 @@ o+d57fYsNa8xAJ4mLfonZbd64+YY9rfvhIh3Vsl3AACeLPPKtma2K6XCfhTBEDnj hzSr4vo= =lBfF -----END PGP PUBLIC KEY BLOCK----- -pub 1024D/265B4C63 2003-08-18 Antoine Levy-Lambert (Apache Ant Committer) -sig 3 265B4C63 2003-12-06 Antoine Levy-Lambert (Apache Ant Committer) -sig 3 5F6B8B72 2003-12-12 Stefan Bodewig -uid Antoine Levy-Lambert (Apache Ant Committer) -sig 3 265B4C63 2003-08-18 Antoine Levy-Lambert (Apache Ant Committer) -sig 3 5F6B8B72 2003-12-12 Stefan Bodewig -sub 1024g/A3060393 2003-08-18 -sig 265B4C63 2003-08-18 Antoine Levy-Lambert (Apache Ant Committer) - ------BEGIN PGP PUBLIC KEY BLOCK----- -Version: GnuPG v1.2.2 (MingW32) - -mQGiBD9AzmcRBACMqgb7IFvC/nLxw7mUAgHENeZXY3JOQJ8wVBevIbbMEeFvzHE2 -diFydqUXocPexduYr0ahkf033WvWdAiNqDLfVW/HFOsc1TpjbHkqPUHtJ62Ya5tg -nH4UGN9BYZfMbfVDOSz41lYwmfK5HYgpZN/sBQBSKf2qgoFB+LxYaae8YwCgrWlu -fYhf7fkKbbdSf3BGS67ggNkD/0VvkXkw1SEnPaqrkKGkPKomCTb2auGxcYYI3/rP -1m+SGRf0gE1NtocmIEitiR6WvfKUjoMAXSCp5KdnUXmO9rwzkM002KCA7K5CY+e/ -2bLDuiQ3rNiD4mFfG6M+UnmZ+GMFba1p9Cp4PqLNLsCHz67t7hEsscTZQ8mZ9xKM -+GCsA/9P+XFM7JDn9MLhYab9qo1CkceBkthUP6jWGjuAZ00elmBCkpkzNv5aIzss -xih2GpaU/tmcMjw8FGp0dTwzqdpmbZBLjunRnuBTir4m4l5G9rwl4JbfK1PVqk4a -VKkh9W7/yqBcEfNcsfJO9cqaQ+PzcnCoDiD9UHEBYzUhrCKwhLRCQW50b2luZSBM -ZXZ5LUxhbWJlcnQgKEFwYWNoZSBBbnQgQ29tbWl0dGVyKSA8YW50b2luZUBhbnRi -dWlsZC5jb20+iFsEExECABsFAj9AzmcGCwkIBwMCAxUCAwMWAgECHgECF4AACgkQ -hhTWqyZbTGMnOgCeJV2gI+1CIxMR7dcIhXjPkiusreIAn2SGOsPS0o89l0EIVuc9 -J2F03aB+iEYEExECAAYFAj/ZwioACgkQohFa4V9ri3J8CACgiGlh+td0BAnJPq19 -ovEQR2DJ02MAoLP203EF+BLPpykeTcGp8UEWmeGQtEBBbnRvaW5lIExldnktTGFt -YmVydCAoQXBhY2hlIEFudCBDb21taXR0ZXIpIDxhbnRvaW5lQGFwYWNoZS5vcmc+ -iF4EExECAB4FAj/SSwYCGwMGCwkIBwMCAxUCAwMWAgECHgECF4AACgkQhhTWqyZb -TGOh/QCfbrSoipMlizyGT6c8BOPEd9zzfi0AnRRTqTDzXzsGk4CG/BJME9CCm7Ts -iEYEExECAAYFAj/ZwiMACgkQohFa4V9ri3IOVACgh2QHS1+cVjvM4eLjls1bJwWi -o5IAoLtAszHrwHS5qrhvr2rtnlyyyV2guQENBD9AzmkQBACNpBfqi2PweozCtxoX -PqzKdRDKqCw7TOrDR6lbP3z/ov/1SN5Vc0XqNzBSGqwBcmGWtneABkX7n4uzJrC5 -wvX/TZ/DkMvypPyeNVMu+/ZMlzdbx06OUDKr6Fy/NtaI7cN1rw+Igyv22Q8ilhhg -s/5Rdj84EtJkWQjVRml6wXSAZwADBwP/TqyhOC4sA5YrePYGH8i46h0SU9dXjfEF -JijC8vXZ+BNQHQVK3fjEXedZL8Zvvp1bsMu7Muz9SMnqygM1unp2NGxLRd/9315p -Qh0VStYKn0xq13ybOKr0Gsyx5yyl3Nzlu/1qAR0es/zN4jV7/IQi3R2GOvezcpHX -mkbsYiZAhu2IRgQYEQIABgUCP0DOaQAKCRCGFNarJltMYxcsAKCSJJUABlXYnLBj -b+WtmAzu0JjZNACdFJ4KIATJDK/5ajFq5+irOpodoHc= -=UomR ------END PGP PUBLIC KEY BLOCK----- pub 1024D/5F6B8B72 2001-05-28 uid Stefan Bodewig @@ -1246,3 +1206,193 @@ iNoi9D8jtudc46l1OASP7n9e+WQDCd/IwwsUXHqT4+EkM/ZIj31W1+mBZtzIPBCU udvp =oSat -----END PGP PUBLIC KEY BLOCK----- +pub 1024D/265B4C63 2003-08-18 +uid Antoine Levy-Lambert (Apache Ant Committer) +sig 3 265B4C63 2003-12-06 Antoine Levy-Lambert (Apache Ant Committer) +sig 3 5F6B8B72 2003-12-12 Stefan Bodewig +uid Antoine Levy-Lambert (Apache Ant Committer) +sig 3 265B4C63 2003-08-18 Antoine Levy-Lambert (Apache Ant Committer) +sig 3 5F6B8B72 2003-12-12 Stefan Bodewig +sub 1024g/A3060393 2003-08-18 +sig 265B4C63 2003-08-18 Antoine Levy-Lambert (Apache Ant Committer) + +pub 4096R/710038F5 2010-11-02 +uid Antoine Levy-Lambert (CODE SIGNING KEY) +sig 3 710038F5 2010-11-02 Antoine Levy-Lambert (CODE SIGNING KEY) +sub 4096R/84F32FDC 2010-11-02 +sig 710038F5 2010-11-02 Antoine Levy-Lambert (CODE SIGNING KEY) + +pub 4096R/82A7FBCD 2010-11-02 +uid Antoine Levy-Lambert (CODE SIGNING KEY) +sig 3 82A7FBCD 2010-11-02 Antoine Levy-Lambert (CODE SIGNING KEY) +sig 62B2963F 2010-11-04 Dan Poirier +sig 7C408737 2010-11-04 Joseph Edward Bergmark (CODE SIGNING KEY) +sig 02E9F65B 2010-11-04 Luc Maisonobe +sig EFB55DF1 2010-11-05 Luciano Resende (Code Signing Key) +sub 4096R/70EC4C9A 2010-11-02 +sig 82A7FBCD 2010-11-02 Antoine Levy-Lambert (CODE SIGNING KEY) + +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG/MacGPG2 v2.0.16 (Darwin) + +mQGiBD9AzmcRBACMqgb7IFvC/nLxw7mUAgHENeZXY3JOQJ8wVBevIbbMEeFvzHE2 +diFydqUXocPexduYr0ahkf033WvWdAiNqDLfVW/HFOsc1TpjbHkqPUHtJ62Ya5tg +nH4UGN9BYZfMbfVDOSz41lYwmfK5HYgpZN/sBQBSKf2qgoFB+LxYaae8YwCgrWlu +fYhf7fkKbbdSf3BGS67ggNkD/0VvkXkw1SEnPaqrkKGkPKomCTb2auGxcYYI3/rP +1m+SGRf0gE1NtocmIEitiR6WvfKUjoMAXSCp5KdnUXmO9rwzkM002KCA7K5CY+e/ +2bLDuiQ3rNiD4mFfG6M+UnmZ+GMFba1p9Cp4PqLNLsCHz67t7hEsscTZQ8mZ9xKM ++GCsA/9P+XFM7JDn9MLhYab9qo1CkceBkthUP6jWGjuAZ00elmBCkpkzNv5aIzss +xih2GpaU/tmcMjw8FGp0dTwzqdpmbZBLjunRnuBTir4m4l5G9rwl4JbfK1PVqk4a +VKkh9W7/yqBcEfNcsfJO9cqaQ+PzcnCoDiD9UHEBYzUhrCKwhLRCQW50b2luZSBM +ZXZ5LUxhbWJlcnQgKEFwYWNoZSBBbnQgQ29tbWl0dGVyKSA8YW50b2luZUBhbnRi +dWlsZC5jb20+iFsEExECABsFAj9AzmcGCwkIBwMCAxUCAwMWAgECHgECF4AACgkQ +hhTWqyZbTGMnOgCeJV2gI+1CIxMR7dcIhXjPkiusreIAn2SGOsPS0o89l0EIVuc9 +J2F03aB+iEYEExECAAYFAj/ZwioACgkQohFa4V9ri3J8CACgiGlh+td0BAnJPq19 +ovEQR2DJ02MAoLP203EF+BLPpykeTcGp8UEWmeGQtEBBbnRvaW5lIExldnktTGFt +YmVydCAoQXBhY2hlIEFudCBDb21taXR0ZXIpIDxhbnRvaW5lQGFwYWNoZS5vcmc+ +iF4EExECAB4FAj/SSwYCGwMGCwkIBwMCAxUCAwMWAgECHgECF4AACgkQhhTWqyZb +TGOh/QCfbrSoipMlizyGT6c8BOPEd9zzfi0AnRRTqTDzXzsGk4CG/BJME9CCm7Ts +iEYEExECAAYFAj/ZwiMACgkQohFa4V9ri3IOVACgh2QHS1+cVjvM4eLjls1bJwWi +o5IAoLtAszHrwHS5qrhvr2rtnlyyyV2guQENBD9AzmkQBACNpBfqi2PweozCtxoX +PqzKdRDKqCw7TOrDR6lbP3z/ov/1SN5Vc0XqNzBSGqwBcmGWtneABkX7n4uzJrC5 +wvX/TZ/DkMvypPyeNVMu+/ZMlzdbx06OUDKr6Fy/NtaI7cN1rw+Igyv22Q8ilhhg +s/5Rdj84EtJkWQjVRml6wXSAZwADBwP/TqyhOC4sA5YrePYGH8i46h0SU9dXjfEF +JijC8vXZ+BNQHQVK3fjEXedZL8Zvvp1bsMu7Muz9SMnqygM1unp2NGxLRd/9315p +Qh0VStYKn0xq13ybOKr0Gsyx5yyl3Nzlu/1qAR0es/zN4jV7/IQi3R2GOvezcpHX +mkbsYiZAhu2IRgQYEQIABgUCP0DOaQAKCRCGFNarJltMYxcsAKCSJJUABlXYnLBj +b+WtmAzu0JjZNACdFJ4KIATJDK/5ajFq5+irOpodoHeZAg0ETM+HJwEQAMkzgJCo +lSOgkvzsTcjy/4ySwS56VgyFdYpZis8QqbEGCe8xKT+d9FYi5sBTw/jGpIy4weig +NKRRW4NLYgriWJANksBaaPOKvczGAOLWzh2aPfifaGF/puIVT8yCubH6ecxr0Wy/ +lN54Rpi7cmpp+CEbhUTR+7xNGCMt3f9brtOlC6qYN3tJ7PPcfNBjJr0Ts+fPt8lT +RZlBhVa9iEUVYoqMnZQEBmYkg+FxSrFlLw7/WLMKaKGHAV7QbpIxhaDvQ7bMM6qW +c4plt10+wtZtJV3MB6TIRSYaEF87hXCif7mJY8KkCN8XkAxFlQhqEY/gJTOs73DS +Z5+LJKUOF+0+66B31tN5gQq5yNBGd55OEA9iOM87hhQb4e0IuZGvq2vxxK1OL6Q5 +apr141c0ZxHLKaG2YCqM0B42mW84V2mO/Xu25HUjmXGrkpEd61KaodffS5g7SWj3 +jb0X1w/+QGQXnWdTPWuWu/SrpnJb9kBpk/awrBbh6/gz9Uug6WVw3jBaYvfm2gEf +eKVYXa8AtBDSDuytXSXCSNRKY6Hd27ohUKMRBLEtz6Z+WgTKS11u9ip6ewG9irtk +cJQmloGjgaQTLmTXJaZ9UkaEh8uH/LinhIDHk+ilht7z2+CN7S3kOX094v1AnvlA +OchoDd7Wn1KqSoiM6WO5pccPdnU/j4LSoeVDABEBAAG0PEFudG9pbmUgTGV2eS1M +YW1iZXJ0IChDT0RFIFNJR05JTkcgS0VZKSA8YW50b2luZUBhcGFjaGUub3JnPokC +OAQTAQIAIgUCTM+HJwIbAwYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AACgkQDmn4 +CXEAOPVsEQ//Vv4CTUrXTvuaPTNR1x08nntcF5RY+2GGNlT5Cs6EzRbiB3GmKFKu +Qxp0Ucgr+Yg1NTa7jOP2TbMwo8/FCD6i/Q5pWTISs7CdahnqKx37a33F1Hz1bNqV +0Jhi5oJS/sVniYG0d4ZcUl5FkD/gDXgNbUDaB1Vi3I9bU+agwrsLoXrFWDpDPxrg +PGDV3grvqfEp7K2HvPl2B6mUQHYHbIZ9FgjRLRIjOzjMr33RkVtg2QrLaUiOlJ3r +i0xpWf2kMKDMej6M3vFP7PTacRHwqZMxZMWZ2WaviuC943pK0gWwUyJgkkYSrfql +LkzIq3DwKPUneuuInNS4bab8YjwuGYSd/Fnj11P8emTEHwkIIKFyH0LxO2JKw8tV +BosgExmS39P99tGjAOp4Qg1E00exl2mxtIiKI359DS3DYhjEhb5EDH1gVAh5GL2s +Y/NiI4VANomiuzkzCybVYaMwjRpaIkCKemXN0BXb8r7e3CLXn4BA3KHIpuZH4Yz7 +I6RpVuyTOrayM62czy9mxF64Pnwp0gRUJhWC3a2BTYXV5vAtW89BrFB7ArENUKGd +q81lUXVocAk/1LnMxy5fveS5yuUMxPM0fRBwzgARfyv+0HdsjzVmKZZKfjKPOjB5 +YWtOFtdFSdCzYnpIGyoPuUU34v8LuzRwMdBDrODb5LfvX3lMw7YvIkq5Ag0ETM+H +JwEQANOvLBAACFpbL82gr5fP0xfL/fG+oSrAqumUsXmxnCcxHOzDoEvExxebVnL+ +102IXIMV3eQqEaZuqcUYGBjkMt216u5btuSoSsVDrwRI8T3/9fXsB/jdvlCzsq7b +pImEFh7VDQc/jC21pP7r1G81Tt7zWB8oWYBbGXJMGsacaNg6449Z/0Ctp+gi+T5L +jIq1b9apD/+ucg9kGdlKFlLJ8zMwc77hG3LWkoli1cbLgYKk4RKahboFmoEVnM9S +ypdFfDZuSCB+7PvitjfqEao+fOCYOG0b3ykdcYXSVitFSnHe9T1DLjvKBy9qMtbA +GkdD61xEl0MtifQxKkya/n2Fg438HUeU7ltcFLlKd4XAzmsh9PXy2Gpj/lbNYpsD +DDMZafyfFfkLYYZasN4/+Ak+f5T1OuUqByIlesAPGReFtnUI+yXM9qEImProy+R5 +gNkBPN1AnNWvy2pi+ZUUI+35NW49uee35p5LNzMiP3hd2W+rDHWhE9y3oVFkpzbL +lXwF7AMQGtMNE6i82XfahDyiMRo9BzssTSdYc1+5OO+5buXWuZUibYmGc5yDQ6qv +0Yhlry4uoBMLJQcVCMkFh/os0gB4hgzI/MkhuEIYIBZcjGTzIzeGnB+0hB3ODiqt +LmrR2IiK56EkJ+UGfQ6Niankx+1M+OtSFXc9oWP4RacT8yaZABEBAAGJAh8EGAEC +AAkFAkzPhycCGwwACgkQDmn4CXEAOPW/3w//Wd3DfhQTXa1LoenNuuALnF9zIJQr +scLXc9HRO41x+0oCxi+ePDhCSiTWKWA4t74PsgLurdwXnQlcFU8rdSeWSalnO0gr +f0Rs+OHl4ICK3AWAgzZjFDh4J5Pyr7fVteGlUlKRgCCy/rGMwwSnCGLQYa9W1/ZE +KYZzLvFk0S/AoSv2iw6BxWUYVZVO7EzRzLoauLXQX6HyFyTpaH2soYbs1Xnp8t/u +w47PDnWXpYAaM0P1pD0T6krYp3M8YdNySGiXaZTkHBP2bj0PllGQHB/RjOyUrv95 +USYZj60O430OyvjlIBDq+BBL/ZLEbMdUIFJJ6WO1F1nIr8MowpTNqeEBpEaqOY6A +lV0j9fZWX2qJKIxQayq5OjfWL6Y7juJUuDBBZUzPtKSmcwGtg3HsCL0SWoz8JT4p +hPOXy4Zk1NMn4F4oIwRrGrcB2lmBaQmoBWBP63g5rObADL0wsyabfYuVRTE7PoSg +iCEN7wONrFjXrpB+WWG36d8nrETyMKALr96YL+1T4VNs0sllYbrkowRe2ioMKj9r +t61UPOGhPekw0HA7pDS1n+nGMMU+efLKKCvcKFKq/TDdjK2jPg1JQ1Xq8O4fDwRf +ibUXyvYwswAqOqQ0nHH5QSj9pov3tsXhJWWDVIWKMFhk+U1Sans9txHEQKJl8L5k +KiqgPxg3Tk50+6aZAg0ETM+LbwEQAN5ZRgD4sZJ6ClxoWjlmMM1c9632/isnzXJM +unkZeCA3gjx++uhZexCdSD36aQZ7dAFSwvrJLHRrjsszl/uc1H7FaBmkZ7E8sjNI +/oulUtMhcLe0TYy6MRSdl8aBqll4slZNfcl7iYk4PCmk2eR4sdMPMEsQC2kcglDW +HDeJfG0RozFgJ46QVRCktRWTrrACQcvuHLizl0+4nMZ76yexNre7Rrgo6kE5Mapl +0UXog6qM9ngV5cVxh2/wDex5fmXvB9uNTusEQIFo8qaZPBtapAAeoIShyUWispqi +kos5t410OzlGfBHsDb0cq4SU44bAXJmkZv/95JECEy8mZjsbywU4MCDjAf1lC4d9 +K7lcwHQS9rE2Xw1suXfD/VjQy9obpLLROk1DGLJC0aige0BbhMOa+mXgKVzSKcKv +PdmcUHcdm0dIy/LYZhC9Ja0uv37Sc9Ri55k3DU6DgdBu2dZgy7q9bBzLpqPIyTPs +XxUlczjhT6KxZYDeyghbwJYQ+miasY2VHeY9aZHYXXhDHIo2eEaut1y/9a7i4auA +aYnaADj/gmryBm6rb+r/MIMbfZ5htB4l6aoI/8BJygzq38LrWwUvzQ3p/N5+jA5N +uJWexAbG9hEc7nbbwINwp1b0P35eqSxhtr5wGdSNor5zScHazaPjPxHKP7WiATj8 +a1p0MlEHABEBAAG0PEFudG9pbmUgTGV2eS1MYW1iZXJ0IChDT0RFIFNJR05JTkcg +S0VZKSA8YW50b2luZUBhcGFjaGUub3JnPokCKwQTAQIAFQIbAwIeAQIXgAUCTM+M +LAUVCgkIAgAKCRBe+tn+gqf7zcwkEAC3VkVY4TGXoj3CDnjCL9nwkxAyK+JagXSw +7g8FMjqWW7YAIU8TprZxtOJUcnSXioVtT8dhKBfaasu34EpMrUYEIPNp5BNzhxIf +f9hXVrcuOZ1k0nJRlSc4IKSsrognoCDm340ma8AOMARVkrz7tXdqdlDPWVjMvqn/ +5/KReaIHQUNRqjypIIdM5mgaE41F1+uAyqLqcxvf4YQtu0NNGMizGZd37bH+5wMF +BT7S6CesAVPogcfnMdoMN1wO2yOzWKlg49U91DLUY3XHGOQnqVnTnVQ/xzLEj/vf +0PlLoY+3Yn9WEaonkMgco9un71xZ9s4DnR4WE+7QJYU2cgSPFB5DbAZ925qcNK/x +wOpKfRyBPN4zdjWE8Vjd25EcjZLsxgPiSlPpbyIJD6Ot61uoqekinNlAo44sleg8 +rNAAYnajlD/1La+Q/grQnHcujOt/w/ya3LG/cTpz7wkUhxhnmMwmxrVlEFaM24Qk +PwbQE/Wuwdvm/hYX5o4F1b7DQ9WepNZ4ahb/ztbsIg2my7JLN4RPDWZ++EMt5K6w +G+34vn8RfuSu4GHT8TAoexDsAEWzFo67F+dAosrvfw+HBBm3hNEz4tRkKP4SPqmo +dE8IXUffF+VFeFH0NLsvIwfpdW90XNxnSlnrc8aVpdvuE3qXqjQICo10LEJuxZRa +hNggNMtUNIkCfQQQAQIAZwUCTNK+FSEcRGFuIFBvaXJpZXIgPHBvaXJpZXJAYXBh +Y2hlLm9yZz4gHERhbiBQb2lyaWVyIDxwb2lyaWVyQHBvYm94LmNvbT4dHERhbiBQ +b2lyaWVyIDxkYW5AcG9pcmllci51cz4ACgkQnPorAWKylj8WUxAAmxx/NESLJp0r +A+fW8dQ08jGZ1Xf1laNCEd1eb6FXr/Z2xsKPFq6okBiiw6cm2wiwp7DBBHxQatyb +AJNLAGVg8wpHUPgUguFOY1LyLRZ9i2SKKmWG0jzQ7svWELxssHFUnMW8dwtk3qAb +o8pKvOKf4ol3qoKfN3Xq8ZBXAGkQaTIOJzGSfau+dH5NbhMcqZEoKGOAcOsLiIHZ +Cnos9KqFMxqBlTMyJWO9YP8dY3mGHUWV0gsYfE32bHM3auaA2Ynzxtor/jMBATeq +hTWjRAD1H92/HZ9vRBKwpHHpjsF+21aL9TZv5D2OmFYeN7/G1tyRcLYLrhDa7tnx +r5S/ePdypMZ2IUaC0umMKrc8ZrAtK/2N4ZmnHKoScCJHjup66cLCVVFGXHb2hEM9 +2fPFog2//s78Cw1DAxaNE4jjmR4QWXmQZUqA8AymIfgsi+nI9rWMWnpTCC6DGG9+ +j7GbIpPdRscqoyAiPl2lBpZerLirTa1GMuDqqGuNiv6YmEvxNVleOlPYCCQr1vY5 +ltJz34zckBNJAH/7woggqoyGiLa456ruDzU77qxUCy5ulFTOWsVtltojnlxgKBML +8f0uThQZN+0HydPb4uP3k5aLNL1ktiSo/XlIP2/AO69Bi4YZzERYsETm2zFLWx1P +MN+R0l/BAjRskTCX+H92fG5OkGjkmR+JAlwEEAECAEcFAkzS16tAHEpvc2VwaCBF +ZHdhcmQgQmVyZ21hcmsgKENPREUgU0lHTklORyBLRVkpIDxiZXJnbWFya0BhcGFj +aGUub3JnPgAKCRCw2ZG0fECHN8OVD/Y8+R4R9aNkuZJ76SCHOIhxjKtMhk44muAZ +FQwB+CG7HY4b/869+JdAOrwsOYr75h3vkz1vkU8FOr2LAu6PdiXDKpEs9wkPDGFx +Rg9yePaX2DbAh0Ch1ucR1FZvr3QqO+L0ri1lfUUl76n/QfZtHXfuoPgsYIjsbv6g +90mxHFJxxmowgX5gWKYaVm6OFN7xYiAC18Ia8LfReNIZO0XyaOq2/NoLuIVyguyi +C3RuVnvAk92/6YCPgZNiH1lN1kLmkoNvGpY6CFkCI9LKZ9xRCbs7Dbkoz7I+EYla +zfRf5mLjsrI+nVmFHvicvuw3ZtCCAImMdZ+Z53CHwd2N2v81lqnxUyCDPJf4Mxcw +Jq7Hf9hYZUBS9Ehj3nfCmJwOVUMrXYXurKinDAcyoYmlA2iqdzUdM3d9xFGjexsl +cUhZusggmOvBc3bK5BLZXUm009B5LYz4BGUAVsmN8vXekRgevszz5GcZBKElgRds +9DQaO4sbgrskq2TXHzBI7e9GiEcUyErZ8fdsbea5zrPoW2/x74Kq93VtQCuWPDOJ +Nq95l0J6bmiaVZuUTO5YIHFts7jphvA4gMf/4Lnzhzkcwftgi9OwyDBbpTyfdno+ +hsYBrBFQP4L7DLaGewHt46Iggil7Y9oMO0Yo7JtCsRnDtZYxc4rveg8vRg2xIl4y +NJlDNzNciQIcBBABCgAGBQJM0p5uAAoJEJrilv0C6fZbqooQAOpWpMdzXdmDG2fe +BffHiY2sabhX7B+tBRw+SIvmGw+ZvWvy3Tp2xFy7+PgCJhs/wbjyI3tCyx+DPb5C +ybZpDjferuhbKA/PVgnJozUhYtwLFQ7bRyvlLq3ZSZZawVn2bbIHn1knjohz+0hB +90zVX6vXhjPNZwL8vzPa3jMMNPDbd4E7w0VB63sWTKXq/pTy5SFGfscunxOsDMbj +KcW1VtSszH68aywefZV9DbmjSDEgNRiqwtj+WxD3rp3fARBO+4o5yIsjWu1wGL+n +59atHZJp34dAJFgOTJ2Jtykyuh3G76k4XKLemgUsu4aWFAlNIWt/f41cT5WmQe4z +YG4yWLE/KWpIc5Jn2p3wlQpKqwl/+F3pkOpqPZmZkYjn4ORCMg1Q0eOzfiaheofv +T78N0j8020z1lf5ojmEtGHoOzwz076Z3TGP256a4F37ZzibM7KFBn4iwjVrgqfFa +62Q5WG+q2rdmpQ5B2eXAYNxg66DiMcfR3zHJeMz3UpOZcygIUZ63N6VK7+WgNPtO +swBmXUxa5L35+a616/vvPtCEBlvJtDQz22BIvp/RpYaJ1k5K58uy0hj0oXZlD3q7 +BJSgPhgYOOqO79ZOwbgqGB9is5yegDXtXctV4FGuj601C+qtUHbRLmGio3XSMnmy +FCOJpZW41tJYo9uQz7dRHIzGsBpSiIAEEBECAEAFAkzTeLE5HEx1Y2lhbm8gUmVz +ZW5kZSAoQ29kZSBTaWduaW5nIEtleSkgPGxyZXNlbmRlQGFwYWNoZS5vcmc+AAoJ +EPOfGH3vtV3xs08AniczpMS0xOouROjBIHLC+RlBdMwAAJ0ZiOfPrr5+C9Glo317 +omxwZ0obvbkCDQRMz4tvARAAoqAcqn4cTgkAEACgeJQJoPKYAAyZwISGNTgqnnSr +BtN91af3XoVybrnXvlzFc6CkyWQ5T44yMaSfM/ZCYMpFCLtzssTlk3R8ASd7aIQR +/ydoB5vaPZ424NjSfsNLiF1NR868R8iFPHphegw3P2UeFT8rw/arcdJ5lXQ/J66p +63t9BlggU4piIMl/JPrtVawVLelYMYy3zw/RdnmrvU1qrZBGno5QkRhRlOXqQBTv +FlWVZT0GtC+lNha/MqEqW5YkACVPYqpmYk2aoNH5+Gj/yBpWap1o8GsVZKZQUMx6 +CPAT9GcTrOlFqFbFG1kL0iOQgOlggQ0Kba5LN1VXUl7ESsu7NYEXDqDdbjduVDMR +UsFrhTPUOf/kRNPjMPmGih0RP1s0woe3M4dsLaZEcAu88HHMCcaiOfBPAFU84upM +fEgh0BIcmTVwAaSftD5gzmZKY3YXfaS0cD6RaZBWuzecHNDLLEgzuhNbUtmtylx1 +X57tep9Mh2tKDFrqBxlhg3M73+mGdE6zgsWhgOeAMATII8mzM90zLh4bg9RBxdp+ +PnoJEbuZVdIX2bNJPt/u4LdAV/czozPjkZtZ60VSkEYyUnZ2dNKUOv5tujkY4dm1 +V+R9uR25C4fLopnE/AN26+GYePrbBaghEUh7ugg7HlTEXPz2JsfvpjPIaao0V1+A +bEUAEQEAAYkCHwQYAQIACQUCTM+LbwIbDAAKCRBe+tn+gqf7zYEvEACoszB5B68Z +QrcOBSWvk4l0xWLNfZQIl0M5WoNEoNj6Vt1CzIXadRFxHu1m0gnDLW3brquRuxTe +acho1iqinNw0pP7yODNW5p5ftKdvFlB7NNemVxzNZn1Q4cSkbI7GdYFiU9WQf7lB +TQpzFhjJSbJEMHtQrYOqw1wGNPZThEfNXwFLwe+0RF25gEQwuTkRdnpKarBeZiax +8zkuOmTLWmrI5Dq0dsYi6YotuHaSa3cFjGo+gp2cj+mBljaW8BXAIjzNunjMKqkV +XNA+Eh3w8FIx7NYZfrbDz4II3naYLb3x3IEwb6g7sTnCexFyTcS2RMJOqPBG2Zh6 +UI73B3AGkWDMsUyDMPVCVOEWUsT94tPBDZCrvdOpVu99OeMqESuaIuPELEbSIrsU +aDCyJDnIWVExk69szQl/4HOM+u9WBtSmG94WOCT7T+ypPcfFBPpUvxx6VriWKRQX +yKUlVCJVET4UpDHIwVUpIsmFmjxZfTlhe7pny8/a03/EnvGImuLYoxhfzP3VRapr +86fwCseMxAPW3gnl6zvGZrIM6ZS09tdyTIOiHUHMcXvWpyxdw+7EXHuncpEB5m0U +Ci8LBeDYqitVqqakgdKGAl8pfwaIJ9DsE5Sv/IHKFmieLa9PEh/2S/4hCD31atIK +3PimOFurhebU3wOU0wEkNb/3IYLk+MFQOA== +=1STU +-----END PGP PUBLIC KEY BLOCK----- diff --git a/lib/ant/WHATSNEW b/lib/ant/WHATSNEW index 4e925b78513e..0b6b9e5b42af 100644 --- a/lib/ant/WHATSNEW +++ b/lib/ant/WHATSNEW @@ -1,15 +1,295 @@ -Changes from Ant 1.8.1 TO current SVN version -============================================= +Changes from Ant 1.8.1 TO Ant 1.8.2 +=================================== Changes that could break older environments: ------------------------------------------- + * Prior to Ant 1.8.0 the task and several other tasks would + overwrite read-only destination files. Starting with 1.8.0 they + would only do so under special circumstances. Ant 1.8.2 now + consistently won't replace a read-only file by default. The same is + true for a number of other tasks. + The , and tasks now have a new force attribute + and has a new forceReadonly attribute that can be used to + make the task overwrite read-only destinations. + Bugzilla Report 49261. + + * Removed ant-nodeps.jar; it is now merged into ant.jar. + + * DOMElementWriter#encode used to employ special code before encoding + ampersands so that { remained { rather than being turned + into &#123;. This is no longer the case, ampersands will now + be encoded unconditionally. + Also DOMElementWriter#encodeData will treat CDATA sections containing a + literal "]]>" sequence different now - it will split the CDATA + section between the second "]" and ">" and create two sections. + This affects task as well as the XML logger or JUnit + formatter where ampersands will now always get encoded. + In addition DOMElementWriter will now replace the characters \t, \r + and \n in attribute values by entity references. + Bugzilla Report 49404. + + * The list elements returned by ProjectHelper#getExtensionStack are + now String arrays of length 3 rather than 2 in order to support the + onMissingExtensionPoint attribute. + Bugzilla Report 49473. + + * When using properties defined + inside the same file will only get used in expansions if the ${} + reference uses the same prefix. This is different from Ant 1.8.1 + but is the same behavior Ant 1.8.0 and earlier exhibited. + A new attribute prefixValues can be used to re-enable the behavior + of Ant 1.8.1. + Bugzilla Report 49373. + + * The files and directories used by Git, Mercurial and Bazaar to + store their information are now excluded by the defaultexcludes. + Bugzilla Report 49624. + + * The task no longer generates TestListener events - which + have been introduced in ant 1.7.0 - by default. The task has a new + attribute enableTestListenerEvents and a new "magic" property + ant.junit.enabletestlistenerevents has been added that can be used + to reinstate the old behavior. + Fixed bugs: ----------- + * hostinfo now prefers addresses with a hostname over addresses without + a hostname, provided the addresses have the same scope. + For local lookup, no IP address will be put in NAME / DOMAIN anymore. + For remote lookup, if a host name was provided and only an IP address is + found, the IP address will no longer overwrite the host name provided to the + task. + Bugzilla Report 49513 + + * mmap-based file copy problems under JDK 1.4 on Linux. + Bugzilla Report 49430. + + * The Sun JVM tries to mmap the entire file during a copy. + For large files this is not feasible. + We now explicitly request to copy at most 16 MiB per request. + Bugzilla Report 49326. + + * DemuxInputStream.read() should return unsigned values + Bugzilla Report 49279. + + * The MIME mailer ignored the port parameter when using SSL. + Bugzilla Report 49267. + + * ignored the classpath when using the default TraX processor. + Bugzilla Report 49271. + + * 's totalproperty only worked reliably if the same file + name didn't occur inside more than one directory. + Bugzilla Report 36748. + + * could fail to download files from remote subdirectories under + certain circumstances. + Bugzilla Report 49296. + + * will now produce better diagnostics when it fails to delete + a temporary file. + Bugzilla Report 49419. + + * Ant would often scan directories even though there were known to + only hold excluded files when evaluating filesets. This never + resulted in wrong results but degraded performance of the scan + itself. + Bugzilla Report 49420. + + * failed for long command lines on OS/2. + Bugzilla Report 49425. + + * did not handle encodings well for stdout/stderr. + Bugzilla Report 49418. + + * could issue a warning about multiple versions of Ant on the + CLASSPATH if two CLASSPATH entries differed in case on a + case-insensitive file system. + Bugzilla Report 49041. + + * The resource collection was checking every resource even if + we actually just want the first one, like in the example of use of + resourcelist in the documentation (getting the first available resource + from a mirror list). + + * A race condition could lead to build failures if multiple + tasks were trying to create the same directory. + Bugzilla Report 49572. + + * the toString() method of the Resources class - and thus any + ${toString:} expansion of a reference to a element - + didn't iterate over its nested elements if it hadn't done so prior + to the toString invocation already. + Bugzilla Report 49588. + + * in parallel mode didn't work together with a nested + if maxparallel was <= 0 (the default) or no source + files matched. + Bugzilla Report 49594. + + * didn't work for manifests added via + s that used the prefix or fullpath attributes. + Bugzilla Report 49605. + + * would cause an error unless the prefix + attribute has been specified. + Bugzilla Report 49755. + + * If forked, after finished was still reading the input stream + for a bunch of characters, then stealing them from a following . + Bugzilla Report 49119. + + * Ant could be leaking threads for each forked process (started by + , , or similar tasks) that didn't receive input + from a resource or string explicitly. + Bugzilla Report 49587. + + * Project#setDefault threw an exception when null was passed in as + argument, even though the Javadoc says null is a valid value. + Bugzilla Report 49803. + + * runant.py would swallow the first argument if CLASSPATH wasn't set. + Bugzilla Report 49963. + + * failed to load resources from jar files contained in a + directory that has a "!" in its name. + Bugzilla Report 50007. + + * ant.bat exit strategy improvements and issues + make the exit codes work in environments where 4NT or MKS are installed + Bugzilla Report 41039. + + * would fail if used via its Java API and the File passed + into the setJar method was not "normalized" (i.e. contained ".." + segments). + Bugzilla Report 50081. + + * ignored 's errorOnMissingDir attribute + Bugzilla Report 50124. + + * failed to close files when reading a list of symbolic + links from a properties file. + Bugzilla Report 50136. + + * could allow tasks to start executing even if a task + scheduled to run before them timed out. + Bugzilla Report 49527. + + * If a batch with multiple tests times out Ant logs a message + about a test named Batch-With-Multiple-Tests since 1.8.0 but the + logic that determined the Java package of this pseudo-test has been + wrong. + Bugzilla Report 45227. + + * didn't preserve the original linefeed style when + updating a file. + Bugzilla Report 50049. + + * 's whenEmpty behavior never consulted the non-fileset + resources so the task could fail even though resources have been + provided using non-fileset resource collections. + Bugzilla Issue 50115. + +* ftp chmod could throw a NPE. + Bugzilla report 50217. + +* The project help (-p option in the command line) will now print + the dependencies of the targets in debug mode (-d on the command + line) + Other changes: -------------- + * 's force attribute has been deprecated in favor of a new + overwrite attribute that is consistent with 's attribute + names. + + * You can now specify a list of methods to run in a JUnit test case. + Bugzilla Report 34748. + + * properties in files read because of the -propertyfile command line + option will now get resolved against other properties that are + defined before the project starts executing (those from the same or + earlier -propertfiles or defined via the -D option). + Bugzilla Report 18732. + + * s can now contain wildcards in order to use wildcard + CLASSPATH entries introduced with Java6. + The wildcards are not expanded or even evaluated by Ant and will be + used literally. The resulting path may be unusable as a CLASSPATH + for Java versions prior to Java6 and likely doesn't mean anything + when used in any other way than a CLASSPATH for a forked Java VM. + Bugzilla Report 46842. + + * A new attribute allows targets to deal with nonexistent extension + points, i.e. they can extend an extension-point if it has been + defined or silently work as plain targets if it hasn't. This is + useful for targets that get included/imported in different + scenarios where a given extension-point may or may not exist. + Bugzilla Report 49473. + + * Ant now logs a warning message if it fails to change the file + modification time in for example when using or preserving + timestamps in various tasks. + Bugzilla Report 49485. + + * ProjectHelpers can now be installed dynamically via the + Ant task. + + * is now able to switch to the proper ProjectHelper to parse + the imported resource. This means that several kinds of different build + files can import each other. + + * now also works for non-filesystem resources. + Bugzilla Report 49756. + + * The filter now supports a casesensitive + attribute. + + * The selector now supports casesensitive, multiline + and singleline attributes. + Bugzilla Report 49764. + + * A new can be used like wget's --cut-dirs option to + strip leading directories from file names. + + * now supports the GNU project's gcjh compiler. + Bugzilla Report 50149. + + * supports additional views of a file's path as elements + for a custom pattern. + Bugzilla Report 50114. + + * JUnit XMLResultAggregator logs the stack trace of caught IO exceptions + in verbose runs. + Bugzilla Report 48836. + + * StringUtils.parseHumanSizes() should turn parse failures into + BuildExceptions. + Bugzilla Report 48835. + + * New task to make a list of targets bound to some + specified extension point. + + * Initial support for OpenJDK7 has been added. + + * Ant now uses java.net.CookieStore rather than + java.util.ServiceLocator to detect whether the environment is a + Java 1.6 system. This means releases of gcj/gij at the time of + this release of Ant are detected as Java 1.5 and not 1.6. + Bugzilla Report 50256. + + * It is now possible to write a compiler adapter for that + compiles sources with extensions other than .java (but that still + compile to .class files). + Bugzilla Report 48829. + + * The performance of VectorSet#add(Object) has been improved which + should also benefit any operation that scans directories in Ant. + Bugzilla Report 50200. + Changes from Ant 1.8.0 TO Ant 1.8.1 =================================== diff --git a/lib/ant/docs.zip b/lib/ant/docs.zip index d40f9ab6840d..80d4d53196e5 100644 Binary files a/lib/ant/docs.zip and b/lib/ant/docs.zip differ diff --git a/lib/ant/fetch.xml b/lib/ant/fetch.xml index cde04b719d05..d0628d283fce 100644 --- a/lib/ant/fetch.xml +++ b/lib/ant/fetch.xml @@ -60,6 +60,10 @@ + + + + @@ -99,9 +103,10 @@ Set -Ddest=LOCATION on the command line + - Unknown archive @{archive} -no property @{archive}.version defined. + Unknown archive @{archive} -no property @{archive}.version defined in ${lib.dir}/libraries.properties. @@ -112,6 +117,7 @@ Set -Ddest=LOCATION on the command line + @@ -123,11 +129,71 @@ Set -Ddest=LOCATION on the command line + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -153,16 +219,12 @@ Set -Ddest=LOCATION on the command line - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + depends="logging,junit,xml,networking,regexp,antlr,bcel,jdepend,bsf,debugging,script,javamail,jspc,jai,netrexx" /> diff --git a/lib/ant/lib/ant-antlr.jar b/lib/ant/lib/ant-antlr.jar index c77044607761..7d32582fbd41 100644 Binary files a/lib/ant/lib/ant-antlr.jar and b/lib/ant/lib/ant-antlr.jar differ diff --git a/lib/ant/lib/ant-antlr.pom b/lib/ant/lib/ant-antlr.pom index de47ce9de9c7..9f429e9bc431 100644 --- a/lib/ant/lib/ant-antlr.pom +++ b/lib/ant/lib/ant-antlr.pom @@ -27,19 +27,20 @@ org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-antlr - 1.8.1 + 1.8.2 + Apache Ant + ANTLR antlr specific task. The implementation forks a java process, therefore the antlr jar file is only needed at runtime org.apache.ant ant - 1.8.1 + 1.8.2 true compile diff --git a/lib/ant/lib/ant-apache-bcel.jar b/lib/ant/lib/ant-apache-bcel.jar index bcee75c27e2b..04f82d72ec87 100644 Binary files a/lib/ant/lib/ant-apache-bcel.jar and b/lib/ant/lib/ant-apache-bcel.jar differ diff --git a/lib/ant/lib/ant-apache-bcel.pom b/lib/ant/lib/ant-apache-bcel.pom index ec838901201e..59458775cb28 100644 --- a/lib/ant/lib/ant-apache-bcel.pom +++ b/lib/ant/lib/ant-apache-bcel.pom @@ -27,17 +27,18 @@ org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-apache-bcel - 1.8.1 + 1.8.2 + Apache Ant + BCEL org.apache.ant ant - 1.8.1 + 1.8.2 compile @@ -56,8 +57,8 @@ 1.4 1.4 - org/apache/tools/ant/tfilters/util/JavaClassHelper* - org/apache/tools/ant/tutil/depend/bcel/* + org/apache/tools/ant/filters/util/JavaClassHelper* + org/apache/tools/ant/util/depend/bcel/* diff --git a/lib/ant/lib/ant-apache-bsf.jar b/lib/ant/lib/ant-apache-bsf.jar index 29914d09d1a6..2e75648289d8 100644 Binary files a/lib/ant/lib/ant-apache-bsf.jar and b/lib/ant/lib/ant-apache-bsf.jar differ diff --git a/lib/ant/lib/ant-apache-bsf.pom b/lib/ant/lib/ant-apache-bsf.pom index 31c01726104e..d0cc88f0d4a6 100644 --- a/lib/ant/lib/ant-apache-bsf.pom +++ b/lib/ant/lib/ant-apache-bsf.pom @@ -27,17 +27,18 @@ org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-apache-bsf - 1.8.1 + 1.8.2 + Apache Ant + BSF org.apache.ant ant - 1.8.1 + 1.8.2 compile diff --git a/lib/ant/lib/ant-apache-log4j.jar b/lib/ant/lib/ant-apache-log4j.jar index b520d3e1cfbf..78c2133cf65f 100644 Binary files a/lib/ant/lib/ant-apache-log4j.jar and b/lib/ant/lib/ant-apache-log4j.jar differ diff --git a/lib/ant/lib/ant-apache-log4j.pom b/lib/ant/lib/ant-apache-log4j.pom index d5b15b703eb2..00f8b63de3c9 100644 --- a/lib/ant/lib/ant-apache-log4j.pom +++ b/lib/ant/lib/ant-apache-log4j.pom @@ -26,17 +26,18 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-apache-log4j - 1.8.1 + 1.8.2 + Apache Ant + Log4J org.apache.ant ant - 1.8.1 + 1.8.2 compile diff --git a/lib/ant/lib/ant-apache-oro.jar b/lib/ant/lib/ant-apache-oro.jar index af1040383d7c..497814810e0b 100644 Binary files a/lib/ant/lib/ant-apache-oro.jar and b/lib/ant/lib/ant-apache-oro.jar differ diff --git a/lib/ant/lib/ant-apache-oro.pom b/lib/ant/lib/ant-apache-oro.pom index 559e5046c105..40324a6c1805 100644 --- a/lib/ant/lib/ant-apache-oro.pom +++ b/lib/ant/lib/ant-apache-oro.pom @@ -27,17 +27,18 @@ org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-apache-oro - 1.8.1 + 1.8.2 + Apache Ant + Apache Oro org.apache.ant ant - 1.8.1 + 1.8.2 compile @@ -59,6 +60,9 @@ org/apache/tools/ant/util/regexp/JakartaOro* org/apache/tools/ant/taskdefs/optional/perforce/* + + org/apache/tools/ant/taskdefs/optional/perforce/* + diff --git a/lib/ant/lib/ant-apache-regexp.jar b/lib/ant/lib/ant-apache-regexp.jar index ccd661722854..dfedea307a77 100644 Binary files a/lib/ant/lib/ant-apache-regexp.jar and b/lib/ant/lib/ant-apache-regexp.jar differ diff --git a/lib/ant/lib/ant-apache-regexp.pom b/lib/ant/lib/ant-apache-regexp.pom index fa6a1b77eb5e..e8f746921df5 100644 --- a/lib/ant/lib/ant-apache-regexp.pom +++ b/lib/ant/lib/ant-apache-regexp.pom @@ -26,17 +26,18 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-apache-regexp - 1.8.1 + 1.8.2 + Apache Ant + Apache Regexp org.apache.ant ant - 1.8.1 + 1.8.2 compile diff --git a/lib/ant/lib/ant-apache-resolver.jar b/lib/ant/lib/ant-apache-resolver.jar index 38293dbc362b..ed8004eb203d 100644 Binary files a/lib/ant/lib/ant-apache-resolver.jar and b/lib/ant/lib/ant-apache-resolver.jar differ diff --git a/lib/ant/lib/ant-apache-resolver.pom b/lib/ant/lib/ant-apache-resolver.pom index d82ea8cb8f58..b999b5040e21 100644 --- a/lib/ant/lib/ant-apache-resolver.pom +++ b/lib/ant/lib/ant-apache-resolver.pom @@ -26,17 +26,18 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-apache-resolver - 1.8.1 + 1.8.2 + Apache Ant + Apache Resolver org.apache.ant ant - 1.8.1 + 1.8.2 compile diff --git a/lib/ant/lib/ant-apache-xalan2.jar b/lib/ant/lib/ant-apache-xalan2.jar index 2b20089d3c32..91376a3e7c0a 100644 Binary files a/lib/ant/lib/ant-apache-xalan2.jar and b/lib/ant/lib/ant-apache-xalan2.jar differ diff --git a/lib/ant/lib/ant-apache-xalan2.pom b/lib/ant/lib/ant-apache-xalan2.pom index cd3b8aaff4eb..cad6f4f47fc9 100644 --- a/lib/ant/lib/ant-apache-xalan2.pom +++ b/lib/ant/lib/ant-apache-xalan2.pom @@ -26,24 +26,19 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-apache-xalan2 - 1.8.1 + 1.8.2 + Apache Ant + Xalan 2 contains Xalan2-specific features org.apache.ant ant - 1.8.1 - compile - - - org.apache.ant - ant-nodeps - 1.8.1 + 1.8.2 compile diff --git a/lib/ant/lib/ant-commons-logging.jar b/lib/ant/lib/ant-commons-logging.jar index aa7cdbe2c7dc..b7e1dee62a75 100644 Binary files a/lib/ant/lib/ant-commons-logging.jar and b/lib/ant/lib/ant-commons-logging.jar differ diff --git a/lib/ant/lib/ant-commons-logging.pom b/lib/ant/lib/ant-commons-logging.pom index a76c0f1374e3..e57ddf957951 100644 --- a/lib/ant/lib/ant-commons-logging.pom +++ b/lib/ant/lib/ant-commons-logging.pom @@ -26,18 +26,19 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-commons-logging - 1.8.1 + 1.8.2 + Apache Ant + Commons Logging Ant Listener based on commons-logging org.apache.ant ant - 1.8.1 + 1.8.2 compile diff --git a/lib/ant/lib/ant-commons-net.jar b/lib/ant/lib/ant-commons-net.jar index fc26e28403e6..25b7fe6ef1f2 100644 Binary files a/lib/ant/lib/ant-commons-net.jar and b/lib/ant/lib/ant-commons-net.jar differ diff --git a/lib/ant/lib/ant-commons-net.pom b/lib/ant/lib/ant-commons-net.pom index 1f16da7440d7..3da389eab4f4 100644 --- a/lib/ant/lib/ant-commons-net.pom +++ b/lib/ant/lib/ant-commons-net.pom @@ -26,18 +26,19 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-commons-net - 1.8.1 + 1.8.2 + Apache Ant + Commons Net ftp, rexec and telnet tasks org.apache.ant ant - 1.8.1 + 1.8.2 compile @@ -60,6 +61,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org/apache/tools/ant/taskdefs/optional/net/RExec* org/apache/tools/ant/taskdefs/optional/net/TelnetTask* + + org/apache/tools/ant/taskdefs/optional/net/FTP* + diff --git a/lib/ant/lib/ant-jai.jar b/lib/ant/lib/ant-jai.jar index 3b3155798e9a..613adaf4bf14 100644 Binary files a/lib/ant/lib/ant-jai.jar and b/lib/ant/lib/ant-jai.jar differ diff --git a/lib/ant/lib/ant-jai.pom b/lib/ant/lib/ant-jai.pom index ce0130f3dff4..fc77323cb0e6 100644 --- a/lib/ant/lib/ant-jai.pom +++ b/lib/ant/lib/ant-jai.pom @@ -27,36 +27,40 @@ org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-jai - 1.8.1 + 1.8.2 + Apache Ant + JAI image task and corresponding types. - jai (Java Advanced Imaging) is not available in public Maven repositories, therefore the dependencies are included with a scope provided - the download URL is http://java.sun.com/products/java-media/jai/ org.apache.ant ant - 1.8.1 + 1.8.2 compile javax.media jai-core - 1.1.2_01 - provided + 1.1.3 - jai + com.sun.media jai-codec - 1.1.2.1 - provided + 1.1.3 + + + jboss + JBoss + http://repository.jboss.org/maven2/ + + diff --git a/lib/ant/lib/ant-javamail.jar b/lib/ant/lib/ant-javamail.jar index 2e0c75d1ae38..7ac7755dd869 100644 Binary files a/lib/ant/lib/ant-javamail.jar and b/lib/ant/lib/ant-javamail.jar differ diff --git a/lib/ant/lib/ant-javamail.pom b/lib/ant/lib/ant-javamail.pom index 53df6292cc98..bfb93ef55146 100644 --- a/lib/ant/lib/ant-javamail.pom +++ b/lib/ant/lib/ant-javamail.pom @@ -26,12 +26,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-javamail - 1.8.1 + 1.8.2 + Apache Ant + JavaMail implementation of the mail task based on javamail. Required to send emails to SMTP servers using user/password combinations or to send mail over SSL @@ -39,7 +40,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org.apache.ant ant - 1.8.1 + 1.8.2 compile diff --git a/lib/ant/lib/ant-jdepend.jar b/lib/ant/lib/ant-jdepend.jar index 803542b3821a..9ff68d04b87a 100644 Binary files a/lib/ant/lib/ant-jdepend.jar and b/lib/ant/lib/ant-jdepend.jar differ diff --git a/lib/ant/lib/ant-jdepend.pom b/lib/ant/lib/ant-jdepend.pom index ad8c94c4d2e6..d585e4b74f07 100644 --- a/lib/ant/lib/ant-jdepend.pom +++ b/lib/ant/lib/ant-jdepend.pom @@ -27,19 +27,20 @@ org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-jdepend - 1.8.1 + 1.8.2 + Apache Ant + JDepend task jdepend invoking the jdepend parser. There is also a version 2.9.1 of the jdepend parser available on the maven repository org.apache.ant ant - 1.8.1 + 1.8.2 compile diff --git a/lib/ant/lib/ant-jmf.jar b/lib/ant/lib/ant-jmf.jar index 227450e4115a..01365c2b910b 100644 Binary files a/lib/ant/lib/ant-jmf.jar and b/lib/ant/lib/ant-jmf.jar differ diff --git a/lib/ant/lib/ant-jmf.pom b/lib/ant/lib/ant-jmf.pom index b9e1a2341ee1..758a2934bc8b 100644 --- a/lib/ant/lib/ant-jmf.pom +++ b/lib/ant/lib/ant-jmf.pom @@ -26,27 +26,22 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-jmf - 1.8.1 + 1.8.2 + Apache Ant + JMF contains the sound task and a soundplayer listener download the dependency from http://java.sun.com/products/java-media/jmf/ org.apache.ant ant - 1.8.1 + 1.8.2 compile - - javax.media - jmf - 2.1.1e - provided - diff --git a/lib/ant/lib/ant-jsch.jar b/lib/ant/lib/ant-jsch.jar index f0d1f65c53ad..59f5fd1e9b23 100644 Binary files a/lib/ant/lib/ant-jsch.jar and b/lib/ant/lib/ant-jsch.jar differ diff --git a/lib/ant/lib/ant-jsch.pom b/lib/ant/lib/ant-jsch.pom index 14bb8e76361c..39e0d161e097 100644 --- a/lib/ant/lib/ant-jsch.pom +++ b/lib/ant/lib/ant-jsch.pom @@ -26,19 +26,20 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-jsch - 1.8.1 + 1.8.2 + Apache Ant + JSch contains the sshexec and scp tasks jsch 0.1.29 might not be available from maven org.apache.ant ant - 1.8.1 + 1.8.2 compile @@ -59,6 +60,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org/apache/tools/ant/taskdefs/optional/ssh/* + + org/apache/tools/ant/taskdefs/optional/ssh/* + diff --git a/lib/ant/lib/ant-junit.jar b/lib/ant/lib/ant-junit.jar index 7028e3c77d21..d2b1665bd4cc 100644 Binary files a/lib/ant/lib/ant-junit.jar and b/lib/ant/lib/ant-junit.jar differ diff --git a/lib/ant/lib/ant-junit.pom b/lib/ant/lib/ant-junit.pom index 05a3a95630e7..f90adc1a1746 100644 --- a/lib/ant/lib/ant-junit.pom +++ b/lib/ant/lib/ant-junit.pom @@ -26,18 +26,19 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-junit - 1.8.1 + 1.8.2 + Apache Ant + JUnit contains the junit and junirreport tasks org.apache.ant ant - 1.8.1 + 1.8.2 compile @@ -82,6 +83,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org/apache/tools/ant/taskdefs/optional/junit/* + + org/apache/tools/ant/taskdefs/optional/junit/JUnit4TestMethodAdapter* + + + org/apache/tools/ant/taskdefs/optional/junit/ + diff --git a/lib/ant/lib/ant-launcher.jar b/lib/ant/lib/ant-launcher.jar index fe48213ac14c..939abb57975f 100644 Binary files a/lib/ant/lib/ant-launcher.jar and b/lib/ant/lib/ant-launcher.jar differ diff --git a/lib/ant/lib/ant-launcher.pom b/lib/ant/lib/ant-launcher.pom index 3751b18c3e85..5015839e25dd 100644 --- a/lib/ant/lib/ant-launcher.pom +++ b/lib/ant/lib/ant-launcher.pom @@ -27,12 +27,13 @@ org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-launcher - 1.8.1 + 1.8.2 + Apache Ant Launcher diff --git a/lib/ant/lib/ant-netrexx.jar b/lib/ant/lib/ant-netrexx.jar index 903d6224edf2..6d38a989a7aa 100644 Binary files a/lib/ant/lib/ant-netrexx.jar and b/lib/ant/lib/ant-netrexx.jar differ diff --git a/lib/ant/lib/ant-netrexx.pom b/lib/ant/lib/ant-netrexx.pom index 2dacde9aa9e2..564282f2e401 100644 --- a/lib/ant/lib/ant-netrexx.pom +++ b/lib/ant/lib/ant-netrexx.pom @@ -26,27 +26,31 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-netrexx - 1.8.1 + 1.8.2 + Apache Ant + NetRexx NetRexxC task dependency can be downloaded from http://www.ibm.com/software/awdtools/netrexx/download.html org.apache.ant ant - 1.8.1 + 1.8.2 compile + @@ -59,8 +63,32 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma org/apache/tools/ant/taskdefs/optional/NetRexxC* + + + ${basedir}/../../../../lib/optional + + + org.apache.maven.plugins + maven-antrun-plugin + 1.4 + + + validate + + + + + + + + + run + + + + ../../../../src/main ../../../../src/testcases diff --git a/lib/ant/lib/ant-nodeps.jar b/lib/ant/lib/ant-nodeps.jar deleted file mode 100644 index 9314502f8c2b..000000000000 Binary files a/lib/ant/lib/ant-nodeps.jar and /dev/null differ diff --git a/lib/ant/lib/ant-nodeps.pom b/lib/ant/lib/ant-nodeps.pom deleted file mode 100644 index 5a548ede2887..000000000000 --- a/lib/ant/lib/ant-nodeps.pom +++ /dev/null @@ -1,94 +0,0 @@ - - - - - - org.apache.ant - ant-parent - ../pom.xml - 1.8.1 - - 4.0.0 - org.apache.ant - ant-nodeps - 1.8.1 - contains all the optional tasks and types which do not have particular dependencies - - - org.apache.ant - ant - 1.8.1 - compile - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.4 - 1.4 - - org/apache/tools/ant/taskdefs/optional/** - org/apache/tools/ant/types/optional/** - org/apache/tools/ant/util/depend/* - org/apache/tools/ant/util/optional/** - org/apache/tools/ant/util/java15/** - org/apache/tools/ant/util/regexp/Jdk14Regexp* - - - org/apache/tools/ant/taskdefs/optional/Xalan2TraceSupport* - org/apache/tools/ant/taskdefs/optional/junit/** - org/apache/tools/ant/taskdefs/optional/perforce/** - org/apache/tools/ant/taskdefs/optional/Script* - org/apache/tools/ant/taskdefs/optional/script/** - org/apache/tools/ant/util/optional/Script* - org/apache/tools/ant/types/optional/*Script* - org/apache/tools/ant/taskdefs/optional/NetRexxC* - org/apache/tools/ant/taskdefs/optional/ejb/Ejbc* - org/apache/tools/ant/taskdefs/optional/ejb/DDCreator* - org/apache/tools/ant/taskdefs/optional/net/Telnet* - org/apache/tools/ant/taskdefs/optional/net/FTP* - org/apache/tools/ant/taskdefs/optional/net/RExec* - org/apache/tools/ant/taskdefs/optional/scm/AntStarTeam* - org/apache/tools/ant/taskdefs/optional/ANTLR* - org/apache/tools/ant/taskdefs/optional/sound/* - org/apache/tools/ant/taskdefs/optional/image/* - org/apache/tools/ant/types/optional/image/* - org/apache/tools/ant/taskdefs/optional/jdepend/* - org/apache/tools/ant/taskdefs/optional/splash/* - org/apache/tools/ant/taskdefs/optional/ssh/* - - - - - - ../../../../src/main - ../../../../src/testcases - ../../../../target/ant-nodeps/classes - ../../../../target/ant-nodeps/testcases - ../../../../target/ant-nodeps - - diff --git a/lib/ant/lib/ant-parent.pom b/lib/ant/lib/ant-parent.pom index 50c200235de4..af8ceb2c6a8b 100644 --- a/lib/ant/lib/ant-parent.pom +++ b/lib/ant/lib/ant-parent.pom @@ -25,14 +25,22 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma 4.0.0 org.apache.ant ant-parent - 1.8.1 + 1.8.2 pom master POM + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + Apache Ant http://ant.apache.org/ 2000 - Apache Software Foundation + The Apache Software Foundation + http://www.apache.org/ @@ -44,9 +52,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma scm:svn:http://svn.apache.org/repos/asf/ant/core/trunk - scm:svn:https://svn.apache.org/repos/asf/jant/core/trunk + scm:svn:https://svn.apache.org/repos/asf/ant/core/trunk http://svn.apache.org/repos/asf/ant/core/trunk + + hudson + https://hudson.apache.org/hudson/job/Ant_BuildFromPOMs/ + Ant Developers List @@ -85,9 +97,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma ant-jmf ant-jsch ant-junit + ant-junit4 ant-launcher ant-netrexx - ant-nodeps ant-swing ant-testutil diff --git a/lib/ant/lib/ant-swing.jar b/lib/ant/lib/ant-swing.jar index bff774d5cde5..0069327bd56a 100644 Binary files a/lib/ant/lib/ant-swing.jar and b/lib/ant/lib/ant-swing.jar differ diff --git a/lib/ant/lib/ant-swing.pom b/lib/ant/lib/ant-swing.pom index 43af4b774f3c..a8c77bf6120b 100644 --- a/lib/ant/lib/ant-swing.pom +++ b/lib/ant/lib/ant-swing.pom @@ -27,18 +27,19 @@ org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-swing - 1.8.1 + 1.8.2 + Apache Ant + Swing a listener and a splash task based on Swing org.apache.ant ant - 1.8.1 + 1.8.2 compile diff --git a/lib/ant/lib/ant-testutil.jar b/lib/ant/lib/ant-testutil.jar index dd8f880797b0..cc73c8d31f62 100644 Binary files a/lib/ant/lib/ant-testutil.jar and b/lib/ant/lib/ant-testutil.jar differ diff --git a/lib/ant/lib/ant-testutil.pom b/lib/ant/lib/ant-testutil.pom index dfe09e6395ea..d7f967df4798 100644 --- a/lib/ant/lib/ant-testutil.pom +++ b/lib/ant/lib/ant-testutil.pom @@ -27,18 +27,19 @@ org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant-testutil - 1.8.1 + 1.8.2 + Apache Ant Test Utilities test utility classes org.apache.ant ant - 1.8.1 + 1.8.2 compile diff --git a/lib/ant/lib/ant.jar b/lib/ant/lib/ant.jar index bac289cdc465..7f5be4a4e059 100644 Binary files a/lib/ant/lib/ant.jar and b/lib/ant/lib/ant.jar differ diff --git a/lib/ant/lib/ant.pom b/lib/ant/lib/ant.pom index 3c9fd4523f87..8854149dc332 100644 --- a/lib/ant/lib/ant.pom +++ b/lib/ant/lib/ant.pom @@ -27,19 +27,18 @@ org.apache.ant ant-parent ../pom.xml - 1.8.1 + 1.8.2 4.0.0 org.apache.ant ant - 1.8.1 - org.apache.tools.ant - Apache Ant + 1.8.2 + Apache Ant Core org.apache.ant ant-launcher - 1.8.1 + 1.8.2 compile @@ -93,27 +92,36 @@ 1.4 1.4 - org/apache/tools/ant/taskdefs/optional/** org/apache/tools/ant/filters/util/JavaClassHelper* - org/apache/tools/ant/types/optional/** org/apache/tools/ant/types/resolver/** - org/apache/tools/ant/util/ScriptRunner.java - org/apache/tools/ant/util/depend/** - org/apache/tools/ant/util/optional/** org/apache/tools/ant/listener/Log4jListener* org/apache/tools/ant/listener/CommonsLoggingListener* org/apache/tools/ant/util/regexp/JakartaRegexp* org/apache/tools/ant/util/regexp/JakartaOro* org/apache/tools/ant/taskdefs/email/MimeMailer* org/apache/tools/ant/launch/** + org/apache/tools/ant/taskdefs/optional/net/FTP* + org/apache/tools/ant/taskdefs/optional/net/RExec* + org/apache/tools/ant/taskdefs/optional/net/TelnetTask* + org/apache/tools/ant/taskdefs/optional/perforce/* + org/apache/tools/ant/taskdefs/optional/junit/* + org/apache/tools/ant/taskdefs/optional/ssh/* + org/apache/tools/ant/taskdefs/optional/image/* + org/apache/tools/ant/types/optional/image/* + org/apache/tools/ant/taskdefs/optional/Script* + org/apache/tools/ant/taskdefs/optional/script/** + org/apache/tools/ant/types/optional/*Script* + org/apache/tools/ant/util/ScriptRunner.java + org/apache/tools/ant/util/optional/ScriptRunner.java + org/apache/tools/ant/filters/util/JavaClassHelper* + org/apache/tools/ant/util/depend/bcel/* + org/apache/tools/ant/taskdefs/optional/NetRexxC* + org/apache/tools/ant/taskdefs/optional/Xalan2TraceSupport* + org/apache/tools/ant/taskdefs/optional/jdepend/* - org/apache/tools/ant/taskdefs/optional/** org/apache/tools/ant/filters/util/JavaClassHelper* - org/apache/tools/ant/types/optional/** org/apache/tools/ant/types/resolver/** - org/apache/tools/ant/util/depend/** - org/apache/tools/ant/util/optional/** org/apache/tools/ant/util/Script* org/apache/tools/ant/listener/Log4jListener* org/apache/tools/ant/listener/CommonsLoggingListener* @@ -123,6 +131,10 @@ org/apache/tools/ant/taskdefs/email/MimeMailer* org/apache/tools/ant/launch/** org/apache/tools/ant/taskdefs/StyleTest* + org/apache/tools/ant/taskdefs/optional/junit/ + org/apache/tools/ant/taskdefs/optional/net/FTP* + org/apache/tools/ant/taskdefs/optional/ssh/* + org/apache/tools/ant/taskdefs/optional/perforce/* diff --git a/lib/ant/lib/libraries.properties b/lib/ant/lib/libraries.properties index 226adb0e99c0..3e948f6fc889 100644 --- a/lib/ant/lib/libraries.properties +++ b/lib/ant/lib/libraries.properties @@ -26,6 +26,8 @@ m2.antlib.url=${m2.url}/org/apache/maven/${m2.artifact-name}/${m2.version}/${m2. #this is the sha1 checksum of the artifact m2.sha1.checksum=4e7ddfdb91600e9b59bb965ff8eef2f06015df50 +# Repository to use by default for fetching dependencies. +m2.repo=http://repo1.maven.org/maven2/ #versions of different libraries. Please keep in alphabetical order, except #when a specific dependency forces them to be out-of-order @@ -37,11 +39,13 @@ bsh-core.version=${bsh.version} commons-net.version=1.4.1 commons-logging.version=1.1 commons-logging-api.version=${commons-logging.version} +jai-core.version=1.1.3 +jai-codec.version=1.1.3 jasper-compiler.version=4.1.36 jasper-runtime.version=${jasper-compiler.version} jdepend.version=2.9.1 jruby.version=0.9.8 -junit.version=3.8.2 +junit.version=4.8.1 jsch.version=0.1.42 jython.version=2.1 #log4j 1.2.15 requires JMS and a few other Sun jars that are not in the m2 repo diff --git a/lib/ant/src/bundled_ant_src.zip b/lib/ant/src/bundled_ant_src.zip index 8a5ff857f423..2a0e7479f4be 100644 Binary files a/lib/ant/src/bundled_ant_src.zip and b/lib/ant/src/bundled_ant_src.zip differ diff --git a/platform/lang-api/src/com/intellij/psi/stubs/DefaultStubBuilder.java b/platform/lang-api/src/com/intellij/psi/stubs/DefaultStubBuilder.java index c6b845a66729..a22f13351f35 100644 --- a/platform/lang-api/src/com/intellij/psi/stubs/DefaultStubBuilder.java +++ b/platform/lang-api/src/com/intellij/psi/stubs/DefaultStubBuilder.java @@ -22,6 +22,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.StubBasedPsiElement; import com.intellij.psi.StubBuilder; import com.intellij.psi.tree.IElementType; +import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -31,73 +32,94 @@ import org.jetbrains.annotations.Nullable; public class DefaultStubBuilder implements StubBuilder { private static final Logger LOG = Logger.getInstance("#com.intellij.psi.stubs.DefaultStubBuilder"); - public StubElement buildStubTree(final PsiFile file) { + public StubElement buildStubTree(@NotNull PsiFile file) { return buildStubTreeFor(file, createStubForFile(file)); } - protected StubElement createStubForFile(final PsiFile file) { + protected StubElement createStubForFile(@NotNull PsiFile file) { + //noinspection unchecked return new PsiFileStubImpl(file); } - private StubElement buildStubTreeFor(@NotNull PsiElement elt, StubElement parentStub) { - StubElement stub = parentStub; - if (elt instanceof StubBasedPsiElement) { - final IStubElementType type = ((StubBasedPsiElement)elt).getElementType(); + private StubElement buildStubTreeFor(@NotNull PsiElement root, @NotNull StubElement parentStub) { + Stack parentStubs = new Stack(); + Stack parentElements = new Stack(); + parentElements.push(root); + parentStubs.push(parentStub); - if (type.shouldCreateStub(elt.getNode())) { - //noinspection unchecked - stub = type.createStub(elt, parentStub); + while (!parentElements.isEmpty()) { + StubElement stub = parentStubs.pop(); + PsiElement elt = parentElements.pop(); + + if (elt instanceof StubBasedPsiElement) { + final IStubElementType type = ((StubBasedPsiElement)elt).getElementType(); + + if (type.shouldCreateStub(elt.getNode())) { + //noinspection unchecked + stub = type.createStub(elt, stub); + } + } + else { + final ASTNode node = elt.getNode(); + final IElementType type = node == null? null : node.getElementType(); + if (type instanceof IStubElementType && ((IStubElementType)type).shouldCreateStub(node)) { + LOG.error("Non-StubBasedPsiElement requests stub creation. Stub type: " + type + ", PSI: " + elt); + } + } + + for (PsiElement child = elt.getLastChild(); child != null; child = child.getPrevSibling()) { + if (!skipChildProcessingWhenBuildingStubs(elt, child)) { + parentStubs.push(stub); + parentElements.push(child); + } } } - else { - final ASTNode node = elt.getNode(); - final IElementType type = node == null? null : node.getElementType(); - if (type instanceof IStubElementType && ((IStubElementType)type).shouldCreateStub(node)) { - LOG.error("Non-StubBasedPsiElement requests stub creation. Stub type: " + type + ", PSI: " + elt); - } - } - - for (PsiElement child = elt.getFirstChild(); child != null; child = child.getNextSibling()) { - if (!skipChildProcessingWhenBuildingStubs(elt, child)) { - buildStubTreeFor(child, stub); - } - } - - return stub; + return parentStub; } - protected boolean skipChildProcessingWhenBuildingStubs(final PsiElement element, final PsiElement child) { + protected boolean skipChildProcessingWhenBuildingStubs(@NotNull PsiElement element, @NotNull PsiElement child) { return false; } - protected StubElement buildStubTreeFor(ASTNode node, StubElement parentStub) { - StubElement stub = parentStub; - IElementType nodeType = node.getElementType(); + protected StubElement buildStubTreeFor(@NotNull ASTNode root, @NotNull StubElement parentStub) { + Stack parentStubs = new Stack(); + Stack parentNodes = new Stack(); + parentNodes.push(root); + parentStubs.push(parentStub); - if (nodeType instanceof IStubElementType) { - final IStubElementType type = (IStubElementType)nodeType; + while (!parentStubs.isEmpty()) { + StubElement stub = parentStubs.pop(); + ASTNode node = parentNodes.pop(); + IElementType nodeType = node.getElementType(); - if (type.shouldCreateStub(node)) { - //noinspection unchecked - PsiElement element = node.getPsi(); - if (!(element instanceof StubBasedPsiElement)) { - LOG.error("Non-StubBasedPsiElement requests stub creation. Stub type: " + type + ", PSI: " + element); + if (nodeType instanceof IStubElementType) { + final IStubElementType type = (IStubElementType)nodeType; + + if (type.shouldCreateStub(node)) { + //noinspection unchecked + PsiElement element = node.getPsi(); + if (!(element instanceof StubBasedPsiElement)) { + LOG.error("Non-StubBasedPsiElement requests stub creation. Stub type: " + type + ", PSI: " + element); + } + //noinspection unchecked + stub = type.createStub(element, stub); + LOG.assertTrue(stub != null, element); + } + } + + for (ASTNode childNode = node.getLastChildNode(); childNode != null; childNode = childNode.getTreePrev()) { + if (!skipChildProcessingWhenBuildingStubs(node, childNode.getElementType())) { + parentNodes.push(childNode); + parentStubs.push(stub); } - stub = type.createStub(element, parentStub); } } - for (ASTNode childNode = node.getFirstChildNode(); childNode != null; childNode = childNode.getTreeNext()) { - if (!skipChildProcessingWhenBuildingStubs(node, childNode.getElementType())) { - buildStubTreeFor(childNode, stub); - } - } - - return stub; + return parentStub; } @Override public boolean skipChildProcessingWhenBuildingStubs(@Nullable ASTNode parent, IElementType childType) { return false; } -} +} \ No newline at end of file diff --git a/platform/lang-api/src/com/intellij/psi/stubs/LightStubBuilder.java b/platform/lang-api/src/com/intellij/psi/stubs/LightStubBuilder.java index 6c20a61bec5f..8258cac02ced 100644 --- a/platform/lang-api/src/com/intellij/psi/stubs/LightStubBuilder.java +++ b/platform/lang-api/src/com/intellij/psi/stubs/LightStubBuilder.java @@ -96,7 +96,7 @@ public class LightStubBuilder implements StubBuilder { final StubElement stub = createStub(tree, element, parentStub); final List kids = tree.getChildren(element); - if (kids.size() > 0) { + if (!kids.isEmpty()) { if (parent != null) { parents.push(parent); childNumbers.push(childNumber); @@ -115,7 +115,7 @@ public class LightStubBuilder implements StubBuilder { } element = null; - while (parents.size() > 0) { + while (!parents.isEmpty()) { parent = parents.pop(); childNumber = childNumbers.pop(); children = kinderGarden.pop(); @@ -287,4 +287,4 @@ public class LightStubBuilder implements StubBuilder { } } } -} \ No newline at end of file +} diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java index e83dc5f81e08..0b0f972a203e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java @@ -352,74 +352,102 @@ public class PasteHandler extends EditorActionHandler { } private static void indentBlockWithFormatter(Project project, Document document, int startOffset, int endOffset, PsiFile file) { + + // Algorithm: the main idea is to process the first line of the pasted block, adjust its indent if necessary, calculate indent + // adjustment string and apply to each line of the pasted block starting from the second one. + // + // We differentiate three possible states here: + // --- pasted block doesn't start new line, i.e. there are non-white space symbols before it at the first line. + // Example: + // old content [pasted line 1 + // pasted line 2] + // Indent adjustment string is just the first line indent then. + // + // --- pasted block is located at the new line and starts with white space symbols. + // Example: + // [ pasted line 1 + // pasted line 2] + // We parse existing indents of the pasted block then, adjust its first line via formatter and adjust indent of the pasted lines + // starting from the second one in order to preserve old indentation. + // + // --- pasted block is located at the new line but doesn't start with white space symbols. + // Example: + // [pasted line 1 + // pasted line 2] + // We adjust the first line via formatter then and apply first line's indent to all subsequent pasted lines. + CharSequence chars = document.getCharsSequence(); + final int firstLine = document.getLineNumber(startOffset); + final int firstLineStart = document.getLineStartOffset(firstLine); + final int lastLine = document.getLineNumber(endOffset); + final int i = CharArrayUtil.shiftBackward(chars, startOffset - 1, " \t"); + + // Handle situation when pasted block doesn't start new line. + if (chars.charAt(i) != '\n') { + int firstNonWsOffset = CharArrayUtil.shiftForward(chars, firstLineStart, " \t"); + if (firstNonWsOffset > firstLineStart) { + CharSequence toInsert = chars.subSequence(firstLineStart, firstNonWsOffset); + for (int line = firstLine + 1; line <= lastLine; line++) { + document.insertString(document.getLineStartOffset(line), toInsert); + } + } + return; + } + + // Sync document and PSI for correct formatting processing. PsiDocumentManager.getInstance(project).commitAllDocuments(); if (file == null) { return; } CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project); - - final int startLine = document.getLineNumber(startOffset); - final int startLineStartOffset = document.getLineStartOffset(startLine); - int indentAdjustmentAnchorLine = -1; // Line which indent change will be applied to all subsequent pasted lines. - int pastedLinesAfterIndentLine = 0; - - final int nonWsOffset = CharArrayUtil.shiftBackward(chars, startOffset - 1, " \t"); - boolean onNewLine = nonWsOffset < 0 || chars.charAt(nonWsOffset) == '\n'; - int diffShift = 0; - if (onNewLine && (chars.charAt(startOffset) == ' ' || chars.charAt(startOffset) == '\n')) { - indentAdjustmentAnchorLine = startLine; - diffShift += startOffset - startLineStartOffset; + final int j = CharArrayUtil.shiftForward(chars, startOffset, " \t"); + codeStyleManager.adjustLineIndent(file, startOffset); + + // Handle situation when pasted block starts with non-white space symbols. + if (j == startOffset) { + int indentOffset = CharArrayUtil.shiftForward(chars, firstLineStart, " \t"); + if (indentOffset > firstLineStart) { + CharSequence toInsert = chars.subSequence(firstLineStart, indentOffset); + for (int line = firstLine + 1; line <= lastLine; line++) { + document.insertString(document.getLineStartOffset(line), toInsert); + } + } + return; } - for (int line = startLine + 1, max = document.getLineCount(); line < max; line++) { - int lineStartOffset = document.getLineStartOffset(line); - if (lineStartOffset >= endOffset) { - break; - } - - if (indentAdjustmentAnchorLine >= 0) { - pastedLinesAfterIndentLine++; - continue; - } - - int j = CharArrayUtil.shiftForward(chars, lineStartOffset, " \t"); - if (j < document.getLineEndOffset(line)) { - // Non-empty line is found - indentAdjustmentAnchorLine = line; - } + // Handle situation when pasted block starts from white space symbols. Assume that the pasted text started at the line start, + // i.e. correct indentation level is stored at the blocks structure. + final int firstNonWsOffset = CharArrayUtil.shiftForward(chars, firstLineStart, " \t"); + final int diff = firstNonWsOffset - j; + if (diff == 0) { + return; } - - if (indentAdjustmentAnchorLine < 0) { - codeStyleManager.adjustLineIndent(file, startOffset); + if (diff > 0) { + CharSequence toInsert = chars.subSequence(firstLineStart, startOffset + diff); + for (int line = firstLine + 1; line <= lastLine; line++) { + document.insertString(document.getLineStartOffset(line), toInsert); + } return; } - int lineAdjustmentStartOffset; // Start offset of the range which indent will be adjusted - final int anchorLineStart = document.getLineStartOffset(indentAdjustmentAnchorLine); - int lineAdjustmentEndOffset = CharArrayUtil.shiftForward(chars, anchorLineStart, " \t"); - - if (onNewLine) { - lineAdjustmentStartOffset = nonWsOffset + 1; + if (-diff == startOffset - firstLineStart) { + return; } - else { - lineAdjustmentStartOffset = anchorLineStart; - } - codeStyleManager.adjustLineIndent(file, new TextRange(lineAdjustmentStartOffset, lineAdjustmentEndOffset)); - int diff = lineAdjustmentEndOffset - CharArrayUtil.shiftForward(chars, anchorLineStart, " \t") - diffShift; - if (diff > 0) { - // Indent was cut. - for (int line = indentAdjustmentAnchorLine + 1, max = line + pastedLinesAfterIndentLine; line < max; line++) { - int lineStartOffset = document.getLineStartOffset(line); - int indentOffset = CharArrayUtil.shiftForward(chars, lineStartOffset, " \t"); - int symbolsToCutNow = Math.min(diff, indentOffset - lineStartOffset); - document.deleteString(lineStartOffset, lineStartOffset + symbolsToCutNow); + if (-diff > startOffset - firstLineStart) { + int desiredSymbolsToRemove = -diff - (startOffset - firstLineStart); + for (int line = firstLine + 1; line <= lastLine; line++) { + int currentLineStart = document.getLineStartOffset(line); + int currentLineIndentOffset = CharArrayUtil.shiftForward(chars, currentLineStart, " \t"); + int symbolsToRemove = Math.min(currentLineIndentOffset - currentLineStart, desiredSymbolsToRemove); + if (symbolsToRemove > 0) { + document.deleteString(currentLineStart, currentLineStart + symbolsToRemove); + } } } - else if (diff < 0) { - final CharSequence toInsert = chars.subSequence(anchorLineStart, anchorLineStart - diff); - for (int line = indentAdjustmentAnchorLine + 1, max = line + pastedLinesAfterIndentLine; line < max; line++) { + else { + CharSequence toInsert = chars.subSequence(firstLineStart, firstLineStart + startOffset - firstLineStart + diff); + for (int line = firstLine + 1; line <= lastLine; line++) { document.insertString(document.getLineStartOffset(line), toInsert); } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/Browser.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/Browser.java index c2234509fcc1..f58c3c55d6bf 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/Browser.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/Browser.java @@ -320,11 +320,12 @@ public class Browser extends JPanel { InspectionTool tool = getTool(); assert tool != null; final GlobalInspectionContextImpl manager = tool.getContext(); - if (true && refEntity instanceof RefElement){ + if (refEntity instanceof RefElement){ PsiElement element = ((RefElement)refEntity).getElement(); if (element == null) return tool; - tool = InspectionProjectProfileManager.getInstance(manager.getProject()).getProfileWrapper().getInspectionTool(tool.getShortName(), - element); + final InspectionProfileWrapper profileWrapper = InspectionProjectProfileManager.getInstance(manager.getProject()).getProfileWrapper(); + if (profileWrapper == null) return tool; + tool = profileWrapper.getInspectionTool(tool.getShortName(), element); } return tool; } diff --git a/platform/lang-impl/src/com/intellij/injected/editor/EditorWindow.java b/platform/lang-impl/src/com/intellij/injected/editor/EditorWindow.java index 84b1c3f6a299..cff30a4c8e59 100644 --- a/platform/lang-impl/src/com/intellij/injected/editor/EditorWindow.java +++ b/platform/lang-impl/src/com/intellij/injected/editor/EditorWindow.java @@ -331,7 +331,7 @@ public class EditorWindow extends UserDataHolderBase implements EditorEx { } int lineLength = myDocumentWindow.getLineEndOffset(pos.line) - myDocumentWindow.getLineStartOffset(pos.line); if (pos.column >= lineLength) { - pos = new LogicalPosition(pos.line, lineLength-1); + pos = new LogicalPosition(pos.line, Math.max(0, lineLength-1)); } return pos; } diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependencyConfigurable.java b/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependencyConfigurable.java index 77ac3dd44005..de6bb4ce408b 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependencyConfigurable.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependencyConfigurable.java @@ -29,7 +29,7 @@ import com.intellij.packageDependencies.DependencyValidationManager; import com.intellij.psi.search.scope.packageSet.NamedScope; import com.intellij.psi.search.scope.packageSet.PackageSet; import com.intellij.ui.EditableModel; -import com.intellij.ui.TableToolbarDecorator; +import com.intellij.ui.ToolbarDecorator; import com.intellij.ui.table.TableView; import com.intellij.util.ui.AbstractTableCellEditor; import com.intellij.util.ui.CellEditorComponentWithBrowseButton; @@ -100,7 +100,7 @@ public class DependencyConfigurable extends BaseConfigurable { table.setShowGrid(true); table.setRowHeight(new PackageSetChooserCombo(myProject, null).getPreferredSize().height); - return TableToolbarDecorator.createDecorator(table).createPanel(); + return ToolbarDecorator.createDecorator(table).createPanel(); } public JComponent getPreferredFocusedComponent() { diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java index f01dbeb77f0d..45c452ed9330 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java @@ -16,10 +16,7 @@ package com.intellij.psi.impl.source.tree.injected; -import com.intellij.injected.editor.DocumentWindow; -import com.intellij.injected.editor.DocumentWindowImpl; -import com.intellij.injected.editor.EditorWindow; -import com.intellij.injected.editor.VirtualFileWindow; +import com.intellij.injected.editor.*; import com.intellij.lang.Language; import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.openapi.editor.Document; @@ -40,6 +37,7 @@ import com.intellij.psi.impl.PsiParameterizedCachedValue; import com.intellij.psi.impl.source.DummyHolder; import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.*; +import com.intellij.util.ParameterizedCachedValueImpl; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; @@ -190,21 +188,37 @@ public class InjectedLanguageUtil { private static final InjectedPsiCachedValueProvider INJECTED_PSI_PROVIDER = new InjectedPsiCachedValueProvider(); private static final Key> INJECTED_PSI_KEY = Key.create("INJECTED_PSI"); + public static ParameterizedCachedValue NULL_VALUE = new ParameterizedCachedValueImpl(new ParameterizedCachedValueProvider() { + @Override + public CachedValueProvider.Result compute(PsiElement param) { + return CachedValueProvider.Result.create(NULL_REGISTRAR, param.getManager().getModificationTracker()); + } + }) { + @Override + public boolean isFromMyProject(Project project) { + return true; + } + }; + + private static final MultiHostRegistrarImpl NULL_REGISTRAR = new MultiHostRegistrarImpl(); + + private static MultiHostRegistrarImpl probeElementsUp(@NotNull PsiElement element, @NotNull PsiFile hostPsiFile, boolean probeUp) { PsiManager psiManager = hostPsiFile.getManager(); final Project project = psiManager.getProject(); InjectedLanguageManagerImpl injectedManager = InjectedLanguageManagerImpl.getInstanceImpl(project); if (injectedManager == null) return null; //for tests - for (PsiElement current = element; current != null && current != hostPsiFile; current = current.getParent()) { + MultiHostRegistrarImpl registrar = null; + PsiElement current; + nextParent: + for (current = element; current != null && current != hostPsiFile; current = current.getParent()) { ProgressManager.checkCanceled(); if ("EL".equals(current.getLanguage().getID())) break; ParameterizedCachedValue data = current.getUserData(INJECTED_PSI_KEY); - MultiHostRegistrarImpl registrar; if (data == null) { registrar = InjectedPsiCachedValueProvider.doCompute(current, injectedManager, project, hostPsiFile); if (registrar != null) { - // pollute user data only if there is injected fragment there ParameterizedCachedValue cachedValue = CachedValuesManager.getManager(psiManager.getProject()).createParameterizedCachedValue(INJECTED_PSI_PROVIDER, false); Document hostDocument = hostPsiFile.getViewProvider().getDocument(); @@ -216,6 +230,10 @@ public class InjectedLanguageUtil { else { registrar = data.getValue(current); } + if (registrar == NULL_REGISTRAR) { + registrar = null; + break; + } if (registrar != null) { List> places = registrar.result; // check that injections found intersect with queried element @@ -224,14 +242,21 @@ public class InjectedLanguageUtil { Place place = pair.first; for (PsiLanguageInjectionHost.Shred shred : place) { if (shred.host.getTextRange().intersects(elementRange)) { - if (place.isValid()) return registrar; + if (place.isValid()) break nextParent; } } } } if (!probeUp) break; } - return null; + if (registrar == null) { + for (PsiElement e = element; e != current && e != null && e != hostPsiFile; e = e.getParent()) { + ProgressManager.checkCanceled(); + //store no-injection flag + e.putUserData(INJECTED_PSI_KEY, NULL_VALUE); + } + } + return registrar; } @Nullable @@ -324,10 +349,10 @@ public class InjectedLanguageUtil { } public static void clearCaches(@NotNull PsiFile injected, @NotNull DocumentWindowImpl documentWindow) { - VirtualFileWindow virtualFile = (VirtualFileWindow)injected.getVirtualFile(); + VirtualFileWindowImpl virtualFile = (VirtualFileWindowImpl)injected.getVirtualFile(); PsiManagerEx psiManagerEx = (PsiManagerEx)injected.getManager(); if (psiManagerEx.getProject().isDisposed()) return; - psiManagerEx.getFileManager().setViewProvider((VirtualFile)virtualFile, null); + psiManagerEx.getFileManager().setViewProvider(virtualFile, null); PsiElement context = injected.getContext(); PsiFile hostFile; if (context != null) { @@ -349,6 +374,8 @@ public class InjectedLanguageUtil { } } } + //FileDocumentManagerImpl.registerDocument(null, virtualFile); + //FileDocumentManagerImpl.registerDocument(documentWindow, null); } diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureDialogBase.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureDialogBase.java index 67715d67aecb..247d382bbe3a 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureDialogBase.java +++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/ChangeSignatureDialogBase.java @@ -379,7 +379,7 @@ public abstract class ChangeSignatureDialogBase

, Exporta UISettings uiSettings=getInstance(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF); - if(uiSettings.ANTIALIASING_IN_EDITOR) { + if (uiSettings == null || uiSettings.ANTIALIASING_IN_EDITOR) { Toolkit tk = Toolkit.getDefaultToolkit(); //noinspection HardCodedStringLiteral Map map = (Map)tk.getDesktopProperty("awt.font.desktophints"); diff --git a/platform/platform-api/src/com/intellij/ui/AddDeleteListPanel.java b/platform/platform-api/src/com/intellij/ui/AddDeleteListPanel.java index 9147bb660867..fa2df6939de7 100644 --- a/platform/platform-api/src/com/intellij/ui/AddDeleteListPanel.java +++ b/platform/platform-api/src/com/intellij/ui/AddDeleteListPanel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2011 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. @@ -23,28 +23,33 @@ import com.intellij.util.ui.StatusText; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; +import java.awt.*; import java.util.ArrayList; import java.util.List; /** * Panel with "Add" and "Delete" buttons on the right side. * + * @author Konstantin Bulenkov * @author anna * @since 5.1 */ public abstract class AddDeleteListPanel extends PanelWithButtons implements ComponentWithEmptyText { private final String myTitle; + + /** + * @deprecated + */ protected JButton myAddButton = new JButton(CommonBundle.message("button.add")); + /** + * @deprecated + */ protected JButton myDeleteButton = new JButton(CommonBundle.message("button.delete")); + protected DefaultListModel myListModel = new DefaultListModel(); protected JBList myList = new JBList(myListModel); - public AddDeleteListPanel(final String title, - final List initialList) { + public AddDeleteListPanel(final String title, final List initialList) { myTitle = title; for (Object o : initialList) { if (o != null) { @@ -52,24 +57,31 @@ public abstract class AddDeleteListPanel extends PanelWithButtons implements } } myList.setCellRenderer(getListCellRenderer()); - myList.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent e) { - myDeleteButton.setEnabled(ListUtil.canRemoveSelectedItems(myList)); - } - }); - myAddButton.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e) { - addElement(findItemToAdd()); - } - }); - myDeleteButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - ListUtil.removeSelectedItems(myList); - } - }); initPanel(); } + @Override + protected void initPanel() { + final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myList) + .disableUpAction() + .disableDownAction() + .setAddAction(new Runnable() { + @Override + public void run() { + addElement(findItemToAdd()); + } + }); + customizeDecorator(decorator); + setLayout(new BorderLayout()); + add(decorator.createPanel(), BorderLayout.CENTER); + if (myTitle != null) { + setBorder(IdeBorderFactory.createTitledBorder(myTitle)); + } + } + + protected void customizeDecorator(ToolbarDecorator decorator) { + } + @Override public StatusText getEmptyText() { return myList.getEmptyText(); diff --git a/platform/platform-api/src/com/intellij/ui/AddEditDeleteListPanel.java b/platform/platform-api/src/com/intellij/ui/AddEditDeleteListPanel.java index a7500f5c91ec..150517f7b015 100644 --- a/platform/platform-api/src/com/intellij/ui/AddEditDeleteListPanel.java +++ b/platform/platform-api/src/com/intellij/ui/AddEditDeleteListPanel.java @@ -1,28 +1,36 @@ +/* + * Copyright 2000-2011 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.ui; import com.intellij.CommonBundle; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.util.IconUtil; import org.jetbrains.annotations.Nullable; -import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.List; /** * @author peter + * @author Konstantin Bulenkov */ public abstract class AddEditDeleteListPanel extends AddDeleteListPanel { - private JButton myEditButton; - public AddEditDeleteListPanel(final String title, final List initialList) { super(title, initialList); - myEditButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - editSelectedItem(); - } - }); myList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { @@ -32,9 +40,19 @@ public abstract class AddEditDeleteListPanel extends AddDeleteListPanel { }); } - @Override protected JButton[] createButtons() { - myEditButton = new JButton(CommonBundle.message("button.edit")); - return new JButton[] { myAddButton, myEditButton, myDeleteButton }; + @Override + protected void customizeDecorator(ToolbarDecorator decorator) { + decorator.addExtraAction(new AnActionButton(CommonBundle.message("button.edit"), null, IconUtil.getEditIcon()) { + @Override + public void actionPerformed(AnActionEvent e) { + editSelectedItem(); + } + + @Override + public void update(AnActionEvent e) { + e.getPresentation().setEnabled(myList.getSelectedIndex() != -1); + } + }); } @Nullable diff --git a/platform/platform-api/src/com/intellij/ui/TableToolbarDecorator.java b/platform/platform-api/src/com/intellij/ui/ToolbarDecorator.java similarity index 57% rename from platform/platform-api/src/com/intellij/ui/TableToolbarDecorator.java rename to platform/platform-api/src/com/intellij/ui/ToolbarDecorator.java index 80412d548bd3..b2880494e419 100644 --- a/platform/platform-api/src/com/intellij/ui/TableToolbarDecorator.java +++ b/platform/platform-api/src/com/intellij/ui/ToolbarDecorator.java @@ -34,9 +34,10 @@ import java.util.List; * @author Konstantin Bulenkov */ @SuppressWarnings("UnusedDeclaration") -public class TableToolbarDecorator { +public class ToolbarDecorator { private JTable myTable; - private TableModel myModel; + private TableModel myTableModel; + private ListModel myListModel; private Border myToolbarBorder; private boolean myAddActionEnabled; private boolean myRemoveActionEnabled; @@ -50,29 +51,66 @@ public class TableToolbarDecorator { private Runnable myUpAction; private Runnable myDownAction; private AddRemoveUpDownPanel myPanel; + private JList myList; - private TableToolbarDecorator(JTable table) { + private ToolbarDecorator(JTable table) { myTable = table; myTable.setBorder(IdeBorderFactory.createEmptyBorder(0)); - myModel = table.getModel(); - myToolbarPosition = SystemInfo.isMac ? ActionToolbarPosition.BOTTOM : ActionToolbarPosition.RIGHT; - myBorder = SystemInfo.isMac ? new CustomLineBorder(0,1,1,1) : new CustomLineBorder(0, 1, 0, 0); - myAddActionEnabled = myRemoveActionEnabled = myUpActionEnabled = myDownActionEnabled = myModel instanceof EditableModel; - if (myModel instanceof EditableModel) { - createDefaultActions(); + myTableModel = table.getModel(); + initPositionAndBorder(); + myAddActionEnabled = myRemoveActionEnabled = myUpActionEnabled = myDownActionEnabled = myTableModel instanceof EditableModel; + if (myTableModel instanceof EditableModel) { + createDefaultTableActions(); } } - private void createDefaultActions() { + private ToolbarDecorator(JList list) { + myList = list; + myListModel = list.getModel(); + myAddActionEnabled = myRemoveActionEnabled = myUpActionEnabled = myDownActionEnabled = true; + initPositionAndBorder(); + createDefaultListActions(); + } + + private void createDefaultListActions() { + myRemoveAction = new Runnable() { + @Override + public void run() { + ListUtil.removeSelectedItems(myList); + updateListButtons(myList, myPanel); + } + }; + myUpAction = new Runnable() { + @Override + public void run() { + ListUtil.moveSelectedItemsUp(myList); + updateListButtons(myList, myPanel); + } + }; + myDownAction = new Runnable() { + @Override + public void run() { + ListUtil.moveSelectedItemsDown(myList); + updateListButtons(myList, myPanel); + } + }; + } + + private void initPositionAndBorder() { + myToolbarPosition = SystemInfo.isMac ? ActionToolbarPosition.BOTTOM : ActionToolbarPosition.RIGHT; + myBorder = SystemInfo.isMac ? new CustomLineBorder(0,1,1,1) : new CustomLineBorder(0, 1, 0, 0); + } + + private void createDefaultTableActions() { final JTable table = myTable; - final EditableModel tableModel = (EditableModel)myModel; + final EditableModel tableModel = (EditableModel)myTableModel; myAddAction = new Runnable() { public void run() { TableUtil.stopEditing(table); tableModel.addRow(); - final int index = myModel.getRowCount() - 1; + final int index = myTableModel.getRowCount() - 1; table.editCellAt(index, 0); table.setRowSelectionInterval(index, index); table.setColumnSelectionInterval(0, 0); @@ -90,9 +128,9 @@ public class TableToolbarDecorator { public void run() { TableUtil.stopEditing(table); int index = table.getSelectedRow(); - if (0 <= index && index < myModel.getRowCount()) { + if (0 <= index && index < myTableModel.getRowCount()) { tableModel.removeRow(index); - if (index < myModel.getRowCount()) { + if (index < myTableModel.getRowCount()) { table.setRowSelectionInterval(index, index); } else { @@ -100,7 +138,7 @@ public class TableToolbarDecorator { table.setRowSelectionInterval(index - 1, index - 1); } } - updateButtons(table, tableModel, myPanel); + updateTableButtons(table, tableModel, myPanel); } table.getParent().repaint(); @@ -112,7 +150,7 @@ public class TableToolbarDecorator { public void run() { TableUtil.stopEditing(table); int index = table.getSelectedRow(); - if (0 < index && index < myModel.getRowCount()) { + if (0 < index && index < myTableModel.getRowCount()) { tableModel.exchangeRows(index, index - 1); table.setRowSelectionInterval(index - 1, index - 1); } @@ -124,7 +162,7 @@ public class TableToolbarDecorator { public void run() { TableUtil.stopEditing(table); int index = table.getSelectedRow(); - if (0 <= index && index < myModel.getRowCount() - 1) { + if (0 <= index && index < myTableModel.getRowCount() - 1) { tableModel.exchangeRows(index, index + 1); table.setRowSelectionInterval(index + 1, index + 1); } @@ -133,92 +171,112 @@ public class TableToolbarDecorator { }; } - private static void updateButtons(final JTable table, - final EditableModel tableModel, - final AddRemoveUpDownPanel p) { - if (table.isEnabled()) { + private static void updateListButtons(final JList list, final AddRemoveUpDownPanel p) { + if (list.isEnabled() && p != null) { + final int index = list.getSelectedIndex(); + if (0 <= index && index < list.getModel().getSize()) { + final boolean downEnable = list.getMaxSelectionIndex() < list.getModel().getSize() - 1; + final boolean upEnable = list.getMinSelectionIndex() > 0; + p.setEnabled(AddRemoveUpDownPanel.Buttons.REMOVE, true); + p.setEnabled(AddRemoveUpDownPanel.Buttons.UP, upEnable); + p.setEnabled(AddRemoveUpDownPanel.Buttons.DOWN, downEnable); + } else { + p.setEnabled(AddRemoveUpDownPanel.Buttons.REMOVE, false); + p.setEnabled(AddRemoveUpDownPanel.Buttons.UP, false); + p.setEnabled(AddRemoveUpDownPanel.Buttons.DOWN, false); + } + p.setEnabled(AddRemoveUpDownPanel.Buttons.ADD, true); + } + } + + private static void updateTableButtons(final JTable table, + final EditableModel tableModel, + final AddRemoveUpDownPanel p) { + if (table.isEnabled() && p != null) { final int index = table.getSelectedRow(); if (0 <= index && index < ((TableModel)tableModel).getRowCount()) { final boolean downEnable = index < ((TableModel)tableModel).getRowCount() - 1; final boolean upEnable = index > 0; - if (p != null) { - p.setEnabled(AddRemoveUpDownPanel.Buttons.REMOVE, true); - p.setEnabled(AddRemoveUpDownPanel.Buttons.UP, upEnable); - p.setEnabled(AddRemoveUpDownPanel.Buttons.DOWN, downEnable); - } + p.setEnabled(AddRemoveUpDownPanel.Buttons.REMOVE, true); + p.setEnabled(AddRemoveUpDownPanel.Buttons.UP, upEnable); + p.setEnabled(AddRemoveUpDownPanel.Buttons.DOWN, downEnable); } else { - if (p != null) { - p.setEnabled(AddRemoveUpDownPanel.Buttons.REMOVE, false); - p.setEnabled(AddRemoveUpDownPanel.Buttons.UP, false); - p.setEnabled(AddRemoveUpDownPanel.Buttons.DOWN, false); - } - } - if (p != null) { - p.setEnabled(AddRemoveUpDownPanel.Buttons.ADD, true); + p.setEnabled(AddRemoveUpDownPanel.Buttons.REMOVE, false); + p.setEnabled(AddRemoveUpDownPanel.Buttons.UP, false); + p.setEnabled(AddRemoveUpDownPanel.Buttons.DOWN, false); } + p.setEnabled(AddRemoveUpDownPanel.Buttons.ADD, true); } } - public static TableToolbarDecorator createDecorator(JTable table) { - return new TableToolbarDecorator(table); + public static ToolbarDecorator createDecorator(JTable table) { + return new ToolbarDecorator(table); } - public TableToolbarDecorator disableAddAction() { + public static ToolbarDecorator createDecorator(JList list) { + return new ToolbarDecorator(list); + } + + public ToolbarDecorator disableAddAction() { myAddActionEnabled = false; return this; } - public TableToolbarDecorator disableRemoveAction() { + public ToolbarDecorator disableRemoveAction() { myRemoveActionEnabled = false; return this; } - public TableToolbarDecorator disableUpAction() { + public ToolbarDecorator disableUpAction() { myUpActionEnabled = false; return this; } - public TableToolbarDecorator disableDownAction() { + public ToolbarDecorator disableDownAction() { myDownActionEnabled = false; return this; } - public TableToolbarDecorator setToolbarBorder(Border border) { + public ToolbarDecorator setToolbarBorder(Border border) { myBorder = border; return this; } - public TableToolbarDecorator setLineBorder(int top, int left, int bottom, int right) { + public ToolbarDecorator setLineBorder(int top, int left, int bottom, int right) { return setToolbarBorder(new CustomLineBorder(top, left, bottom, right)); } - public TableToolbarDecorator addExtraAction(AnActionButton action) { + public ToolbarDecorator addExtraAction(AnActionButton action) { myExtraActions.add(action); return this; } - public TableToolbarDecorator setToolbarPosition(ActionToolbarPosition position) { + public ToolbarDecorator setToolbarPosition(ActionToolbarPosition position) { myToolbarPosition = position; return this; } - public TableToolbarDecorator setAddAction(Runnable action) { + public ToolbarDecorator setAddAction(Runnable action) { + myAddActionEnabled = action != null; myAddAction = action; return this; } - public TableToolbarDecorator setRemoveAction(Runnable action) { + public ToolbarDecorator setRemoveAction(Runnable action) { + myRemoveActionEnabled = action != null; myRemoveAction = action; return this; } - public TableToolbarDecorator setUpAction(Runnable action) { + public ToolbarDecorator setUpAction(Runnable action) { + myUpActionEnabled = action != null; myUpAction = action; return this; } - public TableToolbarDecorator setDownAction(Runnable action) { + public ToolbarDecorator setDownAction(Runnable action) { + myDownActionEnabled = action != null; myDownAction = action; return this; } @@ -226,26 +284,46 @@ public class TableToolbarDecorator { public JPanel createPanel() { final AddRemoveUpDownPanel.Buttons[] buttons = getButtons(); myPanel = new AddRemoveUpDownPanel(createListener(), - myTable, + myTable == null ? myList : myTable, myToolbarPosition == ActionToolbarPosition.TOP || myToolbarPosition == ActionToolbarPosition.BOTTOM, myExtraActions.toArray(new AnActionButton[myExtraActions.size()]), buttons); myPanel.setBorder(myBorder); - final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable); + final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTable == null ? myList : myTable); scrollPane.setBorder(IdeBorderFactory.createEmptyBorder(0)); - final JPanel panel = new JPanel(new BorderLayout()); + final JPanel panel = new JPanel(new BorderLayout()) { + @Override + public void addNotify() { + super.addNotify(); + if (myList != null) { + updateListButtons(myList, myPanel); + } + if (myTable != null && myTableModel instanceof EditableModel) { + updateTableButtons(myTable, (EditableModel)myTableModel, myPanel); + } + } + }; panel.add(scrollPane, BorderLayout.CENTER); panel.add(myPanel, getPlacement()); - if (myModel instanceof EditableModel && buttons.length > 0) { - updateButtons(myTable, (EditableModel)myModel, myPanel); + if (myTableModel instanceof EditableModel && buttons.length > 0) { + updateTableButtons(myTable, (EditableModel)myTableModel, myPanel); if (myUpAction != null && myUpActionEnabled && myDownAction != null && myDownActionEnabled) { - TableRowsDnDSupport.install(myTable, (EditableModel)myModel); + TableRowsDnDSupport.install(myTable, (EditableModel)myTableModel); } myTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { - updateButtons(myTable, (EditableModel)myModel, myPanel); + updateTableButtons(myTable, (EditableModel)myTableModel, myPanel); + } + }); + } + if (myList != null) { + updateListButtons(myList, myPanel); + myList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + updateListButtons(myList, myPanel); } }); } diff --git a/platform/platform-impl/src/com/intellij/help/impl/IdeaJHelpContentViewer.java b/platform/platform-impl/src/com/intellij/help/impl/IdeaJHelpContentViewer.java index 01f7de295400..983211b814db 100644 --- a/platform/platform-impl/src/com/intellij/help/impl/IdeaJHelpContentViewer.java +++ b/platform/platform-impl/src/com/intellij/help/impl/IdeaJHelpContentViewer.java @@ -15,6 +15,7 @@ */ package com.intellij.help.impl; +import com.intellij.ide.ui.UISettings; import com.intellij.util.ui.UIUtil; import sun.swing.SwingUtilities2; @@ -55,6 +56,7 @@ class IdeaJHelpContentViewer extends JHelpContentViewer{ if (editorPane != null) { editorPane.putClientProperty(SwingUtilities2.AA_TEXT_PROPERTY_KEY, SwingUtilities2.AATextInfo.getAATextInfo(true)); } + UISettings.setupAntialiasing(g); super.paint(g); } } \ No newline at end of file diff --git a/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java b/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java index bdde15051217..69cb188f5026 100644 --- a/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/ParsingTestCase.java @@ -110,7 +110,7 @@ public abstract class ParsingTestCase extends LightPlatformTestCase { try { text = text.trim(); String expectedText = doLoadFile(myFullDataPath, targetDataName); - assertEquals(expectedText, text); + assertEquals(targetDataName, expectedText, text); } catch(FileNotFoundException e){ String fullName = myFullDataPath + File.separatorChar + targetDataName; diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/history/VcsAppendableHistoryPartnerAdapter.java b/platform/vcs-api/src/com/intellij/openapi/vcs/history/VcsAppendableHistoryPartnerAdapter.java new file mode 100644 index 000000000000..383adea20d0e --- /dev/null +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/history/VcsAppendableHistoryPartnerAdapter.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2011 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.openapi.vcs.history; + +import com.intellij.openapi.vcs.VcsException; + +/** + * @author irengrig + * Date: 7/13/11 + * Time: 5:52 PM + */ +public class VcsAppendableHistoryPartnerAdapter implements VcsAppendableHistorySessionPartner { + private VcsAbstractHistorySession mySession; + private VcsException myException; + + @Override + public void reportCreatedEmptySession(VcsAbstractHistorySession session) { + mySession = session; + } + + @Override + public void acceptRevision(VcsFileRevision revision) { + mySession.appendRevision(revision); + } + + @Override + public void reportException(VcsException exception) { + myException = exception; + } + + @Override + public void finished() { + } + + @Override + public void forceRefresh() { + } + + public void check() throws VcsException { + if (myException != null) throw myException; + } + + public VcsAbstractHistorySession getSession() { + return mySession; + } +} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java index 5b4421f3c0e8..259d5ff2751e 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java @@ -318,7 +318,7 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj if (options != null) { JPanel vcsOptions = new JPanel(new BorderLayout()); vcsOptions.add(options.getComponent(), BorderLayout.CENTER); - vcsOptions.add(SeparatorFactory.createSeparator(vcs.getDisplayName(), null), BorderLayout.NORTH); + vcsOptions.setBorder(IdeBorderFactory.createTitledBorder(vcs.getDisplayName())); vcsCommitOptions.add(vcsOptions); myPerVcsOptionsPanels.put(vcs, vcsOptions); myAdditionalComponents.add(options); @@ -361,17 +361,21 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj } final String actionName = getCommitActionName(); - final String borderTitleName = actionName.replace("_", ""); + final String borderTitleName = actionName.replace("_", "").replace("&", ""); if (beforeVisible) { beforeBox.add(Box.createVerticalGlue()); - beforeBox.add(SeparatorFactory.createSeparator(VcsBundle.message("border.standard.checkin.options.group", borderTitleName), null), 0); - optionsBox.add(beforeBox); + JPanel beforePanel = new JPanel(new BorderLayout()); + beforePanel.add(beforeBox); + beforePanel.setBorder(IdeBorderFactory.createTitledBorder(VcsBundle.message("border.standard.checkin.options.group", borderTitleName))); + optionsBox.add(beforePanel); } if (afterVisible) { afterBox.add(Box.createVerticalGlue()); - afterBox.add(SeparatorFactory.createSeparator(VcsBundle.message("border.standard.after.checkin.options.group", borderTitleName), null), 0); - optionsBox.add(afterBox); + JPanel afterPanel = new JPanel(new BorderLayout()); + afterPanel.add(afterBox); + afterPanel.setBorder(IdeBorderFactory.createTitledBorder(VcsBundle.message("border.standard.after.checkin.options.group", borderTitleName))); + optionsBox.add(afterPanel); } if (hasVcsOptions || beforeVisible || afterVisible) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitLegendPanel.form b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitLegendPanel.form index ad82fc9fcc9d..6c38708008ea 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitLegendPanel.form +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitLegendPanel.form @@ -1,204 +1,198 @@

- + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + + + + - + - + - - - - - - - - - - - + - + - + - - - - - - - - - - - + - + - + - - - - - - - - - - - - - - - - - + - + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitLegendPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitLegendPanel.java index 1863a9588ecb..d7d11aac9b47 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitLegendPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitLegendPanel.java @@ -43,7 +43,6 @@ public class CommitLegendPanel { private JLabel myNewLabel; private JPanel myDeletedPanel; private JLabel myDeletedLabel; - private JPanel myHeadingPanel; private final InfoCalculator myInfoCalculator; @@ -85,10 +84,6 @@ public class CommitLegendPanel { updateCategory(myDeletedShown, myDeletedIncluded, deleted, includedDeleted); } - private void createUIComponents() { - myHeadingPanel = (JPanel)SeparatorFactory.createSeparator(VcsBundle.message("commit.legend.summary"), null); - } - private static void updateCategory(JLabel totalLabel, JLabel includedLabel, int totalCnt, diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java index 7001d96c9e42..8695252d7473 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ui/CommitMessage.java @@ -62,7 +62,7 @@ public class CommitMessage extends JPanel implements Disposable { JPanel labelPanel = new JPanel(new BorderLayout()); labelPanel.setBorder(BorderFactory.createEmptyBorder()); - JComponent separator = SeparatorFactory.createSeparator(VcsBundle.message("label.commit.comment"), myEditorField.getComponent()); + JComponent separator = SeparatorFactory.createSeparatorWithBoldTitle(VcsBundle.message("label.commit.comment"), myEditorField.getComponent()); JPanel separatorPanel = new JPanel(new BorderLayout()); separatorPanel.add(separator, BorderLayout.SOUTH); separatorPanel.add(Box.createVerticalGlue(), BorderLayout.NORTH); diff --git a/plugins/InspectionGadgets/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspection.java b/plugins/InspectionGadgets/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspection.java index 8ec2ac65c34b..9a7373af23fd 100644 --- a/plugins/InspectionGadgets/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspection.java +++ b/plugins/InspectionGadgets/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspection.java @@ -129,8 +129,7 @@ public class BooleanMethodIsAlwaysInvertedInspection extends GlobalJavaInspectio final PsiPrefixExpression prefixExpression = PsiTreeUtil.getParentOfType(methodExpression, PsiPrefixExpression.class); if (methodExpression.getQualifierExpression() instanceof PsiSuperExpression) return true; //don't flag super calls if (prefixExpression != null) { - final PsiJavaToken sign = prefixExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); if (tokenType.equals(JavaTokenType.EXCL)) { return true; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToCollectionFieldFromParameterInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToCollectionFieldFromParameterInspection.java index ea20c88a7754..695c7bc47a74 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToCollectionFieldFromParameterInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToCollectionFieldFromParameterInspection.java @@ -83,8 +83,7 @@ public class AssignmentToCollectionFieldFromParameterInspection if(!(rhs instanceof PsiReferenceExpression)){ return; } - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.EQ)){ return; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToDateFieldFromParameterInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToDateFieldFromParameterInspection.java index 3e216d306f32..7a58cb68b7b4 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToDateFieldFromParameterInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToDateFieldFromParameterInspection.java @@ -71,8 +71,7 @@ public class AssignmentToDateFieldFromParameterInspection @Override public void visitAssignmentExpression( @NotNull PsiAssignmentExpression expression) { super.visitAssignmentExpression(expression); - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (!JavaTokenType.EQ.equals(tokenType)) { return; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToForLoopParameterInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToForLoopParameterInspection.java index bb8950a589a5..fba786b9c791 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToForLoopParameterInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToForLoopParameterInspection.java @@ -86,8 +86,7 @@ public class AssignmentToForLoopParameterInspection @Override public void visitPrefixExpression( @NotNull PsiPrefixExpression expression) { super.visitPrefixExpression(expression); - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)) { return; @@ -103,8 +102,7 @@ public class AssignmentToForLoopParameterInspection @Override public void visitPostfixExpression( @NotNull PsiPostfixExpression expression) { super.visitPostfixExpression(expression); - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)) { return; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToMethodParameterInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToMethodParameterInspection.java index 4b387f17d41b..6a276ed5bf3c 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToMethodParameterInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToMethodParameterInspection.java @@ -128,8 +128,7 @@ public class AssignmentToMethodParameterInspection return; } super.visitPostfixExpression(expression); - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)) { return; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToStaticFieldFromInstanceMethodInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToStaticFieldFromInstanceMethodInspection.java index 9df1215c85a7..fd216143a4fd 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToStaticFieldFromInstanceMethodInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToStaticFieldFromInstanceMethodInspection.java @@ -57,8 +57,7 @@ public class AssignmentToStaticFieldFromInstanceMethodInspection @Override public void visitPrefixExpression( @NotNull PsiPrefixExpression expression){ - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)){ return; @@ -72,8 +71,7 @@ public class AssignmentToStaticFieldFromInstanceMethodInspection @Override public void visitPostfixExpression( @NotNull PsiPostfixExpression expression){ - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)){ return; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/ReplaceAssignmentWithOperatorAssignmentInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/ReplaceAssignmentWithOperatorAssignmentInspection.java index 24d6cfad540b..1a1084c5e51f 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/ReplaceAssignmentWithOperatorAssignmentInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/ReplaceAssignmentWithOperatorAssignmentInspection.java @@ -154,8 +154,7 @@ public class ReplaceAssignmentWithOperatorAssignmentInspection @Override public void visitAssignmentExpression(@NotNull PsiAssignmentExpression assignment){ super.visitAssignmentExpression(assignment); - final PsiJavaToken sign = assignment.getOperationSign(); - final IElementType assignmentTokenType = sign.getTokenType(); + final IElementType assignmentTokenType = assignment.getOperationTokenType(); if(!assignmentTokenType.equals(JavaTokenType.EQ)){ return; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bitwise/IncompatibleMaskInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bitwise/IncompatibleMaskInspection.java index 98da35cbf505..b6fac5a91457 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/bitwise/IncompatibleMaskInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bitwise/IncompatibleMaskInspection.java @@ -43,9 +43,7 @@ public class IncompatibleMaskInspection extends BaseInspection { public String buildErrorString(Object... infos){ final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) infos[0]; - final PsiJavaToken operationSign = - binaryExpression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if(tokenType.equals(JavaTokenType.EQEQ)){ return InspectionGadgetsBundle.message( "incompatible.mask.operation.problem.descriptor.always.false"); @@ -105,8 +103,7 @@ public class IncompatibleMaskInspection extends BaseInspection { private static boolean isIncompatibleMask( PsiBinaryExpression maskExpression, PsiExpression constantExpression){ - final PsiJavaToken sign = maskExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = maskExpression.getOperationTokenType(); final Object constantValue = ConstantExpressionUtil.computeCastTo(constantExpression, PsiType.LONG); @@ -156,8 +153,7 @@ public class IncompatibleMaskInspection extends BaseInspection { } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) expression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.OR) && !tokenType.equals(JavaTokenType.AND)){ return false; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bitwise/PointlessBitwiseExpressionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bitwise/PointlessBitwiseExpressionInspection.java index fc6cf4d696f7..ffe7667093b8 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/bitwise/PointlessBitwiseExpressionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bitwise/PointlessBitwiseExpressionInspection.java @@ -85,8 +85,7 @@ public class PointlessBitwiseExpressionInspection extends BaseInspection { (PsiBinaryExpression) expression; final PsiExpression lhs = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); assert rhs != null; if(tokenType.equals(JavaTokenType.AND)){ if(isZero(lhs) || isAllOnes(rhs)){ diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/NonShortCircuitBooleanInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/NonShortCircuitBooleanInspection.java index 56c1695cfcee..6d5aca57ec1d 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/NonShortCircuitBooleanInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/NonShortCircuitBooleanInspection.java @@ -64,8 +64,7 @@ public class NonShortCircuitBooleanInspection extends BaseInspection { (PsiBinaryExpression) descriptor.getPsiElement(); final PsiExpression lhs = expression.getLOperand(); final PsiExpression rhs = expression.getROperand(); - final PsiJavaToken operationSign = expression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); assert rhs != null; final String newExpression = lhs.getText() + getShortCircuitOperand(tokenType) + rhs.getText(); @@ -96,8 +95,7 @@ public class NonShortCircuitBooleanInspection extends BaseInspection { if(!(expression.getROperand() != null)){ return; } - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.AND) && !tokenType.equals(JavaTokenType.OR)) { return; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ObjectToStringInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ObjectToStringInspection.java index c4a7204f0919..0c07612276a3 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ObjectToStringInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ObjectToStringInspection.java @@ -75,8 +75,7 @@ public class ObjectToStringInspection extends BaseInspection { if(!WellFormednessUtils.isWellFormed(expression)) { return; } - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.PLUSEQ)) { return; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/SubtractionInCompareToInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/SubtractionInCompareToInspection.java index d89096c29990..0518c5b346d7 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/SubtractionInCompareToInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/SubtractionInCompareToInspection.java @@ -66,8 +66,7 @@ public class SubtractionInCompareToInspection extends BaseInspection { if(rhs == null){ return false; } - final PsiJavaToken sign = exp.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = exp.getOperationTokenType(); return tokenType.equals(JavaTokenType.MINUS); } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/BooleanFieldAlwaysNegatedInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/BooleanFieldAlwaysNegatedInspection.java index b899e9c7bcae..f0dc53d91462 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/BooleanFieldAlwaysNegatedInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/BooleanFieldAlwaysNegatedInspection.java @@ -133,8 +133,7 @@ public class BooleanFieldAlwaysNegatedInspection extends BaseGlobalInspection { private static boolean isInvertedFieldRead(PsiReferenceExpression referenceExpression) { final PsiPrefixExpression prefixExpression = PsiTreeUtil.getParentOfType(referenceExpression, PsiPrefixExpression.class); if (prefixExpression != null) { - final PsiJavaToken sign = prefixExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); if (tokenType.equals(JavaTokenType.EXCL)) { return true; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateBooleanBranchInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateBooleanBranchInspection.java index 2e0287ec542a..e13eeebffcab 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateBooleanBranchInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateBooleanBranchInspection.java @@ -119,8 +119,7 @@ public class DuplicateBooleanBranchInspection extends BaseInspection { if (condition instanceof PsiBinaryExpression) { final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) condition; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType testTokeType = sign.getTokenType(); + final IElementType testTokeType = binaryExpression.getOperationTokenType(); if (testTokeType.equals(tokenType)) { final PsiExpression lhs = binaryExpression.getLOperand(); collectConditions(lhs, conditions, tokenType); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateConditionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateConditionInspection.java index d5cad2ef4894..58d4b0b5cc0d 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateConditionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateConditionInspection.java @@ -144,8 +144,7 @@ public class DuplicateConditionInspection extends BaseInspection { if (condition instanceof PsiBinaryExpression) { final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)condition; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if (JavaTokenType.OROR.equals(tokenType)) { final PsiExpression lhs = binaryExpression.getLOperand(); collectConditionsForExpression(lhs, conditions); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/LoopConditionNotUpdatedInsideLoopInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/LoopConditionNotUpdatedInsideLoopInspection.java index bc516ce4e17a..70e56ee5a37c 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/LoopConditionNotUpdatedInsideLoopInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/LoopConditionNotUpdatedInsideLoopInspection.java @@ -176,8 +176,7 @@ public class LoopConditionNotUpdatedInsideLoopInspection } else if (condition instanceof PsiPrefixExpression) { final PsiPrefixExpression prefixExpression = (PsiPrefixExpression)condition; - final PsiJavaToken sign = prefixExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); if (JavaTokenType.EXCL.equals(tokenType) || JavaTokenType.PLUS.equals(tokenType) || JavaTokenType.MINUS.equals(tokenType)) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspection.java index 8fe9a0662d3e..c3a77298d78d 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspection.java @@ -242,8 +242,7 @@ public class OverlyComplexBooleanExpressionInspection } else if (expression instanceof PsiPrefixExpression) { final PsiPrefixExpression prefixExpression = (PsiPrefixExpression) expression; - final PsiJavaToken sign = prefixExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); return tokenType.equals(JavaTokenType.EXCL); } else if (expression instanceof PsiParenthesizedExpression) { final PsiParenthesizedExpression parenthesizedExpression = diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java index 6e3ab5c5fb84..f7257abb00ef 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java @@ -100,14 +100,13 @@ public class PointlessBooleanExpressionInspection extends BaseInspection { @Nullable private String calculateSimplifiedBinaryExpression( PsiBinaryExpression expression){ - final PsiJavaToken sign = expression.getOperationSign(); - final PsiExpression lhs = expression.getLOperand(); + final PsiExpression lhs = expression.getLOperand(); final PsiExpression rhs = expression.getROperand(); if(rhs == null){ return null; } - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); final String rhsText = rhs.getText(); final String lhsText = lhs.getText(); if(tokenType.equals(JavaTokenType.ANDAND) || @@ -156,9 +155,8 @@ public class PointlessBooleanExpressionInspection extends BaseInspection { if(ComparisonUtils.isComparison(exp)){ final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) exp; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final String negatedComparison = - ComparisonUtils.getNegatedComparison(sign); + final String negatedComparison = + ComparisonUtils.getNegatedComparison(binaryExpression.getOperationTokenType()); final PsiExpression lhs = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); assert rhs != null; @@ -284,9 +282,8 @@ public class PointlessBooleanExpressionInspection extends BaseInspection { @Override public void visitPrefixExpression( @NotNull PsiPrefixExpression expression){ super.visitPrefixExpression(expression); - final PsiJavaToken sign = expression.getOperationSign(); - final PsiExpression operand = expression.getOperand(); - final IElementType tokenType = sign.getTokenType(); + final PsiExpression operand = expression.getOperand(); + final IElementType tokenType = expression.getOperationTokenType(); if(!(!tokenType.equals(JavaTokenType.EXCL) || !notExpressionIsPointless(operand))){ registerError(expression, expression); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/TrivialIfInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/TrivialIfInspection.java index 2e9c56bd5011..c2aeb66ed3ea 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/TrivialIfInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/TrivialIfInspection.java @@ -386,10 +386,8 @@ public class TrivialIfInspection extends BaseInspection { final PsiAssignmentExpression elseExpression = (PsiAssignmentExpression) elseExpressionStatement.getExpression(); - final PsiJavaToken thenSign = thenExpression.getOperationSign(); - final PsiJavaToken elseSign = elseExpression.getOperationSign(); - final IElementType thenTokenType = thenSign.getTokenType(); - if (!thenTokenType.equals(elseSign.getTokenType())) { + final IElementType thenTokenType = thenExpression.getOperationTokenType(); + if (!thenTokenType.equals(elseExpression.getOperationTokenType())) { return false; } final PsiExpression thenLhs = thenExpression.getLExpression(); @@ -419,10 +417,8 @@ public class TrivialIfInspection extends BaseInspection { final PsiAssignmentExpression elseExpression = (PsiAssignmentExpression) elseExpressionStatement.getExpression(); - final PsiJavaToken thenSign = thenExpression.getOperationSign(); - final PsiJavaToken elseSign = elseExpression.getOperationSign(); - final IElementType thenTokenType = thenSign.getTokenType(); - if (!thenTokenType.equals(elseSign.getTokenType())) { + final IElementType thenTokenType = thenExpression.getOperationTokenType(); + if (!thenTokenType.equals(elseExpression.getOperationTokenType())) { return false; } final PsiExpression thenLhs = thenExpression.getLExpression(); @@ -461,10 +457,8 @@ public class TrivialIfInspection extends BaseInspection { final PsiAssignmentExpression elseExpression = (PsiAssignmentExpression) elseExpressionStatement.getExpression(); - final PsiJavaToken thenSign = thenExpression.getOperationSign(); - final PsiJavaToken elseSign = elseExpression.getOperationSign(); - final IElementType thenTokenType = thenSign.getTokenType(); - if (!thenTokenType.equals(elseSign.getTokenType())) { + final IElementType thenTokenType = thenExpression.getOperationTokenType(); + if (!thenTokenType.equals(elseExpression.getOperationTokenType())) { return false; } final PsiExpression thenLhs = thenExpression.getLExpression(); @@ -503,10 +497,8 @@ public class TrivialIfInspection extends BaseInspection { final PsiAssignmentExpression elseExpression = (PsiAssignmentExpression) elseExpressionStatement.getExpression(); - final PsiJavaToken thenSign = thenExpression.getOperationSign(); - final PsiJavaToken elseSign = elseExpression.getOperationSign(); - final IElementType thenTokenType = thenSign.getTokenType(); - if (!thenTokenType.equals(elseSign.getTokenType())) { + final IElementType thenTokenType = thenExpression.getOperationTokenType(); + if (!thenTokenType.equals(elseExpression.getOperationTokenType())) { return false; } final PsiExpression thenLhs = thenExpression.getLExpression(); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/dataflow/ConstantValueVariableUseInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/dataflow/ConstantValueVariableUseInspection.java index b20663dbe8a0..b158ca914a79 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/dataflow/ConstantValueVariableUseInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/dataflow/ConstantValueVariableUseInspection.java @@ -238,9 +238,7 @@ public class ConstantValueVariableUseInspection extends BaseInspection { return; } super.visitPrefixExpression(prefixExpression); - final PsiJavaToken operationSign = - prefixExpression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)) { return; @@ -265,9 +263,7 @@ public class ConstantValueVariableUseInspection extends BaseInspection { return; } super.visitPostfixExpression(postfixExpression); - final PsiJavaToken operationSign = - postfixExpression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = postfixExpression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)) { return; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/dataflow/ReuseOfLocalVariableInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/dataflow/ReuseOfLocalVariableInspection.java index 03dc462c8ba0..ecbff4f02cdb 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/dataflow/ReuseOfLocalVariableInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/dataflow/ReuseOfLocalVariableInspection.java @@ -185,8 +185,7 @@ public class ReuseOfLocalVariableInspection if(variable.getInitializer() == null){ return; } - final PsiJavaToken sign = assignment.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = assignment.getOperationTokenType(); if(!JavaTokenType.EQ.equals(tokenType)){ return; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/BadExceptionCaughtInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/BadExceptionCaughtInspection.java index 67fa3b18ec64..12ea1945171b 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/BadExceptionCaughtInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/BadExceptionCaughtInspection.java @@ -15,37 +15,53 @@ */ package com.siyeh.ig.errorhandling; -import com.intellij.codeInspection.ui.ListEditForm; -import com.intellij.openapi.util.InvalidDataException; -import com.intellij.openapi.util.WriteExternalException; +import com.intellij.codeInspection.ui.ListTable; +import com.intellij.codeInspection.ui.ListWrappingTableModel; +import com.intellij.openapi.actionSystem.ActionToolbar; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiCatchSection; import com.intellij.psi.PsiParameter; -import com.intellij.psi.PsiTryStatement; import com.intellij.psi.PsiType; import com.intellij.psi.PsiTypeElement; +import com.intellij.ui.ScrollPaneFactory; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; -import org.jdom.Element; +import com.siyeh.ig.ui.ExternalizableStringSet; +import com.siyeh.ig.ui.UiUtils; import org.jetbrains.annotations.NotNull; -import javax.swing.*; -import java.util.ArrayList; -import java.util.HashSet; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import java.awt.Dimension; +import java.awt.FontMetrics; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; import java.util.List; -import java.util.Set; public class BadExceptionCaughtInspection extends BaseInspection { /** @noinspection PublicField*/ - public String exceptionsString = - "java.lang.NullPointerException" + ',' + - "java.lang.IllegalMonitorStateException" + ',' + - "java.lang.ArrayIndexOutOfBoundsException"; + public String exceptionsString = ""; - final List exceptionList = new ArrayList(32); + /** @noinspection PublicField*/ + public final ExternalizableStringSet exceptions = + new ExternalizableStringSet( + "java.lang.NullPointerException", + "java.lang.IllegalMonitorStateException", + "java.lang.ArrayIndexOutOfBoundsException" + ); public BadExceptionCaughtInspection() { - parseString(exceptionsString, exceptionList); + if (exceptionsString.length() != 0) { + final List strings = + StringUtil.split(exceptionsString, ","); + for (String string : strings) { + exceptions.add(string); + } + exceptionsString = ""; + } } @NotNull @@ -53,62 +69,84 @@ public class BadExceptionCaughtInspection extends BaseInspection { return "ProhibitedExceptionCaught"; } + @Override @NotNull public String getDisplayName() { return InspectionGadgetsBundle.message( "bad.exception.caught.display.name"); } + @Override @NotNull public String buildErrorString(Object... infos) { return InspectionGadgetsBundle.message( "bad.exception.caught.problem.descriptor"); } + @Override public JComponent createOptionsPanel() { - final ListEditForm form = new ListEditForm(InspectionGadgetsBundle.message("exception.class.column.name"), - exceptionList); - return form.getContentPanel(); - } - - public void readSettings(Element element) throws InvalidDataException { - super.readSettings(element); - parseString(exceptionsString, exceptionList); - } - - public void writeSettings(Element element) throws WriteExternalException { - exceptionsString = formatString(exceptionList); - super.writeSettings(element); + final JComponent panel = new JPanel(new GridBagLayout()); + + final ListTable table = + new ListTable(new ListWrappingTableModel(exceptions, + InspectionGadgetsBundle.message( + "ignored.io.resource.types"))); + final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(table); + final FontMetrics fontMetrics = table.getFontMetrics(table.getFont()); + scrollPane.setPreferredSize(new Dimension(0, fontMetrics.getHeight() * 7)); + scrollPane.setMinimumSize(new Dimension(0, fontMetrics.getHeight() * 3)); + + final ActionToolbar toolbar = + UiUtils.createAddRemoveTreeClassChooserToolbar(table, + InspectionGadgetsBundle.message( + "exception.class.column.name"), + "java.lang.Throwable"); + + final GridBagConstraints constraints = new GridBagConstraints(); + constraints.anchor = GridBagConstraints.FIRST_LINE_START; + constraints.gridx = 0; + constraints.gridy = 0; + constraints.insets.left = 4; + constraints.insets.right = 4; + constraints.fill = GridBagConstraints.HORIZONTAL; + panel.add(toolbar.getComponent(), constraints); + + constraints.gridy = 1; + constraints.weightx = 1.0; + constraints.weighty = 1.0; + constraints.fill = GridBagConstraints.BOTH; + panel.add(scrollPane, constraints); + + return panel; } + @Override public BaseInspectionVisitor buildVisitor() { return new BadExceptionCaughtVisitor(); } private class BadExceptionCaughtVisitor extends BaseInspectionVisitor { - private final Set exceptionSet = new HashSet(exceptionList); - - @Override public void visitTryStatement(@NotNull PsiTryStatement statement) { - super.visitTryStatement(statement); - final PsiParameter[] catchBlockParameters = - statement.getCatchBlockParameters(); - for (PsiParameter parameter : catchBlockParameters) { - if(parameter == null) { - continue; - } - final PsiType type = parameter.getType(); - final String text = type.getCanonicalText(); - if (text == null) { - continue; - } - if (exceptionSet.contains(text)) { - final PsiTypeElement typeElement = - parameter.getTypeElement(); - registerError(typeElement); - } + @Override + public void visitCatchSection(PsiCatchSection section) { + super.visitCatchSection(section); + final PsiParameter parameter = section.getParameter(); + if(parameter == null) { + return; } + final PsiType type = parameter.getType(); + final String text = type.getCanonicalText(); + if (text == null) { + return; + } + if (!exceptions.contains(text)) { + return; + } + final PsiTypeElement typeElement = parameter.getTypeElement(); + if (typeElement == null) { + return; + } + registerError(typeElement); } } - } \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/EqualityToEqualsFix.java b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/EqualityToEqualsFix.java index 63b33f956ef5..a27f32828c44 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/EqualityToEqualsFix.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/EqualityToEqualsFix.java @@ -43,8 +43,7 @@ public class EqualityToEqualsFix extends InspectionGadgetsFix { return; } boolean negated=false; - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (JavaTokenType.NE.equals(tokenType)) { negated = true; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/SerialVersionUIDBuilder.java b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/SerialVersionUIDBuilder.java index 3ad54aaec625..785f9b4ee57a 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/SerialVersionUIDBuilder.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/SerialVersionUIDBuilder.java @@ -477,8 +477,7 @@ public class SerialVersionUIDBuilder extends JavaRecursiveElementVisitor{ } else if(parent instanceof PsiPostfixExpression){ final PsiPostfixExpression postfixExpression = (PsiPostfixExpression) parent; - final PsiJavaToken operationSign = postfixExpression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = postfixExpression.getOperationTokenType(); if(tokenType.equals(JavaTokenType.PLUSPLUS)){ name = ACCESS_METHOD_NAME_PREFIX + accessMethodIndex + "08"; @@ -488,8 +487,7 @@ public class SerialVersionUIDBuilder extends JavaRecursiveElementVisitor{ } } else if(parent instanceof PsiPrefixExpression){ final PsiPrefixExpression prefixExpression = (PsiPrefixExpression) parent; - final PsiJavaToken operationSign = prefixExpression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); if(tokenType.equals(JavaTokenType.PLUSPLUS)){ name = ACCESS_METHOD_NAME_PREFIX + accessMethodIndex + "04"; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/initialization/NonThreadSafeLazyInitializationInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/initialization/NonThreadSafeLazyInitializationInspection.java index 9565cfa9daa4..3fdf9b064f71 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/initialization/NonThreadSafeLazyInitializationInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/initialization/NonThreadSafeLazyInitializationInspection.java @@ -136,8 +136,7 @@ public class NonThreadSafeLazyInitializationInspection } final PsiBinaryExpression comparison = (PsiBinaryExpression) condition; - final PsiJavaToken sign = comparison.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = comparison.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.EQEQ)){ return false; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/internationalization/StringConcatenationInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/internationalization/StringConcatenationInspection.java index b0e3f37b4943..a6c45289be73 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/internationalization/StringConcatenationInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/internationalization/StringConcatenationInspection.java @@ -165,8 +165,7 @@ public class StringConcatenationInspection extends BaseInspection { if(rhs == null) { return; } - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (!JavaTokenType.PLUS.equals(tokenType)) { return; } @@ -261,7 +260,7 @@ public class StringConcatenationInspection extends BaseInspection { if (NonNlsUtils.isNonNlsAnnotatedUse(expression)) { return; } - registerError(sign, expression); + registerError(expression.getOperationSign(), expression); } private boolean isInsideAnnotation(PsiBinaryExpression expression) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/j2me/MultiplyOrDivideByPowerOfTwoInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/j2me/MultiplyOrDivideByPowerOfTwoInspection.java index e023a957141e..2727f19257f3 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/j2me/MultiplyOrDivideByPowerOfTwoInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/j2me/MultiplyOrDivideByPowerOfTwoInspection.java @@ -66,10 +66,9 @@ public class MultiplyOrDivideByPowerOfTwoInspection if (expression instanceof PsiAssignmentExpression) { final PsiAssignmentExpression exp = (PsiAssignmentExpression)expression; - final PsiJavaToken sign = exp.getOperationSign(); - lhs = exp.getLExpression(); + lhs = exp.getLExpression(); rhs = exp.getRExpression(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = exp.getOperationTokenType(); if (tokenType.equals(JavaTokenType.ASTERISKEQ)) { operator = "<<="; } else { @@ -77,10 +76,9 @@ public class MultiplyOrDivideByPowerOfTwoInspection } } else { final PsiBinaryExpression exp = (PsiBinaryExpression)expression; - final PsiJavaToken sign = exp.getOperationSign(); - lhs = exp.getLOperand(); + lhs = exp.getLOperand(); rhs = exp.getROperand(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = exp.getOperationTokenType(); if (tokenType.equals(JavaTokenType.ASTERISK)) { operator = "<<"; } else { @@ -159,9 +157,8 @@ public class MultiplyOrDivideByPowerOfTwoInspection if (rhs == null) { return; } - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.ASTERISK)) { if (!checkDivision || !tokenType.equals(JavaTokenType.DIV)) { return; @@ -186,8 +183,7 @@ public class MultiplyOrDivideByPowerOfTwoInspection if (!WellFormednessUtils.isWellFormed(expression)) { return; } - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.ASTERISKEQ)) { if (!checkDivision || !tokenType.equals(JavaTokenType.DIVEQ)) { return; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/j2me/SimplifiableIfStatementInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/j2me/SimplifiableIfStatementInspection.java index c87a8977f645..a89eba4fb367 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/j2me/SimplifiableIfStatementInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/j2me/SimplifiableIfStatementInspection.java @@ -245,9 +245,8 @@ public class SimplifiableIfStatementInspection extends BaseInspection { } else if (ComparisonUtils.isComparison(expression)) { final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) expression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final String negatedComparison = - ComparisonUtils.getNegatedComparison(sign); + final String negatedComparison = + ComparisonUtils.getNegatedComparison(binaryExpression.getOperationTokenType()); final PsiExpression lhs = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); if (ParenthesesUtils.getPrecedence(expression) > precedence) { @@ -390,13 +389,8 @@ public class SimplifiableIfStatementInspection extends BaseInspection { (PsiExpressionStatement)elseBranch; final PsiAssignmentExpression elseExpression = (PsiAssignmentExpression)elseStatement.getExpression(); - final PsiJavaToken thenOperationSign = - thenExpression.getOperationSign(); - final IElementType thenTokenType = thenOperationSign.getTokenType(); - final PsiJavaToken elseOperationSign = - elseExpression.getOperationSign(); - final IElementType elseTokenType = elseOperationSign.getTokenType(); - if (!thenTokenType.equals(elseTokenType)) { + final IElementType elseTokenType = elseExpression.getOperationTokenType(); + if (!thenExpression.getOperationTokenType().equals(elseTokenType)) { return false; } final PsiExpression thenRhs = thenExpression.getRExpression(); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/AutoUnboxingInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/AutoUnboxingInspection.java index dbf2acc0d9f5..7b88518114b0 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/AutoUnboxingInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/AutoUnboxingInspection.java @@ -148,9 +148,7 @@ public class AutoUnboxingInspection extends BaseInspection { !unboxedType.equalsToText("boolean") ) { final PsiPrefixExpression prefixExpression = (PsiPrefixExpression)parent; - final PsiJavaToken operationSign = - prefixExpression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); if (JavaTokenType.PLUSPLUS.equals(tokenType)) { replaceExpression(prefixExpression, expressionText + '=' + newExpressionText + "+1"); @@ -161,9 +159,7 @@ public class AutoUnboxingInspection extends BaseInspection { } else if (parent instanceof PsiPostfixExpression) { final PsiPostfixExpression postfixExpression = (PsiPostfixExpression)parent; - final PsiJavaToken operationSign = - postfixExpression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = postfixExpression.getOperationTokenType(); final PsiElement grandParent = postfixExpression.getParent(); if (grandParent instanceof PsiExpressionStatement) { if (JavaTokenType.PLUSPLUS.equals(tokenType)) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/SimplifiableJUnitAssertionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/SimplifiableJUnitAssertionInspection.java index 1feb199cc7d7..559ceb5ae8ed 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/SimplifiableJUnitAssertionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/SimplifiableJUnitAssertionInspection.java @@ -693,9 +693,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection { if (expression instanceof PsiBinaryExpression) { final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression; - final PsiJavaToken sign = - binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.EQEQ)) { return false; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/NegationCountVisitor.java b/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/NegationCountVisitor.java index e89767088291..bbd989ce4d06 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/NegationCountVisitor.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/methodmetrics/NegationCountVisitor.java @@ -25,8 +25,7 @@ class NegationCountVisitor extends JavaRecursiveElementVisitor { @Override public void visitBinaryExpression(@NotNull PsiBinaryExpression expression) { super.visitBinaryExpression(expression); - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (tokenType.equals(JavaTokenType.NE)) { m_count++; } @@ -38,8 +37,7 @@ class NegationCountVisitor extends JavaRecursiveElementVisitor { @Override public void visitPrefixExpression(@NotNull PsiPrefixExpression expression) { super.visitPrefixExpression(expression); - final PsiJavaToken sign = expression.getOperationSign(); - if (sign.getTokenType().equals(JavaTokenType.EXCL)) { + if (expression.getOperationTokenType().equals(JavaTokenType.EXCL)) { m_count++; } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/ForCanBeForeachInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/ForCanBeForeachInspection.java index 2f1a34d812a8..babd0bec118e 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/ForCanBeForeachInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/ForCanBeForeachInspection.java @@ -1245,8 +1245,7 @@ public class ForCanBeForeachInspection extends BaseInspection{ } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) condition; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.LT)){ return false; } @@ -1266,8 +1265,7 @@ public class ForCanBeForeachInspection extends BaseInspection{ } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) condition; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.LT)){ return null; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IfCanBeSwitchInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IfCanBeSwitchInspection.java index e38c08f88170..e025aa571464 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IfCanBeSwitchInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IfCanBeSwitchInspection.java @@ -379,8 +379,7 @@ public class IfCanBeSwitchInspection extends BaseInspection { (PsiBinaryExpression)expression; final PsiExpression lhs = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if (JavaTokenType.OROR.equals(tokenType)) { extractCaseExpressions(lhs, switchExpression, values); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IndexOfReplaceableByContainsInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IndexOfReplaceableByContainsInspection.java index 9cef431076f4..11a4f4b6c2f1 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IndexOfReplaceableByContainsInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IndexOfReplaceableByContainsInspection.java @@ -53,17 +53,16 @@ public class IndexOfReplaceableByContainsInspection public String buildErrorString(Object... infos) { final PsiBinaryExpression expression = (PsiBinaryExpression)infos[0]; final PsiExpression lhs = expression.getLOperand(); - final PsiJavaToken sign = expression.getOperationSign(); - final String text; + final String text; if (lhs instanceof PsiMethodCallExpression) { final PsiMethodCallExpression callExpression = (PsiMethodCallExpression)lhs; - text = createContainsExpressionText(callExpression, sign, false); + text = createContainsExpressionText(callExpression, false, expression.getOperationTokenType()); } else { final PsiMethodCallExpression callExpression = (PsiMethodCallExpression)expression.getROperand(); assert callExpression != null; - text = createContainsExpressionText(callExpression, sign, true); + text = createContainsExpressionText(callExpression, true, expression.getOperationTokenType()); } return InspectionGadgetsBundle.message( "indexof.replaceable.by.contains.problem.descriptor", text); @@ -89,19 +88,18 @@ public class IndexOfReplaceableByContainsInspection (PsiBinaryExpression) element; final PsiExpression lhs = expression.getLOperand(); final PsiExpression rhs = expression.getROperand(); - final PsiJavaToken sign = expression.getOperationSign(); - final String newExpressionText; + final String newExpressionText; if (lhs instanceof PsiMethodCallExpression) { final PsiMethodCallExpression callExpression = (PsiMethodCallExpression)lhs; newExpressionText = - createContainsExpressionText(callExpression, sign, - false); + createContainsExpressionText(callExpression, + false, expression.getOperationTokenType()); } else if (rhs instanceof PsiMethodCallExpression) { final PsiMethodCallExpression callExpression = (PsiMethodCallExpression)rhs; newExpressionText = - createContainsExpressionText(callExpression, sign, true); + createContainsExpressionText(callExpression, true, expression.getOperationTokenType()); } else { return; } @@ -116,10 +114,8 @@ public class IndexOfReplaceableByContainsInspection } static String createContainsExpressionText( - @NotNull PsiMethodCallExpression call, - @NotNull PsiJavaToken sign, - boolean flipped) { - final IElementType tokenType = sign.getTokenType(); + @NotNull PsiMethodCallExpression call, + boolean flipped, IElementType tokenType) { final PsiReferenceExpression methodExpression = call.getMethodExpression(); final PsiExpression qualifierExpression = @@ -169,21 +165,19 @@ public class IndexOfReplaceableByContainsInspection } final PsiExpression lhs = expression.getLOperand(); if (lhs instanceof PsiMethodCallExpression) { - final PsiJavaToken sign = expression.getOperationSign(); - if (canBeReplacedByContains(lhs, sign, rhs, false)) { + if (canBeReplacedByContains(lhs, rhs, false, expression.getOperationTokenType())) { registerError(expression, expression); } } else if (rhs instanceof PsiMethodCallExpression) { - final PsiJavaToken sign = expression.getOperationSign(); - if (canBeReplacedByContains(rhs, sign, lhs, true)) { + if (canBeReplacedByContains(rhs, lhs, true, expression.getOperationTokenType())) { registerError(expression, expression); } } } private static boolean canBeReplacedByContains( - PsiExpression lhs, PsiJavaToken sign, - PsiExpression rhs, boolean flipped) { + PsiExpression lhs, + PsiExpression rhs, boolean flipped, IElementType tokenType) { final PsiMethodCallExpression callExpression = (PsiMethodCallExpression)lhs; if (!isIndexOfCall(callExpression)) { @@ -196,7 +190,6 @@ public class IndexOfReplaceableByContainsInspection } final Integer integer = (Integer)object; final int constant = integer.intValue(); - final IElementType tokenType = sign.getTokenType(); if (flipped) { if (constant == -1 && (JavaTokenType.NE.equals(tokenType) || JavaTokenType.LT.equals(tokenType) || diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/BadOddnessInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/BadOddnessInspection.java index fea34f7ebb81..3c3992957660 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/BadOddnessInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/BadOddnessInspection.java @@ -67,8 +67,7 @@ public class BadOddnessInspection extends BaseInspection { return false; } final PsiBinaryExpression binary = (PsiBinaryExpression) exp; - final PsiJavaToken sign = binary.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binary.getOperationTokenType(); if (!JavaTokenType.PERC.equals(tokenType)) { return false; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/CharUsedInArithmeticContextInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/CharUsedInArithmeticContextInspection.java index 30a2e959fcfc..ece02825083e 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/CharUsedInArithmeticContextInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/CharUsedInArithmeticContextInspection.java @@ -13,12 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.siyeh.ig.numeric; import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.tree.IElementType; +import com.intellij.psi.util.TypeConversionUtil; import com.intellij.util.IncorrectOperationException; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; @@ -50,8 +52,8 @@ public class CharUsedInArithmeticContextInspection extends BaseInspection { @NotNull @Override protected InspectionGadgetsFix[] buildFixes(Object... infos) { - final List result = new ArrayList(); - final PsiElement expression = (PsiElement)infos[0]; + List result = new ArrayList(); + PsiElement expression = (PsiElement)infos[0]; PsiElement parent = expression.getParent(); if (parent instanceof PsiExpression) { final PsiExpression binaryExpression = @@ -65,10 +67,8 @@ public class CharUsedInArithmeticContextInspection extends BaseInspection { if (!(expression instanceof PsiLiteralExpression)) { return result.toArray(new InspectionGadgetsFix[result.size()]); } - while (parent instanceof PsiBinaryExpression) { - final PsiBinaryExpression binaryExpression = - (PsiBinaryExpression) parent; - if (TypeUtils.expressionHasType(binaryExpression, + while (parent instanceof PsiPolyadicExpression) { + if (TypeUtils.expressionHasType((PsiExpression)parent, CommonClassNames.JAVA_LANG_STRING)) { result.add(new CharUsedInArithmeticContentFix()); break; @@ -142,32 +142,31 @@ public class CharUsedInArithmeticContextInspection extends BaseInspection { private static class CharUsedInArithmeticContextVisitor extends BaseInspectionVisitor { - - @Override - public void visitBinaryExpression(PsiBinaryExpression expression) { - super.visitBinaryExpression(expression); - final PsiType type = expression.getType(); - if (type == null || type.equalsToText("java.lang.String")) { - return; - } + @Override + public void visitPolyadicExpression(PsiPolyadicExpression expression) { + super.visitPolyadicExpression(expression); final IElementType tokenType = expression.getOperationTokenType(); if (ComparisonUtils.isComparisonOperation(tokenType)) { return; } - final PsiExpression lhs = expression.getLOperand(); - final PsiType lhsType = lhs.getType(); - if (PsiType.CHAR.equals(lhsType)) { - registerError(lhs, lhs); - } - final PsiExpression rhs = expression.getROperand(); - if (rhs == null) { - return; - } - final PsiType rhsType = rhs.getType(); - if (!PsiType.CHAR.equals(rhsType)) { - return; - } - registerError(rhs, rhs); + PsiExpression[] operands = expression.getOperands(); + PsiType left = operands[0].getType(); + for (int i = 1; i < operands.length; i++) { + PsiExpression operand = operands[i]; + final PsiType rType = operand.getType(); + PsiType opType = TypeConversionUtil.calcTypeForBinaryExpression(left, rType, tokenType, true); + if (opType == null || opType.equalsToText("java.lang.String")) { + return; + } + + if (PsiType.CHAR.equals(rType)) { + registerError(operand, operand); + } + if (PsiType.CHAR.equals(left) && i == 1) { + registerError(operands[0], operands[0]); + } + left = rType; } + } } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ComparisonToNaNInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ComparisonToNaNInspection.java index 958666ac7deb..4430c0ca31eb 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ComparisonToNaNInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ComparisonToNaNInspection.java @@ -39,8 +39,7 @@ public class ComparisonToNaNInspection extends BaseInspection { @NotNull public String buildErrorString(Object... infos) { final PsiBinaryExpression comparison = (PsiBinaryExpression)infos[0]; - final PsiJavaToken sign = comparison.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = comparison.getOperationTokenType(); if (tokenType.equals(JavaTokenType.EQEQ)) { return InspectionGadgetsBundle.message( "comparison.to.nan.problem.descriptor1"); @@ -87,8 +86,7 @@ public class ComparisonToNaNInspection extends BaseInspection { } assert operand != null; final String operandText = operand.getText(); - final PsiJavaToken sign = comparison.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = comparison.getOperationTokenType(); final String negationString; if (tokenType.equals(JavaTokenType.EQEQ)) { negationString = ""; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/DivideByZeroInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/DivideByZeroInspection.java index 8e85f5af600e..f36a4d9e6b73 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/DivideByZeroInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/DivideByZeroInspection.java @@ -54,8 +54,7 @@ public class DivideByZeroInspection extends BaseInspection { if (rhs == null) { return; } - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.DIV) && !tokenType.equals(JavaTokenType.PERC)) { return; @@ -78,8 +77,7 @@ public class DivideByZeroInspection extends BaseInspection { if (rhs == null) { return; } - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.DIVEQ) && !tokenType.equals(JavaTokenType.PERCEQ)) { return; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ImplicitNumericConversionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ImplicitNumericConversionInspection.java index 93e815e6ce34..1be0aae39005 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ImplicitNumericConversionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ImplicitNumericConversionInspection.java @@ -243,8 +243,7 @@ public class ImplicitNumericConversionInspection extends BaseInspection { } final PsiPrefixExpression prefixExpression = (PsiPrefixExpression)expression; - final PsiJavaToken sign = prefixExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); if (!JavaTokenType.MINUS.equals(tokenType)) { return false; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/IntegerDivisionInFloatingPointContextInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/IntegerDivisionInFloatingPointContextInspection.java index f02675881c22..da4e9a330355 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/IntegerDivisionInFloatingPointContextInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/IntegerDivisionInFloatingPointContextInspection.java @@ -72,8 +72,7 @@ public class IntegerDivisionInFloatingPointContextInspection @Override public void visitBinaryExpression( @NotNull PsiBinaryExpression expression) { super.visitBinaryExpression(expression); - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.DIV)) { return; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/IntegerMultiplicationImplicitCastToLongInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/IntegerMultiplicationImplicitCastToLongInspection.java index 9c1ba2ba268e..127cffc272a3 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/IntegerMultiplicationImplicitCastToLongInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/IntegerMultiplicationImplicitCastToLongInspection.java @@ -79,8 +79,7 @@ public class IntegerMultiplicationImplicitCastToLongInspection extends @Override public void visitBinaryExpression( @NotNull PsiBinaryExpression expression) { super.visitBinaryExpression(expression); - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.ASTERISK) && !tokenType.equals(JavaTokenType.LTLT)) { return; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/OverlyComplexArithmeticExpressionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/OverlyComplexArithmeticExpressionInspection.java index 434257b08ba2..13f24a95b9cc 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/OverlyComplexArithmeticExpressionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/OverlyComplexArithmeticExpressionInspection.java @@ -16,6 +16,7 @@ package com.siyeh.ig.numeric; import com.intellij.psi.*; +import com.intellij.psi.tree.IElementType; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; @@ -37,15 +38,15 @@ public class OverlyComplexArithmeticExpressionInspection /** @noinspection PublicField */ public int m_limit = TERM_LIMIT; //this is public for the DefaultJDOMExternalizer thingy - private static final Set arithmeticTokens = - new HashSet(5); + private static final Set arithmeticTokens = + new HashSet(5); static { - arithmeticTokens.add("+"); - arithmeticTokens.add("-"); - arithmeticTokens.add("*"); - arithmeticTokens.add("/"); - arithmeticTokens.add("%"); + arithmeticTokens.add(JavaTokenType.PLUS); + arithmeticTokens.add(JavaTokenType.MINUS); + arithmeticTokens.add(JavaTokenType.ASTERISK); + arithmeticTokens.add(JavaTokenType.DIV); + arithmeticTokens.add(JavaTokenType.PERC); } @Override @@ -162,16 +163,12 @@ public class OverlyComplexArithmeticExpressionInspection } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final String signText = sign.getText(); - return arithmeticTokens.contains(signText); + return arithmeticTokens.contains(binaryExpression.getOperationTokenType()); } else if (expression instanceof PsiPrefixExpression) { final PsiPrefixExpression prefixExpression = (PsiPrefixExpression)expression; - final PsiJavaToken sign = prefixExpression.getOperationSign(); - final String signText = sign.getText(); - return arithmeticTokens.contains(signText); + return arithmeticTokens.contains(prefixExpression.getOperationTokenType()); } else if (expression instanceof PsiParenthesizedExpression) { final PsiParenthesizedExpression parenthesizedExpression = diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspection.java index a15975403114..abaf829aae04 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspection.java @@ -38,20 +38,20 @@ import java.util.Set; public class PointlessArithmeticExpressionInspection extends BaseInspection { - private static final Set arithmeticTokens = - new HashSet(9); + private static final Set arithmeticTokens = + new HashSet(5); - static { - arithmeticTokens.add("+"); - arithmeticTokens.add("-"); - arithmeticTokens.add("*"); - arithmeticTokens.add("/"); - arithmeticTokens.add("%"); - arithmeticTokens.add(">"); - arithmeticTokens.add("<"); - arithmeticTokens.add("<="); - arithmeticTokens.add(">="); - } + static { + arithmeticTokens.add(JavaTokenType.PLUS); + arithmeticTokens.add(JavaTokenType.MINUS); + arithmeticTokens.add(JavaTokenType.ASTERISK); + arithmeticTokens.add(JavaTokenType.DIV); + arithmeticTokens.add(JavaTokenType.PERC); + arithmeticTokens.add(JavaTokenType.GT); + arithmeticTokens.add(JavaTokenType.LT); + arithmeticTokens.add(JavaTokenType.LE); + arithmeticTokens.add(JavaTokenType.GE); + } /** * @noinspection PublicField @@ -90,11 +90,10 @@ public class PointlessArithmeticExpressionInspection String calculateReplacementExpression( PsiExpression expression) { final PsiBinaryExpression exp = (PsiBinaryExpression) expression; - final PsiJavaToken sign = exp.getOperationSign(); - final PsiExpression lhs = exp.getLOperand(); + final PsiExpression lhs = exp.getLOperand(); final PsiExpression rhs = exp.getROperand(); assert rhs != null; - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = exp.getOperationTokenType(); if (tokenType.equals(JavaTokenType.PLUS)) { if (isZero(lhs)) { return rhs.getText(); @@ -169,9 +168,7 @@ public class PointlessArithmeticExpressionInspection PsiType.FLOAT.equals(expressionType)) { return; } - final PsiJavaToken sign = expression.getOperationSign(); - final String signText = sign.getText(); - if (!arithmeticTokens.contains(signText)) { + if (!arithmeticTokens.contains(expression.getOperationTokenType())) { return; } if (TypeUtils.expressionHasType(expression, @@ -179,7 +176,7 @@ public class PointlessArithmeticExpressionInspection return; } final PsiExpression lhs = expression.getLOperand(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); final boolean isPointless; if (tokenType.equals(JavaTokenType.PLUS)) { isPointless = additionExpressionIsPointless(lhs, rhs); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/LengthOneStringsInConcatenationInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/LengthOneStringsInConcatenationInspection.java index 2bf7cfea75ad..4a5600335112 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/LengthOneStringsInConcatenationInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/LengthOneStringsInConcatenationInspection.java @@ -113,8 +113,7 @@ public class LengthOneStringsInConcatenationInspection return false; } final PsiBinaryExpression binaryExp = (PsiBinaryExpression)parent; - final PsiJavaToken sign = binaryExp.getOperationSign(); - if (!JavaTokenType.PLUS.equals(sign.getTokenType())) { + if (!JavaTokenType.PLUS.equals(binaryExp.getOperationTokenType())) { return false; } final PsiExpression lhs = binaryExp.getLOperand(); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/ManualArrayCopyInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/ManualArrayCopyInspection.java index ff623e5ae556..9ec183594e2e 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/ManualArrayCopyInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/ManualArrayCopyInspection.java @@ -562,8 +562,7 @@ public class ManualArrayCopyInspection extends BaseInspection { } final PsiAssignmentExpression assignment = (PsiAssignmentExpression)strippedExpression; - final PsiJavaToken sign = assignment.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = assignment.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.EQ)) { return false; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/RandomDoubleForRandomIntegerInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/RandomDoubleForRandomIntegerInspection.java index e6ae0cbbad7d..a6f84a528522 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/RandomDoubleForRandomIntegerInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/RandomDoubleForRandomIntegerInspection.java @@ -160,8 +160,7 @@ public class RandomDoubleForRandomIntegerInspection } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); return JavaTokenType.ASTERISK.equals(tokenType); } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/SizeReplaceableByIsEmptyInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/SizeReplaceableByIsEmptyInspection.java index 1996230b6d82..b8af1335ea5a 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/SizeReplaceableByIsEmptyInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/SizeReplaceableByIsEmptyInspection.java @@ -98,8 +98,7 @@ public class SizeReplaceableByIsEmptyInspection extends BaseInspection { return; } @NonNls String newExpression = qualifierExpression.getText(); - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if (!JavaTokenType.EQEQ.equals(tokenType)) { newExpression = '!' + newExpression; } @@ -129,21 +128,19 @@ public class SizeReplaceableByIsEmptyInspection extends BaseInspection { } final PsiExpression lhs = expression.getLOperand(); if (lhs instanceof PsiMethodCallExpression) { - final PsiJavaToken sign = expression.getOperationSign(); - if (canBeReplacedByIsEmpty(lhs, sign, rhs, false)) { + if (canBeReplacedByIsEmpty(lhs, rhs, false, expression.getOperationTokenType())) { registerError(expression, isEmptyCall); } } else if (rhs instanceof PsiMethodCallExpression) { - final PsiJavaToken sign = expression.getOperationSign(); - if (canBeReplacedByIsEmpty(rhs, sign, lhs, true)) { + if (canBeReplacedByIsEmpty(rhs, lhs, true, expression.getOperationTokenType())) { registerError(expression, isEmptyCall); } } } private boolean canBeReplacedByIsEmpty( - PsiExpression lhs, PsiJavaToken sign, PsiExpression rhs, - boolean flipped) { + PsiExpression lhs, PsiExpression rhs, + boolean flipped, IElementType tokenType) { final PsiMethodCallExpression callExpression = (PsiMethodCallExpression)lhs; if (!isSizeCall(callExpression)) { @@ -159,8 +156,7 @@ public class SizeReplaceableByIsEmptyInspection extends BaseInspection { if (constant != 0) { return false; } - final IElementType tokenType = sign.getTokenType(); - if (JavaTokenType.EQEQ.equals(tokenType)) { + if (JavaTokenType.EQEQ.equals(tokenType)) { return true; } if (ignoreNegations) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringBufferToStringInConcatenationInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringBufferToStringInConcatenationInspection.java index 6bb758357b70..314899618e01 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringBufferToStringInConcatenationInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringBufferToStringInConcatenationInspection.java @@ -93,8 +93,7 @@ public class StringBufferToStringInConcatenationInspection } final PsiBinaryExpression parentBinary = (PsiBinaryExpression)parent; - final PsiJavaToken sign = parentBinary.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = parentBinary.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.PLUS)) { return; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringConcatenationInLoopsInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringConcatenationInLoopsInspection.java index bc68834f7b09..0e1162419f2d 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringConcatenationInLoopsInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringConcatenationInLoopsInspection.java @@ -70,41 +70,38 @@ public class StringConcatenationInLoopsInspection extends BaseInspection { private class StringConcatenationInLoopsVisitor extends BaseInspectionVisitor { - - @Override public void visitBinaryExpression( - @NotNull PsiBinaryExpression expression) { - super.visitBinaryExpression(expression); - if (expression.getROperand() == null) { + @Override + public void visitPolyadicExpression(PsiPolyadicExpression expression) { + super.visitPolyadicExpression(expression); + PsiExpression[] operands = expression.getOperands(); + if (operands.length <= 1) { return; } - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); - if (!tokenType.equals(JavaTokenType.PLUS)) { - return; - } - final PsiType type = expression.getType(); - if (type == null) { - return; - } - if (!TypeUtils.isJavaLangString(type)) { - return; - } - if (!ControlFlowUtils.isInLoop(expression)) { - return; - } - if (ControlFlowUtils.isInExitStatement(expression)) { - return; - } - if (ExpressionUtils.isEvaluatedAtCompileTime(expression)) { - return; - } - if (containingStatementExits(expression)) { - return; - } - if (m_ignoreUnlessAssigned && !isAppendedRepeatedly(expression)) { - return; - } - registerError(sign); + final IElementType tokenType = expression.getOperationTokenType(); + if (!tokenType.equals(JavaTokenType.PLUS)) { + return; + } + final PsiType type = expression.getType(); + if (!TypeUtils.isJavaLangString(type)) { + return; + } + if (!ControlFlowUtils.isInLoop(expression)) { + return; + } + if (ControlFlowUtils.isInExitStatement(expression)) { + return; + } + if (ExpressionUtils.isEvaluatedAtCompileTime(expression)) { + return; + } + if (containingStatementExits(expression)) { + return; + } + if (m_ignoreUnlessAssigned && !isAppendedRepeatedly(expression)) { + return; + } + final PsiJavaToken sign = expression.getTokenBeforeOperand(operands[1]); + registerError(sign); } @Override public void visitAssignmentExpression( @@ -164,7 +161,7 @@ public class StringConcatenationInLoopsInspection extends BaseInspection { private boolean isAppendedRepeatedly(PsiExpression expression) { PsiElement parent = expression.getParent(); while (parent instanceof PsiParenthesizedExpression || - parent instanceof PsiBinaryExpression) { + parent instanceof PsiPolyadicExpression) { parent = parent.getParent(); } if (!(parent instanceof PsiAssignmentExpression)) { @@ -197,4 +194,4 @@ public class StringConcatenationInLoopsInspection extends BaseInspection { VariableAccessUtils.variableIsUsed(variable, rhs); } } -} \ No newline at end of file +} diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringVariableIsAppendedToVisitor.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringVariableIsAppendedToVisitor.java index 7329dc39e36a..d50456a032a4 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringVariableIsAppendedToVisitor.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/StringVariableIsAppendedToVisitor.java @@ -56,8 +56,7 @@ class StringVariableIsAppendedToVisitor extends JavaRecursiveElementVisitor { if (!variable.equals(referent)) { return; } - final PsiJavaToken operationSign = assignment.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = assignment.getOperationTokenType(); if (tokenType.equals(JavaTokenType.PLUSEQ)) { if (onlyWarnOnLoop && !ControlFlowUtils.isInLoop(assignment)) { return; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ArrayContentsAssignedVisitor.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ArrayContentsAssignedVisitor.java index bfb6388299ac..4a867562af5b 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ArrayContentsAssignedVisitor.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ArrayContentsAssignedVisitor.java @@ -57,8 +57,7 @@ class ArrayContentsAssignedVisitor extends JavaRecursiveElementVisitor { return; } super.visitPrefixExpression(expression); - final PsiJavaToken operationSign = expression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(!(tokenType.equals(JavaTokenType.PLUSPLUS) || tokenType.equals(JavaTokenType.MINUSMINUS))){ return; @@ -84,8 +83,7 @@ class ArrayContentsAssignedVisitor extends JavaRecursiveElementVisitor { return; } super.visitPostfixExpression(expression); - final PsiJavaToken operationSign = expression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(!(tokenType.equals(JavaTokenType.PLUSPLUS) || tokenType.equals(JavaTokenType.MINUSMINUS))){ return; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/BoolUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/BoolUtils.java index 047817b799ad..33779d815774 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/BoolUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/BoolUtils.java @@ -29,8 +29,7 @@ public class BoolUtils { return false; } final PsiPrefixExpression prefixExp = (PsiPrefixExpression) expression; - final PsiJavaToken sign = prefixExp.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = prefixExp.getOperationTokenType(); return JavaTokenType.EXCL.equals(tokenType); } @@ -61,9 +60,8 @@ public class BoolUtils { } else if (ComparisonUtils.isComparison(condition)) { final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) condition; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final String negatedComparison = - ComparisonUtils.getNegatedComparison(sign); + final String negatedComparison = + ComparisonUtils.getNegatedComparison(binaryExpression.getOperationTokenType()); final PsiExpression lhs = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); if (rhs == null) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ComparisonUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ComparisonUtils.java index 831aed9c4f74..36de90adc697 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ComparisonUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ComparisonUtils.java @@ -18,7 +18,6 @@ package com.siyeh.ig.psiutils; import com.intellij.psi.JavaTokenType; import com.intellij.psi.PsiBinaryExpression; import com.intellij.psi.PsiExpression; -import com.intellij.psi.PsiJavaToken; import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -74,8 +73,7 @@ public class ComparisonUtils { } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) expression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); return isComparisonOperation(tokenType); } @@ -83,9 +81,8 @@ public class ComparisonUtils { return s_comparisonTokens.contains(tokenType); } - public static String getFlippedComparison(@NotNull PsiJavaToken token) { - final IElementType tokenType = token.getTokenType(); - return s_swappedComparisons.get(tokenType); + public static String getFlippedComparison(IElementType tokenType) { + return s_swappedComparisons.get(tokenType); } public static boolean isEqualityComparison( @@ -95,8 +92,7 @@ public class ComparisonUtils { tokenType.equals(JavaTokenType.NE); } - public static String getNegatedComparison(@NotNull PsiJavaToken token) { - final IElementType tokenType = token.getTokenType(); - return s_invertedComparisons.get(tokenType); - } + public static String getNegatedComparison(IElementType tokenType) { + return s_invertedComparisons.get(tokenType); + } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/EquivalenceChecker.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/EquivalenceChecker.java index 44cc20fb78d2..fd0eb7fd6bc2 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/EquivalenceChecker.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/EquivalenceChecker.java @@ -879,10 +879,8 @@ public class EquivalenceChecker{ private static boolean prefixExpressionsAreEquivalent( @NotNull PsiPrefixExpression prefixExp1, @NotNull PsiPrefixExpression prefixExp2){ - final PsiJavaToken sign1 = prefixExp1.getOperationSign(); - final PsiJavaToken sign2 = prefixExp2.getOperationSign(); - final IElementType tokenType1 = sign1.getTokenType(); - if(!tokenType1.equals(sign2.getTokenType())){ + final IElementType tokenType1 = prefixExp1.getOperationTokenType(); + if(!tokenType1.equals(prefixExp2.getOperationTokenType())){ return false; } final PsiExpression operand1 = prefixExp1.getOperand(); @@ -893,10 +891,8 @@ public class EquivalenceChecker{ private static boolean postfixExpressionsAreEquivalent( @NotNull PsiPostfixExpression postfixExp1, @NotNull PsiPostfixExpression postfixExp2){ - final PsiJavaToken sign1 = postfixExp1.getOperationSign(); - final PsiJavaToken sign2 = postfixExp2.getOperationSign(); - final IElementType tokenType1 = sign1.getTokenType(); - if(!tokenType1.equals(sign2.getTokenType())){ + final IElementType tokenType1 = postfixExp1.getOperationTokenType(); + if(!tokenType1.equals(postfixExp2.getOperationTokenType())){ return false; } final PsiExpression operand1 = postfixExp1.getOperand(); @@ -907,10 +903,8 @@ public class EquivalenceChecker{ private static boolean binaryExpressionsAreEquivalent( @NotNull PsiBinaryExpression binaryExp1, @NotNull PsiBinaryExpression binaryExp2){ - final PsiJavaToken sign1 = binaryExp1.getOperationSign(); - final PsiJavaToken sign2 = binaryExp2.getOperationSign(); - final IElementType tokenType1 = sign1.getTokenType(); - if(!tokenType1.equals(sign2.getTokenType())){ + final IElementType tokenType1 = binaryExp1.getOperationTokenType(); + if(!tokenType1.equals(binaryExp2.getOperationTokenType())){ return false; } final PsiExpression lhs1 = binaryExp1.getLOperand(); @@ -924,10 +918,8 @@ public class EquivalenceChecker{ private static boolean assignmentExpressionsAreEquivalent( @NotNull PsiAssignmentExpression assignExp1, @NotNull PsiAssignmentExpression assignExp2){ - final PsiJavaToken sign1 = assignExp1.getOperationSign(); - final PsiJavaToken sign2 = assignExp2.getOperationSign(); - final IElementType tokenType1 = sign1.getTokenType(); - if(!tokenType1.equals(sign2.getTokenType())){ + final IElementType tokenType1 = assignExp1.getOperationTokenType(); + if(!tokenType1.equals(assignExp2.getOperationTokenType())){ return false; } final PsiExpression lhs1 = assignExp1.getLExpression(); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpectedTypeUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpectedTypeUtils.java index e4ed99576fc3..34bc5d381747 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpectedTypeUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpectedTypeUtils.java @@ -157,8 +157,7 @@ public class ExpectedTypeUtils{ @Override public void visitBinaryExpression( @NotNull PsiBinaryExpression binaryExpression) { - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); final PsiType type = binaryExpression.getType(); final PsiExpression rhs = binaryExpression.getROperand(); if (rhs == null) { @@ -295,9 +294,7 @@ public class ExpectedTypeUtils{ @Override public void visitAssignmentExpression( @NotNull PsiAssignmentExpression assignment){ final PsiExpression rExpression = assignment.getRExpression(); - final PsiJavaToken operationSign = - assignment.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = assignment.getOperationTokenType(); final PsiExpression lExpression = assignment.getLExpression(); final PsiType lType = lExpression.getType(); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java index 4663d4a85e31..47f09f6e726f 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java @@ -243,19 +243,17 @@ public class ExpressionUtils { if (condition instanceof PsiPrefixExpression) { final PsiPrefixExpression prefixExpression = (PsiPrefixExpression)condition; - final PsiJavaToken sign = prefixExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); return tokenType.equals(JavaTokenType.EXCL); } else if (condition instanceof PsiBinaryExpression) { final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)condition; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final PsiExpression lhs = binaryExpression.getLOperand(); + final PsiExpression lhs = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); if (rhs == null) { return false; } - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if (tokenType.equals(JavaTokenType.NE)) { if (ignoreNegatedNullComparison) { final String lhsText = lhs.getText(); @@ -307,8 +305,7 @@ public class ExpressionUtils { } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)strippedExpression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if (!JavaTokenType.PLUS.equals(tokenType) && !JavaTokenType.MINUS.equals(tokenType)) { return false; @@ -331,8 +328,7 @@ public class ExpressionUtils { } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if (tokenType.equals(JavaTokenType.LT) || tokenType.equals(JavaTokenType.LE)) { final PsiExpression lhs = binaryExpression.getLOperand(); @@ -354,8 +350,7 @@ public class ExpressionUtils { } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if (tokenType.equals(JavaTokenType.GT) || tokenType.equals(JavaTokenType.GE)) { final PsiExpression lhs = binaryExpression.getLOperand(); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/InstanceOfUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/InstanceOfUtils.java index 18e59e367419..1b8168fa6e9b 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/InstanceOfUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/InstanceOfUtils.java @@ -109,9 +109,7 @@ public class InstanceOfUtils { @Override public void visitBinaryExpression( PsiBinaryExpression expression) { - final PsiJavaToken sign = - expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (tokenType == JavaTokenType.ANDAND) { checkExpression(expression.getLOperand()); if (agreeingInstanceof) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java index bbfb0a75a10f..c4d14cc628ab 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java @@ -126,11 +126,11 @@ public class ParenthesesUtils{ if(expression instanceof PsiPostfixExpression){ return POSTFIX_PRECEDENCE; } - if(expression instanceof PsiBinaryExpression){ - final PsiBinaryExpression binaryExpression = - (PsiBinaryExpression)expression; - final PsiJavaToken sign = - binaryExpression.getOperationSign(); + if(expression instanceof PsiPolyadicExpression){ + final PsiPolyadicExpression binaryExpression = + (PsiPolyadicExpression)expression; + final IElementType sign = + binaryExpression.getOperationTokenType(); return getPrecedenceForBinaryOperator(sign); } if(expression instanceof PsiInstanceOfExpression){ @@ -214,9 +214,9 @@ public class ParenthesesUtils{ removeParensFromPostfixExpression(postfixExpression, ignoreClarifyingParentheses); } - if(expression instanceof PsiBinaryExpression){ - final PsiBinaryExpression binaryExpression = - (PsiBinaryExpression)expression; + if(expression instanceof PsiPolyadicExpression){ + final PsiPolyadicExpression binaryExpression = + (PsiPolyadicExpression)expression; removeParensFromBinaryExpression(binaryExpression, ignoreClarifyingParentheses); } @@ -282,23 +282,22 @@ public class ParenthesesUtils{ removeParentheses(expression, ignoreClarifyingParentheses); } } else if(parentPrecedence == childPrecedence){ - if(parentExpression instanceof PsiBinaryExpression && - body instanceof PsiBinaryExpression){ - final PsiBinaryExpression parentBinaryExpression = - (PsiBinaryExpression)parentExpression; + if(parentExpression instanceof PsiPolyadicExpression && + body instanceof PsiPolyadicExpression){ + final PsiPolyadicExpression parentBinaryExpression = + (PsiPolyadicExpression)parentExpression; final IElementType parentOperator = parentBinaryExpression.getOperationTokenType(); - final PsiBinaryExpression bodyBinaryExpression = - (PsiBinaryExpression)body; + final PsiPolyadicExpression bodyBinaryExpression = + (PsiPolyadicExpression)body; final IElementType bodyOperator = bodyBinaryExpression.getOperationTokenType(); final PsiType parentType = parentBinaryExpression.getType(); final PsiType bodyType = body.getType(); if(parentType != null && parentType.equals(bodyType) && parentOperator.equals(bodyOperator)) { - final PsiExpression rhs = - parentBinaryExpression.getROperand(); - if (!PsiTreeUtil.isAncestor(rhs, body, true) || + PsiExpression[] parentOperands = parentBinaryExpression.getOperands(); + if (PsiTreeUtil.isAncestor(parentOperands[0], body, true) || isCommutativeBinaryOperator(bodyOperator)) { // use addAfter() + delete() instead of replace() to // workaround automatic insertion of parentheses by psi @@ -327,8 +326,8 @@ public class ParenthesesUtils{ } } else { if (ignoreClarifyingParentheses && - parent instanceof PsiBinaryExpression && - (body instanceof PsiBinaryExpression || + parent instanceof PsiPolyadicExpression && + (body instanceof PsiPolyadicExpression || body instanceof PsiInstanceOfExpression)) { removeParentheses(body, ignoreClarifyingParentheses); } else { @@ -366,15 +365,12 @@ public class ParenthesesUtils{ } private static void removeParensFromBinaryExpression( - @NotNull PsiBinaryExpression binaryExpression, + @NotNull PsiPolyadicExpression binaryExpression, boolean ignoreClarifyingParentheses) throws IncorrectOperationException { - final PsiExpression lhs = binaryExpression.getLOperand(); - removeParentheses(lhs, ignoreClarifyingParentheses); - final PsiExpression rhs = binaryExpression.getROperand(); - if (rhs != null) { - removeParentheses(rhs, ignoreClarifyingParentheses); - } + for (PsiExpression operand : binaryExpression.getOperands()) { + removeParentheses(operand, ignoreClarifyingParentheses); + } } private static void removeParensFromPostfixExpression( @@ -495,12 +491,13 @@ public class ParenthesesUtils{ public static boolean areParenthesesNeeded( PsiExpression expression, PsiElement parentExpression, boolean ignoreClarifyingParentheses) { - if (parentExpression instanceof PsiBinaryExpression) { - final PsiBinaryExpression parentBinaryExpression = - (PsiBinaryExpression) parentExpression; - if (expression instanceof PsiBinaryExpression) { - final PsiBinaryExpression childBinaryExpression = - (PsiBinaryExpression)expression; + if (parentExpression instanceof PsiPolyadicExpression) { + final PsiPolyadicExpression parentBinaryExpression = + (PsiPolyadicExpression) parentExpression; + PsiExpression[] parentOperands = parentBinaryExpression.getOperands(); + if (expression instanceof PsiPolyadicExpression) { + final PsiPolyadicExpression childBinaryExpression = + (PsiPolyadicExpression)expression; final IElementType childOperator = childBinaryExpression.getOperationTokenType(); final IElementType parentOperator = @@ -517,24 +514,24 @@ public class ParenthesesUtils{ if (!parentType.equals(childType)) { return true; } - if (PsiTreeUtil.isAncestor(parentBinaryExpression.getROperand(), - expression, false)) { + if (!PsiTreeUtil.isAncestor(parentOperands[0], + expression, false)) { if (!isCommutativeBinaryOperator(parentOperator)) { return true; } } return false; } else if (expression instanceof PsiConditionalExpression) { - if (PsiTreeUtil.isAncestor(parentBinaryExpression.getROperand(), - expression, false)) { + if (!PsiTreeUtil.isAncestor(parentOperands[0], + expression, false)) { return true; } } } else if (parentExpression instanceof PsiPrefixExpression) { - if (expression instanceof PsiBinaryExpression) { + if (expression instanceof PsiPolyadicExpression) { return true; } } return false; } -} \ No newline at end of file +} diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/RecursionUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/RecursionUtils.java index c55212e1bfdd..370fa0bf0b25 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/RecursionUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/RecursionUtils.java @@ -298,8 +298,7 @@ public class RecursionUtils{ if(expressionDefinitelyRecurses(lhs, method)){ return true; } - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(tokenType.equals(JavaTokenType.ANDAND) || tokenType.equals(JavaTokenType.OROR)){ return false; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SideEffectChecker.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SideEffectChecker.java index 61866da5f0da..0ff1c3395cc4 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SideEffectChecker.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SideEffectChecker.java @@ -73,8 +73,7 @@ public class SideEffectChecker{ return; } super.visitPostfixExpression(expression); - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(tokenType.equals(JavaTokenType.PLUSPLUS) || tokenType.equals(JavaTokenType.MINUSMINUS)){ mayHaveSideEffects = true; @@ -87,8 +86,7 @@ public class SideEffectChecker{ return; } super.visitPrefixExpression(expression); - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(tokenType.equals(JavaTokenType.PLUSPLUS) || tokenType.equals(JavaTokenType.MINUSMINUS)){ mayHaveSideEffects = true; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SwitchUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SwitchUtils.java index 6c2fd4d6f77c..3c5fe00d77ac 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SwitchUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SwitchUtils.java @@ -101,8 +101,7 @@ public class SwitchUtils{ } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) expression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType operation = sign.getTokenType(); + final IElementType operation = binaryExpression.getOperationTokenType(); final PsiExpression lhs = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); if(operation.equals(JavaTokenType.OROR)){ @@ -143,8 +142,7 @@ public class SwitchUtils{ } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) expression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType operation = sign.getTokenType(); + final IElementType operation = binaryExpression.getOperationTokenType(); final PsiExpression lhs = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); if(operation.equals(JavaTokenType.OROR)){ diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/VariableAccessUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/VariableAccessUtils.java index 3af1b91ae281..805b4894ac44 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/VariableAccessUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/VariableAccessUtils.java @@ -263,8 +263,7 @@ public class VariableAccessUtils{ if (expression instanceof PsiPrefixExpression) { final PsiPrefixExpression prefixExpression = (PsiPrefixExpression)expression; - final PsiJavaToken sign = prefixExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.MINUSMINUS)) { return false; } @@ -273,8 +272,7 @@ public class VariableAccessUtils{ } else if (expression instanceof PsiPostfixExpression) { final PsiPostfixExpression postfixExpression = (PsiPostfixExpression)expression; - final PsiJavaToken sign = postfixExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = postfixExpression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.MINUSMINUS)) { return false; } @@ -334,8 +332,7 @@ public class VariableAccessUtils{ if (expression instanceof PsiPrefixExpression) { final PsiPrefixExpression prefixExpression = (PsiPrefixExpression)expression; - final PsiJavaToken sign = prefixExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.PLUSPLUS)) { return false; } @@ -344,8 +341,7 @@ public class VariableAccessUtils{ } else if (expression instanceof PsiPostfixExpression) { final PsiPostfixExpression postfixExpression = (PsiPostfixExpression)expression; - final PsiJavaToken sign = postfixExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = postfixExpression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.PLUSPLUS)) { return false; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/VariableAssignedVisitor.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/VariableAssignedVisitor.java index d9786e40c37b..e3bd1bad5cac 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/VariableAssignedVisitor.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/VariableAssignedVisitor.java @@ -74,8 +74,7 @@ class VariableAssignedVisitor extends JavaRecursiveElementVisitor{ return; } super.visitPrefixExpression(prefixExpression); - final PsiJavaToken operationSign = prefixExpression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)){ return; @@ -95,8 +94,7 @@ class VariableAssignedVisitor extends JavaRecursiveElementVisitor{ return; } super.visitPostfixExpression(postfixExpression); - final PsiJavaToken operationSign = postfixExpression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = postfixExpression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)){ return; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/VariableValueUsedVisitor.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/VariableValueUsedVisitor.java index e3eaa104943b..9f583e75dc45 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/VariableValueUsedVisitor.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/VariableValueUsedVisitor.java @@ -72,9 +72,7 @@ class VariableValueUsedVisitor extends JavaRecursiveElementVisitor { return; } super.visitPrefixExpression(prefixExpression); - final PsiJavaToken operationSign = - prefixExpression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)) { return; @@ -99,9 +97,7 @@ class VariableValueUsedVisitor extends JavaRecursiveElementVisitor { return; } super.visitPostfixExpression(postfixExpression); - final PsiJavaToken operationSign = - postfixExpression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = postfixExpression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)) { return; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ChainedEqualityInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ChainedEqualityInspection.java index 51a610e17b5b..f5964ab0c5ea 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ChainedEqualityInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ChainedEqualityInspection.java @@ -18,7 +18,6 @@ package com.siyeh.ig.style; import com.intellij.psi.JavaTokenType; import com.intellij.psi.PsiBinaryExpression; import com.intellij.psi.PsiExpression; -import com.intellij.psi.PsiJavaToken; import com.intellij.psi.tree.IElementType; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; @@ -71,8 +70,7 @@ public class ChainedEqualityInspection extends BaseInspection { private static boolean isEqualityComparison( @NotNull PsiBinaryExpression expression) { - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); return tokenType.equals(JavaTokenType.EQEQ) || tokenType.equals(JavaTokenType.NE); } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnLHSOfComparisonInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnLHSOfComparisonInspection.java index d1a38e00189a..ef01c707cb45 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnLHSOfComparisonInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnLHSOfComparisonInspection.java @@ -19,7 +19,6 @@ import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiBinaryExpression; import com.intellij.psi.PsiExpression; -import com.intellij.psi.PsiJavaToken; import com.intellij.psi.util.PsiUtil; import com.intellij.util.IncorrectOperationException; import com.siyeh.InspectionGadgetsBundle; @@ -78,9 +77,8 @@ public class ConstantOnLHSOfComparisonInspection extends BaseInspection { if (rhs == null) { return; } - final PsiJavaToken sign = expression.getOperationSign(); - final String flippedComparison = - ComparisonUtils.getFlippedComparison(sign); + final String flippedComparison = + ComparisonUtils.getFlippedComparison(expression.getOperationTokenType()); if (flippedComparison == null) { return; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnRHSOfComparisonInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnRHSOfComparisonInspection.java index 518ffacfb650..dcc6d0f2e52f 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnRHSOfComparisonInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ConstantOnRHSOfComparisonInspection.java @@ -19,7 +19,6 @@ import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiBinaryExpression; import com.intellij.psi.PsiExpression; -import com.intellij.psi.PsiJavaToken; import com.intellij.psi.util.PsiUtil; import com.intellij.util.IncorrectOperationException; import com.siyeh.InspectionGadgetsBundle; @@ -78,9 +77,8 @@ public class ConstantOnRHSOfComparisonInspection extends BaseInspection { if (rhs == null) { return; } - final PsiJavaToken sign = expression.getOperationSign(); - final String flippedComparison = - ComparisonUtils.getFlippedComparison(sign); + final String flippedComparison = + ComparisonUtils.getFlippedComparison(expression.getOperationTokenType()); if (flippedComparison == null) { return; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ListIndexOfReplaceableByContainsInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ListIndexOfReplaceableByContainsInspection.java index 4a312fac4cdf..5d1dc5c4f385 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ListIndexOfReplaceableByContainsInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ListIndexOfReplaceableByContainsInspection.java @@ -47,17 +47,16 @@ public class ListIndexOfReplaceableByContainsInspection public String buildErrorString(Object... infos) { final PsiBinaryExpression expression = (PsiBinaryExpression)infos[0]; final PsiExpression lhs = expression.getLOperand(); - final PsiJavaToken sign = expression.getOperationSign(); - final String text; + final String text; if (lhs instanceof PsiMethodCallExpression) { final PsiMethodCallExpression callExpression = (PsiMethodCallExpression)lhs; - text = createContainsExpressionText(callExpression, sign, false); + text = createContainsExpressionText(callExpression, false, expression.getOperationTokenType()); } else { final PsiMethodCallExpression callExpression = (PsiMethodCallExpression)expression.getROperand(); assert callExpression != null; - text = createContainsExpressionText(callExpression, sign, true); + text = createContainsExpressionText(callExpression, true, expression.getOperationTokenType()); } return InspectionGadgetsBundle.message( "indexof.replaceable.by.contains.problem.descriptor", text); @@ -79,20 +78,19 @@ public class ListIndexOfReplaceableByContainsInspection (PsiBinaryExpression)descriptor.getPsiElement(); final PsiExpression lhs = expression.getLOperand(); final PsiExpression rhs = expression.getROperand(); - final PsiJavaToken sign = expression.getOperationSign(); - final String newExpressionText; + final String newExpressionText; if (lhs instanceof PsiMethodCallExpression) { final PsiMethodCallExpression callExpression = (PsiMethodCallExpression)lhs; newExpressionText = - createContainsExpressionText(callExpression, sign, - false); + createContainsExpressionText(callExpression, + false, expression.getOperationTokenType()); } else { final PsiMethodCallExpression callExpression = (PsiMethodCallExpression)rhs; assert callExpression != null; newExpressionText = - createContainsExpressionText(callExpression, sign, true); + createContainsExpressionText(callExpression, true, expression.getOperationTokenType()); } replaceExpression(expression, newExpressionText); } @@ -105,10 +103,8 @@ public class ListIndexOfReplaceableByContainsInspection } static String createContainsExpressionText( - @NotNull PsiMethodCallExpression call, - @NotNull PsiJavaToken sign, - boolean flipped) { - final IElementType tokenType = sign.getTokenType(); + @NotNull PsiMethodCallExpression call, + boolean flipped, IElementType tokenType) { final PsiReferenceExpression methodExpression = call.getMethodExpression(); final PsiExpression qualifierExpression = @@ -154,21 +150,19 @@ public class ListIndexOfReplaceableByContainsInspection } final PsiExpression lhs = expression.getLOperand(); if (lhs instanceof PsiMethodCallExpression) { - final PsiJavaToken sign = expression.getOperationSign(); - if (canBeReplacedByContains(lhs, sign, rhs, false)) { + if (canBeReplacedByContains(lhs, rhs, false, expression.getOperationTokenType())) { registerError(expression, expression); } } else if (rhs instanceof PsiMethodCallExpression) { - final PsiJavaToken sign = expression.getOperationSign(); - if (canBeReplacedByContains(rhs, sign, lhs, true)) { + if (canBeReplacedByContains(rhs, lhs, true, expression.getOperationTokenType())) { registerError(expression, expression); } } } private static boolean canBeReplacedByContains( - PsiExpression lhs, PsiJavaToken sign, - PsiExpression rhs, boolean flipped) { + PsiExpression lhs, + PsiExpression rhs, boolean flipped, IElementType tokenType) { final PsiMethodCallExpression callExpression = (PsiMethodCallExpression)lhs; if (!isIndexOfCall(callExpression)) { @@ -181,8 +175,7 @@ public class ListIndexOfReplaceableByContainsInspection } final Integer integer = (Integer)object; final int constant = integer.intValue(); - final IElementType tokenType = sign.getTokenType(); - if (flipped) { + if (flipped) { if (constant == -1 && (JavaTokenType.NE.equals(tokenType) || JavaTokenType.LT.equals(tokenType) || JavaTokenType.EQEQ.equals(tokenType) || diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryParenthesesInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryParenthesesInspection.java index 76f642b3a54b..9855aba7cfa2 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryParenthesesInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryParenthesesInspection.java @@ -112,8 +112,8 @@ public class UnnecessaryParenthesesInspection extends BaseInspection { final int childPrecedence = ParenthesesUtils.getPrecedence(child); if (parentPrecedence > childPrecedence) { if (ignoreClarifyingParentheses) { - if (parent instanceof PsiBinaryExpression && - child instanceof PsiBinaryExpression) { + if (parent instanceof PsiPolyadicExpression && + child instanceof PsiPolyadicExpression) { return; } else if (child instanceof PsiInstanceOfExpression) { return; @@ -143,4 +143,4 @@ public class UnnecessaryParenthesesInspection extends BaseInspection { super.visitParenthesizedExpression(expression); } } -} \ No newline at end of file +} diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/ui/ExternalizableStringSet.java b/plugins/InspectionGadgets/src/com/siyeh/ig/ui/ExternalizableStringSet.java index ffff4b91767c..3498c60e6fca 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/ui/ExternalizableStringSet.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/ui/ExternalizableStringSet.java @@ -25,6 +25,15 @@ import org.jetbrains.annotations.NonNls; import java.util.List; +/** + * Always assign instances of this class to a final field to prevent an InstantiationException + * from DefaultJDOMExternalizer. + * + * The constructor of this class takes parameters. This means an instance of this class + * cannot be constructed by {@link com.intellij.openapi.util.DefaultJDOMExternalizer}. + * If instances of this class are assigned to a final field, DefaultJDOMExternalizer will + * omit the construction of a new instance and prevent the problem. + */ @SuppressWarnings({"HardCodedStringLiteral"}) public class ExternalizableStringSet extends OrderedSet implements JDOMExternalizable { diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/string_concatenation_in_loops/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/string_concatenation_in_loops/expected.xml index d52bd4acd226..4b3ba72440f5 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/string_concatenation_in_loops/expected.xml +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/string_concatenation_in_loops/expected.xml @@ -8,20 +8,6 @@ String concatenation <code>+</code> in loop #loc - - StringConcatenationInLoop.java - 14 - String concatenation in loop - String concatenation <code>+</code> in loop #loc - - - - StringConcatenationInLoop.java - 15 - String concatenation in loop - String concatenation <code>+</code> in loop #loc - - StringConcatenationInLoop.java 15 @@ -43,4 +29,4 @@ String concatenation <code>+=</code> in loop #loc - \ No newline at end of file + diff --git a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/ConcatenationInjector.java b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/ConcatenationInjector.java index 9367ae2dd04a..67689d6fe807 100644 --- a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/ConcatenationInjector.java +++ b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/ConcatenationInjector.java @@ -407,7 +407,7 @@ public class ConcatenationInjector implements ConcatenationAwareInjector { return true; } } - else if (parent instanceof PsiBinaryExpression) { + else if (parent instanceof PsiBinaryExpression || parent instanceof PsiPolyadicExpression) { return true; } return false; diff --git a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/util/ContextComputationProcessor.java b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/util/ContextComputationProcessor.java index 2bc55e1e6fa7..7fedc7cdb25e 100644 --- a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/util/ContextComputationProcessor.java +++ b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/util/ContextComputationProcessor.java @@ -82,6 +82,13 @@ public class ContextComputationProcessor { collectOperands(binaryExpression.getLOperand(), result, unparsable); collectOperands(binaryExpression.getROperand(), result, unparsable); } + else if (expression instanceof PsiPolyadicExpression && + ((PsiPolyadicExpression)expression).getOperationTokenType() == JavaTokenType.PLUS) { + final PsiPolyadicExpression binaryExpression = (PsiPolyadicExpression)expression; + for (PsiExpression operand : binaryExpression.getOperands()) { + collectOperands(operand, result, unparsable); + } + } else if (expression instanceof PsiAssignmentExpression && ((PsiAssignmentExpression)expression).getOperationTokenType() == JavaTokenType.PLUSEQ) { unparsable.set(Boolean.TRUE); @@ -112,7 +119,7 @@ public class ContextComputationProcessor { PsiElement target = host; PsiElement parent = target.getParent(); for (; parent != null; target = parent, parent = target.getParent()) { - if (parent instanceof PsiBinaryExpression) continue; + if (parent instanceof PsiPolyadicExpression) continue; if (parent instanceof PsiParenthesizedExpression) continue; if (parent instanceof PsiConditionalExpression && ((PsiConditionalExpression)parent).getCondition() != target) continue; if (parent instanceof PsiArrayInitializerMemberValue) continue; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/base/Intention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/base/Intention.java index 124462d50e5d..e6f417a34a14 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/base/Intention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/base/Intention.java @@ -91,9 +91,8 @@ public abstract class Intention extends PsiElementBaseIntentionAction { } else if(ComparisonUtils.isComparison(newExpression)){ final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) newExpression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final String negatedComparison = - ComparisonUtils.getNegatedComparison(sign); + final String negatedComparison = + ComparisonUtils.getNegatedComparison(binaryExpression.getOperationTokenType()); final PsiExpression lhs = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); assert rhs != null; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/BooleanLiteralEqualityPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/BooleanLiteralEqualityPredicate.java index 00445ca5c34a..246c44421f57 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/BooleanLiteralEqualityPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/BooleanLiteralEqualityPredicate.java @@ -28,8 +28,7 @@ class BooleanLiteralEqualityPredicate implements PsiElementPredicate{ return false; } final PsiBinaryExpression expression = (PsiBinaryExpression) element; - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.EQEQ) && !tokenType.equals(JavaTokenType.NE)){ return false; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/ConjunctionPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/ConjunctionPredicate.java index 635936e29d59..fc5bfc3598de 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/ConjunctionPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/ConjunctionPredicate.java @@ -18,7 +18,6 @@ package com.siyeh.ipp.bool; import com.intellij.psi.JavaTokenType; import com.intellij.psi.PsiBinaryExpression; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiJavaToken; import com.intellij.psi.tree.IElementType; import com.siyeh.ipp.base.PsiElementPredicate; import com.siyeh.ipp.psiutils.ErrorUtil; @@ -30,8 +29,7 @@ class ConjunctionPredicate implements PsiElementPredicate{ return false; } final PsiBinaryExpression expression = (PsiBinaryExpression) element; - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.ANDAND) && !tokenType.equals(JavaTokenType.OROR)) { return false; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/DemorgansIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/DemorgansIntention.java index df35c28338ae..0e9479cfbe01 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/DemorgansIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/DemorgansIntention.java @@ -31,8 +31,7 @@ public class DemorgansIntention extends MutablyNamedIntention { protected String getTextForElement(PsiElement element) { final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)element; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if (tokenType.equals(JavaTokenType.ANDAND)) { return IntentionPowerPackBundle.message("demorgans.intention.name1"); } else { @@ -49,8 +48,7 @@ public class DemorgansIntention extends MutablyNamedIntention { throws IncorrectOperationException { PsiBinaryExpression exp = (PsiBinaryExpression)element; - final PsiJavaToken sign = exp.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = exp.getOperationTokenType(); PsiElement parent = exp.getParent(); while (isConjunctionExpression(parent, tokenType)) { exp = (PsiBinaryExpression)parent; @@ -106,9 +104,8 @@ public class DemorgansIntention extends MutablyNamedIntention { } else if (ComparisonUtils.isComparison(condition)) { final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)condition; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final String negatedComparison = - ComparisonUtils.getNegatedComparison(sign); + final String negatedComparison = + ComparisonUtils.getNegatedComparison(binaryExpression.getOperationTokenType()); final PsiExpression lhs = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); assert rhs != null; @@ -127,8 +124,7 @@ public class DemorgansIntention extends MutablyNamedIntention { return false; } final PsiBinaryExpression binExp = (PsiBinaryExpression)exp; - final PsiJavaToken sign = binExp.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binExp.getOperationTokenType(); return tokenType.equals(conjunctionType); } } \ No newline at end of file diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/FlipConjunctionIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/FlipConjunctionIntention.java index 41f0d24f8e93..c9221f48aa96 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/FlipConjunctionIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/FlipConjunctionIntention.java @@ -43,8 +43,7 @@ public class FlipConjunctionIntention extends MutablyNamedIntention { PsiExpression exp = (PsiExpression)element; final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)exp; assert binaryExpression != null; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType conjunctionType = sign.getTokenType(); + final IElementType conjunctionType = binaryExpression.getOperationTokenType(); PsiElement parent = exp.getParent(); while (isConjunctionExpression(parent, conjunctionType)) { exp = (PsiExpression)parent; @@ -83,8 +82,7 @@ public class FlipConjunctionIntention extends MutablyNamedIntention { } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)element; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); return tokenType.equals(conjunctionType); } } \ No newline at end of file diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/NegateComparisonIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/NegateComparisonIntention.java index 3b17945314b1..3c45329aaca2 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/NegateComparisonIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/NegateComparisonIntention.java @@ -36,7 +36,7 @@ public class NegateComparisonIntention extends MutablyNamedIntention { final PsiJavaToken sign = exp.getOperationSign(); operatorText = sign.getText(); negatedOperatorText = - ComparisonUtils.getNegatedComparison(sign); + ComparisonUtils.getNegatedComparison(sign.getTokenType()); } if (operatorText.equals(negatedOperatorText)) { return IntentionPowerPackBundle.message( @@ -59,9 +59,8 @@ public class NegateComparisonIntention extends MutablyNamedIntention { (PsiBinaryExpression)element; final PsiExpression lhs = expression.getLOperand(); final PsiExpression rhs = expression.getROperand(); - final PsiJavaToken sign = expression.getOperationSign(); - final String negatedOperator = - ComparisonUtils.getNegatedComparison(sign); + final String negatedOperator = + ComparisonUtils.getNegatedComparison(expression.getOperationTokenType()); final String lhsText = lhs.getText(); assert rhs != null; final String rhsText = rhs.getText(); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/RemoveBooleanEqualityIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/RemoveBooleanEqualityIntention.java index c9f989738d2b..9203d27dfc64 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/RemoveBooleanEqualityIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/RemoveBooleanEqualityIntention.java @@ -44,8 +44,7 @@ public class RemoveBooleanEqualityIntention extends MutablyNamedIntention { final PsiBinaryExpression exp = (PsiBinaryExpression)element; assert exp != null; - final PsiJavaToken sign = exp.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = exp.getOperationTokenType(); final boolean isEquals = JavaTokenType.EQEQ.equals(tokenType); final PsiExpression lhs = exp.getLOperand(); @NonNls final String lhsText = lhs.getText(); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/chartostring/CharToStringPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/chartostring/CharToStringPredicate.java index ab55eb6c7dcc..9a1689a2b5c6 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/chartostring/CharToStringPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/chartostring/CharToStringPredicate.java @@ -59,8 +59,7 @@ class CharToStringPredicate implements PsiElementPredicate{ } else if(parent instanceof PsiAssignmentExpression){ final PsiAssignmentExpression parentExpression = (PsiAssignmentExpression) parent; - final PsiJavaToken sign = parentExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = parentExpression.getOperationTokenType(); if(!JavaTokenType.PLUSEQ.equals(tokenType)){ return false; } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/chartostring/StringToCharPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/chartostring/StringToCharPredicate.java index 510b6bbce99f..825aa94e7f09 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/chartostring/StringToCharPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/chartostring/StringToCharPredicate.java @@ -77,8 +77,7 @@ class StringToCharPredicate implements PsiElementPredicate{ } else if(parent instanceof PsiAssignmentExpression){ final PsiAssignmentExpression parentExpression = (PsiAssignmentExpression) parent; - final PsiJavaToken sign = parentExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = parentExpression.getOperationTokenType(); if(!JavaTokenType.PLUSEQ.equals(tokenType)){ return false; } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/Jdk5StringConcatenationPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/Jdk5StringConcatenationPredicate.java index e289206334d3..85aaced800d8 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/Jdk5StringConcatenationPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/Jdk5StringConcatenationPredicate.java @@ -15,17 +15,14 @@ */ package com.siyeh.ipp.concatenation; -import com.intellij.psi.PsiArrayInitializerMemberValue; -import com.intellij.psi.PsiBinaryExpression; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiNameValuePair; +import com.intellij.psi.*; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; import com.siyeh.ipp.base.PsiElementPredicate; import com.siyeh.ipp.psiutils.ConcatenationUtils; import com.siyeh.ipp.psiutils.ErrorUtil; class Jdk5StringConcatenationPredicate implements PsiElementPredicate { - public boolean satisfiedBy(PsiElement element) { if (!PsiUtil.isLanguageLevel5OrHigher(element)) { return false; @@ -40,14 +37,6 @@ class Jdk5StringConcatenationPredicate implements PsiElementPredicate { } private static boolean isInsideAnnotation(PsiElement element) { - for (int i = 0; i < 20 && element instanceof PsiBinaryExpression; i++) { - // optimization: don't check deep string concatenations more than 20 levels up. - element = element.getParent(); - if (element instanceof PsiNameValuePair || - element instanceof PsiArrayInitializerMemberValue) { - return true; - } - } - return false; + return PsiTreeUtil.getParentOfType(element, PsiNameValuePair.class, PsiArrayInitializerMemberValue.class) != null; } } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java index 7693623a9974..95f628014c79 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java @@ -15,8 +15,8 @@ */ package com.siyeh.ipp.concatenation; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; +import com.intellij.psi.util.PsiConcatenationUtil; import com.intellij.util.IncorrectOperationException; import com.siyeh.ipp.base.Intention; import com.siyeh.ipp.base.PsiElementPredicate; @@ -38,11 +38,11 @@ public class ReplaceConcatenationWithFormatStringIntention @Override protected void processIntention(@NotNull PsiElement element) throws IncorrectOperationException { - PsiBinaryExpression expression = - (PsiBinaryExpression)element; + PsiPolyadicExpression expression = + (PsiPolyadicExpression)element; PsiElement parent = expression.getParent(); while (ConcatenationUtils.isConcatenation(parent)) { - expression = (PsiBinaryExpression)parent; + expression = (PsiPolyadicExpression)parent; if (expression == null) { return; } @@ -51,7 +51,7 @@ public class ReplaceConcatenationWithFormatStringIntention final StringBuilder formatString = new StringBuilder(); final List formatParameters = new ArrayList(); - buildFormatString(expression, formatString, formatParameters); + PsiConcatenationUtil.buildFormatString(expression, formatString, formatParameters, true); if (replaceWithPrintfExpression(expression, formatString, formatParameters)) { return; @@ -69,7 +69,7 @@ public class ReplaceConcatenationWithFormatStringIntention } private static boolean replaceWithPrintfExpression( - PsiBinaryExpression expression, + PsiExpression expression, CharSequence formatString, List formatParameters) throws IncorrectOperationException { @@ -129,49 +129,4 @@ public class ReplaceConcatenationWithFormatStringIntention return true; } - private static void buildFormatString( - PsiExpression expression, StringBuilder formatString, - List formatParameters) { - if (expression instanceof PsiLiteralExpression) { - final PsiLiteralExpression literalExpression = - (PsiLiteralExpression) expression; - final String text = String.valueOf(literalExpression.getValue()); - final String formatText = - StringUtil.escapeStringCharacters(text) - .replace("%", "%%").replace("\\'", "'"); - formatString.append(formatText); - } else if (expression instanceof PsiBinaryExpression) { - final PsiType type = expression.getType(); - if (type != null && type.equalsToText("java.lang.String")) { - final PsiBinaryExpression binaryExpression = - (PsiBinaryExpression) expression; - final PsiExpression lhs = binaryExpression.getLOperand(); - buildFormatString(lhs, formatString, formatParameters); - final PsiExpression rhs = binaryExpression.getROperand(); - if (rhs != null) { - buildFormatString(rhs, formatString, formatParameters); - } - } else { - addFormatParameter(expression, formatString, formatParameters); - } - } else { - addFormatParameter(expression, formatString, formatParameters); - } - } - - private static void addFormatParameter(PsiExpression expression, - StringBuilder formatString, - List formatParameters) { - final PsiType type = expression.getType(); - if (type != null && - (type.equalsToText("long") || - type.equalsToText("int") || - type.equalsToText("java.lang.Long") || - type.equalsToText("java.lang.Integer"))) { - formatString.append("%d"); - } else { - formatString.append("%s"); - } - formatParameters.add(expression); - } } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/StringConcatPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/StringConcatPredicate.java index ed99620217a3..9b7fb13af37f 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/StringConcatPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/StringConcatPredicate.java @@ -39,8 +39,7 @@ class StringConcatPredicate implements PsiElementPredicate{ } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) parent; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.PLUS)){ return false; } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ObjectEqualityPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ObjectEqualityPredicate.java index 2848bfcfa047..1248421fed28 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ObjectEqualityPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ObjectEqualityPredicate.java @@ -28,8 +28,7 @@ class ObjectEqualityPredicate implements PsiElementPredicate{ return false; } final PsiBinaryExpression expression = (PsiBinaryExpression) element; - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.NE) && !tokenType.equals(JavaTokenType.EQEQ)){ return false; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ReplaceEqualityWithEqualsIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ReplaceEqualityWithEqualsIntention.java index f89b9b9f57c6..256eed19be99 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ReplaceEqualityWithEqualsIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ReplaceEqualityWithEqualsIntention.java @@ -50,8 +50,7 @@ public class ReplaceEqualityWithEqualsIntention extends Intention { if (strippedRhs == null) { return; } - final PsiJavaToken operationSign = exp.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = exp.getOperationTokenType(); @NonNls final String expString; if (tokenType.equals(JavaTokenType.EQEQ)) { if (ParenthesesUtils.getPrecedence(strippedLhs) > diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/CreateAssertIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/CreateAssertIntention.java index 5826ec10e48a..0258d3f9fcc2 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/CreateAssertIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/CreateAssertIntention.java @@ -162,8 +162,7 @@ public class CreateAssertIntention extends Intention { } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); return JavaTokenType.EQEQ.equals(tokenType); } @@ -173,8 +172,7 @@ public class CreateAssertIntention extends Intention { } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if (!JavaTokenType.EQEQ.equals(tokenType)) { return false; } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/AssignmentExpressionReplaceableWithOperatorAssigment.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/AssignmentExpressionReplaceableWithOperatorAssigment.java index 2d9a13704968..7e11cd293801 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/AssignmentExpressionReplaceableWithOperatorAssigment.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/AssignmentExpressionReplaceableWithOperatorAssigment.java @@ -32,8 +32,7 @@ class AssignmentExpressionReplaceableWithOperatorAssigment } final PsiAssignmentExpression assignment = (PsiAssignmentExpression) element; - final PsiJavaToken sign = assignment.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = assignment.getOperationTokenType(); if(!JavaTokenType.EQ.equals(tokenType)){ return false; } @@ -51,8 +50,7 @@ class AssignmentExpressionReplaceableWithOperatorAssigment if(rhsRhs == null){ return false; } - final PsiJavaToken operatorSign = binaryRhs.getOperationSign(); - final IElementType rhsTokenType = operatorSign.getTokenType(); + final IElementType rhsTokenType = binaryRhs.getOperationTokenType(); if(JavaTokenType.OROR.equals(rhsTokenType) || JavaTokenType.ANDAND.equals(rhsTokenType) || JavaTokenType.EQEQ.equals(rhsTokenType) || diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceOperatorAssignmentWithAssignmentIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceOperatorAssignmentWithAssignmentIntention.java index 872ce7470d83..9895379e5ecb 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceOperatorAssignmentWithAssignmentIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceOperatorAssignmentWithAssignmentIntention.java @@ -82,9 +82,8 @@ public class ReplaceOperatorAssignmentWithAssignmentIntention if (rhs instanceof PsiBinaryExpression) { final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)rhs; - final PsiJavaToken javaToken = binaryExpression.getOperationSign(); - final int precedence1 = - ParenthesesUtils.getPrecedenceForBinaryOperator(javaToken); + final int precedence1 = + ParenthesesUtils.getPrecedenceForBinaryOperator(binaryExpression.getOperationTokenType()); final IElementType signTokenType = sign.getTokenType(); final IElementType newOperatorToken = tokenMap.get(signTokenType); final int precedence2 = diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/parenthesis/UnnecessaryParenthesesPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/parenthesis/UnnecessaryParenthesesPredicate.java index 6c67b87c979c..4c6b92d825f5 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/parenthesis/UnnecessaryParenthesesPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/parenthesis/UnnecessaryParenthesesPredicate.java @@ -53,9 +53,7 @@ class UnnecessaryParenthesesPredicate implements PsiElementPredicate{ final PsiJavaToken parentSign = binaryExpression.getOperationSign(); final IElementType parentOperator = parentSign.getTokenType(); - final PsiJavaToken childSign = - ((PsiBinaryExpression) body).getOperationSign(); - final IElementType childOperator = childSign.getTokenType(); + final IElementType childOperator = ((PsiBinaryExpression)body).getOperationTokenType(); if(!parentOperator.equals(childOperator)){ return false; } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/BoolUtils.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/BoolUtils.java index 80b7e93b1dc6..2c176c54c69b 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/BoolUtils.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/BoolUtils.java @@ -32,8 +32,7 @@ public class BoolUtils{ if(ancestor.getParent() instanceof PsiPrefixExpression){ final PsiPrefixExpression prefixAncestor = (PsiPrefixExpression) ancestor.getParent(); - final PsiJavaToken sign = prefixAncestor.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = prefixAncestor.getOperationTokenType(); if(tokenType.equals(JavaTokenType.EXCL)){ return true; } @@ -50,8 +49,7 @@ public class BoolUtils{ if(ancestor.getParent() instanceof PsiPrefixExpression){ final PsiPrefixExpression prefixAncestor = (PsiPrefixExpression) ancestor.getParent(); - final PsiJavaToken sign = prefixAncestor.getOperationSign(); - if(JavaTokenType.EXCL.equals(sign.getTokenType())){ + if(JavaTokenType.EXCL.equals(prefixAncestor.getOperationTokenType())){ return prefixAncestor; } } @@ -63,8 +61,7 @@ public class BoolUtils{ return false; } final PsiPrefixExpression prefixExp = (PsiPrefixExpression) exp; - final PsiJavaToken sign = prefixExp.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = prefixExp.getOperationTokenType(); return tokenType.equals(JavaTokenType.EXCL); } @@ -109,9 +106,8 @@ public class BoolUtils{ } else if(ComparisonUtils.isComparison(condition)){ final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) condition; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final String negatedComparison = - ComparisonUtils.getNegatedComparison(sign); + final String negatedComparison = + ComparisonUtils.getNegatedComparison(binaryExpression.getOperationTokenType()); final PsiExpression lhs = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); if(rhs == null){ diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ComparisonUtils.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ComparisonUtils.java index e3261ddfd04d..0acf41fa73ed 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ComparisonUtils.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ComparisonUtils.java @@ -86,11 +86,6 @@ public class ComparisonUtils{ return flippedComparisons.get(text); } - public static String getNegatedComparison(@NotNull PsiJavaToken sign){ - final IElementType tokenType = sign.getTokenType(); - return getNegatedComparison(tokenType); - } - public static String getNegatedComparison(IElementType tokenType){ return negatedComparisons.get(tokenType); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ConcatenationUtils.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ConcatenationUtils.java index 3c579e6d370c..3d4d72511f91 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ConcatenationUtils.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ConcatenationUtils.java @@ -25,31 +25,27 @@ public class ConcatenationUtils{ } public static boolean isConcatenation(PsiElement element){ - if(!(element instanceof PsiBinaryExpression)){ + if(!(element instanceof PsiPolyadicExpression)){ return false; } - final PsiBinaryExpression expression = (PsiBinaryExpression) element; - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final PsiPolyadicExpression expression = (PsiPolyadicExpression) element; + final IElementType tokenType = expression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.PLUS)){ return false; } - final PsiExpression rhs = expression.getROperand(); - if(rhs == null){ - return false; - } + PsiExpression[] operands = expression.getOperands(); + if (operands.length <= 1) return false; final PsiType type = expression.getType(); if(type == null){ - final PsiExpression lhs = expression.getLOperand(); - return hasStringType(lhs) || hasStringType(rhs); + for (PsiExpression operand : operands) { + if (hasStringType(operand)) return true; + } + return false; } return type.equalsToText("java.lang.String"); } private static boolean hasStringType(PsiExpression expression) { - if (expression == null) { - return false; - } final PsiType type = expression.getType(); return type != null && type.equalsToText("java.lang.String"); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/EquivalenceChecker.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/EquivalenceChecker.java index 77ff76899cec..9e8582ab05d4 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/EquivalenceChecker.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/EquivalenceChecker.java @@ -794,10 +794,8 @@ public class EquivalenceChecker{ private static boolean prefixExpressionsAreEquivalent( @NotNull PsiPrefixExpression prefixExpression1, @NotNull PsiPrefixExpression prefixExpression2){ - final PsiJavaToken sign1 = prefixExpression1.getOperationSign(); - final PsiJavaToken sign2 = prefixExpression2.getOperationSign(); - final IElementType tokenType1 = sign1.getTokenType(); - if(!tokenType1.equals(sign2.getTokenType())){ + final IElementType tokenType1 = prefixExpression1.getOperationTokenType(); + if(!tokenType1.equals(prefixExpression2.getOperationTokenType())){ return false; } final PsiExpression operand1 = prefixExpression1.getOperand(); @@ -808,10 +806,8 @@ public class EquivalenceChecker{ private static boolean postfixExpressionsAreEquivalent( @NotNull PsiPostfixExpression postfixExpression1, @NotNull PsiPostfixExpression postfixExpression2){ - final PsiJavaToken sign1 = postfixExpression1.getOperationSign(); - final PsiJavaToken sign2 = postfixExpression2.getOperationSign(); - final IElementType tokenType1 = sign1.getTokenType(); - if(!tokenType1.equals(sign2.getTokenType())){ + final IElementType tokenType1 = postfixExpression1.getOperationTokenType(); + if(!tokenType1.equals(postfixExpression2.getOperationTokenType())){ return false; } final PsiExpression operand1 = postfixExpression1.getOperand(); @@ -822,10 +818,8 @@ public class EquivalenceChecker{ private static boolean binaryExpressionsAreEquivalent( @NotNull PsiBinaryExpression binaryExpression1, @NotNull PsiBinaryExpression binaryExpression2){ - final PsiJavaToken sign1 = binaryExpression1.getOperationSign(); - final PsiJavaToken sign2 = binaryExpression2.getOperationSign(); - final IElementType tokenType1 = sign1.getTokenType(); - if(!tokenType1.equals(sign2.getTokenType())){ + final IElementType tokenType1 = binaryExpression1.getOperationTokenType(); + if(!tokenType1.equals(binaryExpression2.getOperationTokenType())){ return false; } final PsiExpression lhs1 = binaryExpression1.getLOperand(); @@ -839,10 +833,8 @@ public class EquivalenceChecker{ private static boolean assignmentExpressionsAreEquivalent( @NotNull PsiAssignmentExpression assignmentExpression1, @NotNull PsiAssignmentExpression assignmentExpression2){ - final PsiJavaToken sign1 = assignmentExpression1.getOperationSign(); - final PsiJavaToken sign2 = assignmentExpression2.getOperationSign(); - final IElementType tokenType1 = sign1.getTokenType(); - if(!tokenType1.equals(sign2.getTokenType())){ + final IElementType tokenType1 = assignmentExpression1.getOperationTokenType(); + if(!tokenType1.equals(assignmentExpression2.getOperationTokenType())){ return false; } final PsiExpression lhs1 = assignmentExpression1.getLExpression(); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ParenthesesUtils.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ParenthesesUtils.java index 5a19a4fa4c07..3535a0f2d033 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ParenthesesUtils.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/ParenthesesUtils.java @@ -129,9 +129,7 @@ public class ParenthesesUtils{ if(expression instanceof PsiBinaryExpression){ final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression; - final PsiJavaToken sign = - binaryExpression.getOperationSign(); - return getPrecedenceForBinaryOperator(sign); + return getPrecedenceForBinaryOperator(binaryExpression.getOperationTokenType()); } if(expression instanceof PsiInstanceOfExpression){ return RELATIONAL_PRECEDENCE; @@ -148,11 +146,6 @@ public class ParenthesesUtils{ return -1; } - public static int getPrecedenceForBinaryOperator(@NotNull PsiJavaToken sign){ - final IElementType tokenType = sign.getTokenType(); - return getPrecedenceForBinaryOperator(tokenType); - } - public static int getPrecedenceForBinaryOperator(IElementType operator) { final Integer precedence = s_binaryOperatorPrecedence.get(operator); return precedence.intValue(); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/SideEffectChecker.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/SideEffectChecker.java index a679639ca8a5..c82a7b35f83e 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/SideEffectChecker.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/SideEffectChecker.java @@ -56,8 +56,7 @@ public class SideEffectChecker{ @Override public void visitPrefixExpression(PsiPrefixExpression expression){ super.visitPrefixExpression(expression); - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(tokenType.equals(JavaTokenType.PLUSPLUS) || tokenType.equals(JavaTokenType.MINUSMINUS)){ @@ -67,8 +66,7 @@ public class SideEffectChecker{ @Override public void visitPostfixExpression(PsiPostfixExpression expression){ super.visitPostfixExpression(expression); - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(tokenType.equals(JavaTokenType.PLUSPLUS) || tokenType.equals(JavaTokenType.MINUSMINUS)){ diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java index a169b5b30ccb..b6d772cf737a 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAccessUtils.java @@ -66,8 +66,7 @@ public class VariableAccessUtils { if (expression instanceof PsiPrefixExpression) { final PsiPrefixExpression prefixExpression = (PsiPrefixExpression)expression; - final PsiJavaToken sign = prefixExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)) { return false; @@ -77,8 +76,7 @@ public class VariableAccessUtils { } else if (expression instanceof PsiPostfixExpression) { final PsiPostfixExpression postfixExpression = (PsiPostfixExpression)expression; - final PsiJavaToken sign = postfixExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = postfixExpression.getOperationTokenType(); if (!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)) { return false; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAssignedVisitor.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAssignedVisitor.java index 5956e36e2bdf..b8dd0b6f3129 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAssignedVisitor.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/psiutils/VariableAssignedVisitor.java @@ -72,8 +72,7 @@ class VariableAssignedVisitor extends JavaRecursiveElementVisitor{ return; } super.visitPrefixExpression(prefixExpression); - final PsiJavaToken operationSign = prefixExpression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = prefixExpression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)){ return; @@ -92,8 +91,7 @@ class VariableAssignedVisitor extends JavaRecursiveElementVisitor{ return; } super.visitPostfixExpression(postfixExpression); - final PsiJavaToken operationSign = postfixExpression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); + final IElementType tokenType = postfixExpression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.PLUSPLUS) && !tokenType.equals(JavaTokenType.MINUSMINUS)){ return; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/MultiplyByPowerOfTwoPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/MultiplyByPowerOfTwoPredicate.java index eb45c3a846e0..8c67428187c4 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/MultiplyByPowerOfTwoPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/MultiplyByPowerOfTwoPredicate.java @@ -36,8 +36,7 @@ class MultiplyByPowerOfTwoPredicate implements PsiElementPredicate{ private static boolean assignmentExpressionIsMultiplyByPowerOfTwo( PsiAssignmentExpression expression){ - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.ASTERISKEQ) && !tokenType.equals(JavaTokenType.DIVEQ)){ return false; @@ -59,8 +58,7 @@ class MultiplyByPowerOfTwoPredicate implements PsiElementPredicate{ private static boolean binaryExpressionIsMultiplyByPowerOfTwo( PsiBinaryExpression expression){ - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.ASTERISK) && !tokenType.equals(JavaTokenType.DIV)){ return false; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceMultiplyWithShiftIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceMultiplyWithShiftIntention.java index c76ad852dc7d..05e16f55d084 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceMultiplyWithShiftIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceMultiplyWithShiftIntention.java @@ -77,8 +77,7 @@ public class ReplaceMultiplyWithShiftIntention extends MutablyNamedIntention { throws IncorrectOperationException { final PsiExpression lhs = expression.getLExpression(); final PsiExpression rhs = expression.getRExpression(); - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); final String assignString; if (tokenType.equals(JavaTokenType.ASTERISKEQ)) { assignString = "<<="; @@ -95,8 +94,7 @@ public class ReplaceMultiplyWithShiftIntention extends MutablyNamedIntention { throws IncorrectOperationException { final PsiExpression lhs = expression.getLOperand(); final PsiExpression rhs = expression.getROperand(); - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); final String operatorString; if (tokenType.equals(JavaTokenType.ASTERISK)) { operatorString = "<<"; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceShiftWithMultiplyIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceShiftWithMultiplyIntention.java index ccd63a85c0b1..f62f3cd81cb6 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceShiftWithMultiplyIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceShiftWithMultiplyIntention.java @@ -81,8 +81,7 @@ public class ReplaceShiftWithMultiplyIntention extends MutablyNamedIntention { (PsiAssignmentExpression)element; final PsiExpression lhs = exp.getLExpression(); final PsiExpression rhs = exp.getRExpression(); - final PsiJavaToken sign = exp.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = exp.getOperationTokenType(); final String assignString; if (tokenType.equals(JavaTokenType.LTLTEQ)) { assignString = "*="; @@ -100,8 +99,7 @@ public class ReplaceShiftWithMultiplyIntention extends MutablyNamedIntention { (PsiBinaryExpression)element; final PsiExpression lhs = exp.getLOperand(); final PsiExpression rhs = exp.getROperand(); - final PsiJavaToken sign = exp.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = exp.getOperationTokenType(); final String operatorString; if (tokenType.equals(JavaTokenType.LTLT)) { operatorString = "*"; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ShiftByLiteralPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ShiftByLiteralPredicate.java index 301aeccd4d1e..5ba78c84dd65 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ShiftByLiteralPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ShiftByLiteralPredicate.java @@ -35,8 +35,7 @@ class ShiftByLiteralPredicate implements PsiElementPredicate{ private static boolean isAssignmentShiftByLiteral( PsiAssignmentExpression expression){ - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.LTLTEQ) && !tokenType.equals(JavaTokenType.GTGTEQ)){ return false; @@ -58,8 +57,7 @@ class ShiftByLiteralPredicate implements PsiElementPredicate{ private static boolean isBinaryShiftByLiteral( PsiBinaryExpression expression){ - final PsiJavaToken sign = expression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = expression.getOperationTokenType(); if(!tokenType.equals(JavaTokenType.LTLT) && !tokenType.equals(JavaTokenType.GTGT)){ return false; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/ReplaceIfWithSwitchIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/ReplaceIfWithSwitchIntention.java index c35f86c1ce6a..8a2bdc259aa3 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/ReplaceIfWithSwitchIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/ReplaceIfWithSwitchIntention.java @@ -274,8 +274,7 @@ public class ReplaceIfWithSwitchIntention extends Intention { (PsiBinaryExpression)expression; final PsiExpression lhs = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType tokenType = sign.getTokenType(); + final IElementType tokenType = binaryExpression.getOperationTokenType(); if (JavaTokenType.OROR.equals(tokenType)) { getValuesFromExpression(lhs, caseExpression, values); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/SwitchUtils.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/SwitchUtils.java index a9fb0aaff79d..93cc35901133 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/SwitchUtils.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/switchtoif/SwitchUtils.java @@ -143,8 +143,7 @@ class SwitchUtils { } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) expression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType operation = sign.getTokenType(); + final IElementType operation = binaryExpression.getOperationTokenType(); final PsiExpression lhs = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); if(operation.equals(JavaTokenType.OROR)){ @@ -223,8 +222,7 @@ class SwitchUtils { } final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) expression; - final PsiJavaToken sign = binaryExpression.getOperationSign(); - final IElementType operation = sign.getTokenType(); + final IElementType operation = binaryExpression.getOperationTokenType(); final PsiExpression lOperand = binaryExpression.getLOperand(); final PsiExpression rhs = binaryExpression.getROperand(); if(operation.equals(JavaTokenType.OROR)){ diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/ReplaceIfWithConditionalPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/ReplaceIfWithConditionalPredicate.java index ee1d8613c1d1..6a17e07faae3 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/ReplaceIfWithConditionalPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/ReplaceIfWithConditionalPredicate.java @@ -144,10 +144,8 @@ class ReplaceIfWithConditionalPredicate implements PsiElementPredicate{ final PsiAssignmentExpression elseExpression = (PsiAssignmentExpression) ((PsiExpressionStatement) elseBranch).getExpression(); - final PsiJavaToken thenSign = thenExpression.getOperationSign(); - final PsiJavaToken elseSign = elseExpression.getOperationSign(); - final IElementType tokenType = thenSign.getTokenType(); - if(!tokenType.equals(elseSign.getTokenType())){ + final IElementType tokenType = thenExpression.getOperationTokenType(); + if(!tokenType.equals(elseExpression.getOperationTokenType())){ return false; } final PsiExpression thenLhs = thenExpression.getLExpression(); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/SimplifyIfElsePredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/SimplifyIfElsePredicate.java index 670d835b2493..8dd6bf563032 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/SimplifyIfElsePredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/SimplifyIfElsePredicate.java @@ -140,10 +140,8 @@ class SimplifyIfElsePredicate implements PsiElementPredicate{ final PsiAssignmentExpression elseExpression = (PsiAssignmentExpression) elseExpressionStatement.getExpression(); - final PsiJavaToken thenSign = thenExpression.getOperationSign(); - final PsiJavaToken elseSign = elseExpression.getOperationSign(); - final IElementType thenTokenType = thenSign.getTokenType(); - if(!thenTokenType.equals(elseSign.getTokenType())){ + final IElementType thenTokenType = thenExpression.getOperationTokenType(); + if(!thenTokenType.equals(elseExpression.getOperationTokenType())){ return false; } final PsiExpression thenLhs = thenExpression.getLExpression(); @@ -171,10 +169,8 @@ class SimplifyIfElsePredicate implements PsiElementPredicate{ final PsiAssignmentExpression elseExpression = (PsiAssignmentExpression) elseExpressionStatement.getExpression(); - final PsiJavaToken thenSign = thenExpression.getOperationSign(); - final PsiJavaToken elseSign = elseExpression.getOperationSign(); - final IElementType thenTokenType = thenSign.getTokenType(); - if(!thenTokenType.equals(elseSign.getTokenType())){ + final IElementType thenTokenType = thenExpression.getOperationTokenType(); + if(!thenTokenType.equals(elseExpression.getOperationTokenType())){ return false; } final PsiExpression thenLhs = thenExpression.getLExpression(); @@ -207,10 +203,8 @@ class SimplifyIfElsePredicate implements PsiElementPredicate{ final PsiAssignmentExpression elseExpression = (PsiAssignmentExpression) ((PsiExpressionStatement) elseBranch).getExpression(); - final PsiJavaToken thenSign = thenExpression.getOperationSign(); - final PsiJavaToken elseSign = elseExpression.getOperationSign(); - final IElementType thenTokenType = thenSign.getTokenType(); - if(!thenTokenType.equals(elseSign.getTokenType())){ + final IElementType thenTokenType = thenExpression.getOperationTokenType(); + if(!thenTokenType.equals(elseExpression.getOperationTokenType())){ return false; } final PsiExpression thenLhs = thenExpression.getLExpression(); @@ -247,10 +241,8 @@ class SimplifyIfElsePredicate implements PsiElementPredicate{ final PsiAssignmentExpression elseExpression = (PsiAssignmentExpression) elseExpressionStatement.getExpression(); - final PsiJavaToken thenSign = thenExpression.getOperationSign(); - final PsiJavaToken elseSign = elseExpression.getOperationSign(); - final IElementType thenTokenType = thenSign.getTokenType(); - if(!thenTokenType.equals(elseSign.getTokenType())){ + final IElementType thenTokenType = thenExpression.getOperationTokenType(); + if(!thenTokenType.equals(elseExpression.getOperationTokenType())){ return false; } final PsiExpression thenLhs = thenExpression.getLExpression(); diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/concatenation/string_format/HexadecimalLiteral_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/concatenation/string_format/HexadecimalLiteral_after.java index 897397e05dfc..a5cadb01651b 100644 --- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/concatenation/string_format/HexadecimalLiteral_after.java +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/concatenation/string_format/HexadecimalLiteral_after.java @@ -1,3 +1,3 @@ class C { - String s = String.format("or not16"); + String s = String.format("or not%d", 0x10); } \ No newline at end of file diff --git a/plugins/android/src/org/jetbrains/android/compiler/AndroidPackagingCompiler.java b/plugins/android/src/org/jetbrains/android/compiler/AndroidPackagingCompiler.java index 96f432445695..affe2432a007 100644 --- a/plugins/android/src/org/jetbrains/android/compiler/AndroidPackagingCompiler.java +++ b/plugins/android/src/org/jetbrains/android/compiler/AndroidPackagingCompiler.java @@ -411,7 +411,7 @@ public class AndroidPackagingCompiler implements PackagingCompiler { ArrayList nativeLibs = new ArrayList(); for (VirtualFile nativeLibFolder : nativeLibFolders) { for (VirtualFile child : nativeLibFolder.getChildren()) { - AndroidApkBuilder.collectNativeLibraries(child, nativeLibs); + AndroidApkBuilder.collectNativeLibraries(child, nativeLibs, !releaseBuild); } } for (VirtualFile nativeLib : nativeLibs) { diff --git a/plugins/android/src/org/jetbrains/android/compiler/tools/AndroidApkBuilder.java b/plugins/android/src/org/jetbrains/android/compiler/tools/AndroidApkBuilder.java index 1c011cff99ff..815da70522a7 100644 --- a/plugins/android/src/org/jetbrains/android/compiler/tools/AndroidApkBuilder.java +++ b/plugins/android/src/org/jetbrains/android/compiler/tools/AndroidApkBuilder.java @@ -236,7 +236,7 @@ public class AndroidApkBuilder { } for (VirtualFile nativeLibsFolder : nativeLibsFolders) { for (VirtualFile child : nativeLibsFolder.getChildren()) { - writeNativeLibraries(builder, nativeLibsFolder, child); + writeNativeLibraries(builder, nativeLibsFolder, child, signed); } } builder.close(); @@ -297,9 +297,10 @@ public class AndroidApkBuilder { }); } - private static void writeNativeLibraries(SignedJarBuilder builder, VirtualFile nativeLibsFolder, VirtualFile child) throws IOException { + private static void writeNativeLibraries(SignedJarBuilder builder, VirtualFile nativeLibsFolder, VirtualFile child, boolean debugBuild) + throws IOException { ArrayList list = new ArrayList(); - collectNativeLibraries(child, list); + collectNativeLibraries(child, list, debugBuild); for (VirtualFile file : list) { String relativePath = VfsUtil.getRelativePath(file, nativeLibsFolder, File.separatorChar); String path = FileUtil.toSystemIndependentName(SdkConstants.FD_APK_NATIVE_LIBS + File.separator + relativePath); @@ -314,16 +315,17 @@ public class AndroidApkBuilder { return result; } - public static void collectNativeLibraries(@NotNull VirtualFile file, @NotNull List result) { + public static void collectNativeLibraries(@NotNull VirtualFile file, @NotNull List result, boolean debugBuild) { if (!file.isDirectory()) { String ext = file.getExtension(); - if (AndroidUtils.EXT_NATIVE_LIB.equalsIgnoreCase(ext)) { + if (AndroidUtils.EXT_NATIVE_LIB.equalsIgnoreCase(ext) || + (debugBuild && SdkConstants.FN_GDBSERVER.equals(file.getName()))) { result.add(file); } } else if (JavaResourceFilter.checkFolderForPackaging(file.getName())) { for (VirtualFile child : file.getChildren()) { - collectNativeLibraries(child, result); + collectNativeLibraries(child, result, debugBuild); } } } diff --git a/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java b/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java index c043a3f20e74..b5a328d0de78 100644 --- a/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java +++ b/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java @@ -149,7 +149,7 @@ public class GitAnnotationProvider implements AnnotationProvider, VcsCacheableAn h.setNoSSH(true); h.setStdoutSuppressed(true); h.setCharset(file.getCharset()); - h.addParameters("-p", "-l", "-t", "-M"); + h.addParameters("-p", "-l", "-t"); if (revision == null) { h.addParameters("HEAD"); } diff --git a/plugins/git4idea/src/git4idea/history/wholeTree/GitLogUI.java b/plugins/git4idea/src/git4idea/history/wholeTree/GitLogUI.java index 689f24368453..0dad36c269ae 100644 --- a/plugins/git4idea/src/git4idea/history/wholeTree/GitLogUI.java +++ b/plugins/git4idea/src/git4idea/history/wholeTree/GitLogUI.java @@ -89,6 +89,7 @@ public class GitLogUI implements Disposable { private UIRefresh myUIRefresh; private JBTable myJBTable; private RepositoryChangesBrowser myRepositoryChangesBrowser; + final List myCommitsInRepositoryChangesBrowser; private boolean myDataBeingAdded; private CardLayout myRepoLayout; private JPanel myRepoPanel; @@ -130,6 +131,7 @@ public class GitLogUI implements Disposable { myPreviousFilter = ""; myDescriptionRenderer = new DescriptionRenderer(); myCommentSearchContext.addHighlighter(myDescriptionRenderer.myInner.myWorker); + myCommitsInRepositoryChangesBrowser = new ArrayList(); mySelectionRequestsMerger = new RequestsMerger(new Runnable() { @Override @@ -405,10 +407,10 @@ public class GitLogUI implements Disposable { myRepoPanel.repaint(); return; } - myRepoLayout.show(myRepoPanel, "loading"); - myRepoPanel.repaint(); - - gatherNotLoadedData(); + if (! myDataBeingAdded && ! gatherNotLoadedData()) { + myRepoLayout.show(myRepoPanel, "loading"); + myRepoPanel.repaint(); + } } private static class MeaningfulSelection { @@ -486,10 +488,12 @@ public class GitLogUI implements Disposable { gatherNotLoadedData(); } - private void gatherNotLoadedData() { - if (myDataBeingAdded) return; + private boolean gatherNotLoadedData() { + if (myDataBeingAdded) return false; final int[] rows = myJBTable.getSelectedRows(); final List commits = new ArrayList(); + final List forComparison = new ArrayList(); + final MultiMap missingHashes = new MultiMap(); for (int i = rows.length - 1; i >= 0; --i) { final int row = rows[i]; @@ -499,13 +503,18 @@ public class GitLogUI implements Disposable { if (details == null) { missingHashes.putValue(commitI.selectRepository(myRootsUnderVcs), commitI.getHash()); } else if (missingHashes.isEmpty()) { // no sense in collecting commits when s + forComparison.add(commitI); commits.add(details); } } if (! missingHashes.isEmpty()) { myDetailsCache.acceptQuestion(missingHashes); - return; + return false; } + if (Comparing.equal(myCommitsInRepositoryChangesBrowser, forComparison)) return true; + myCommitsInRepositoryChangesBrowser.clear(); + myCommitsInRepositoryChangesBrowser.addAll(forComparison); + final List changes = new ArrayList(); for (GitCommit commit : commits) { changes.addAll(commit.getChanges()); @@ -514,6 +523,7 @@ public class GitLogUI implements Disposable { myRepositoryChangesBrowser.setChangesToDisplay(zipped); myRepoLayout.show(myRepoPanel, "main"); myRepoPanel.repaint(); + return true; } private JPanel createMainTable() { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrStubFileElementType.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrStubFileElementType.java index 893daddfc483..ea0e80abeea8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrStubFileElementType.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrStubFileElementType.java @@ -21,6 +21,7 @@ import com.intellij.psi.StubBuilder; import com.intellij.psi.stubs.*; import com.intellij.psi.tree.IStubFileElementType; import com.intellij.util.io.StringRef; +import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; import org.jetbrains.plugins.groovy.lang.psi.stubs.GrFileStub; import org.jetbrains.plugins.groovy.lang.psi.stubs.GrStubUtils; @@ -41,7 +42,7 @@ public class GrStubFileElementType extends IStubFileElementType { public StubBuilder getBuilder() { return new DefaultStubBuilder() { - protected StubElement createStubForFile(final PsiFile file) { + protected StubElement createStubForFile(@NotNull final PsiFile file) { if (file instanceof GroovyFile) { return new GrFileStub((GroovyFile)file); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureDialog.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureDialog.java index 4f0fa8eab622..418650eb49c6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureDialog.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrChangeSignatureDialog.java @@ -30,8 +30,8 @@ import com.intellij.refactoring.util.CanonicalTypes; import com.intellij.refactoring.util.CommonRefactoringUtil; import com.intellij.ui.EditableRowTable; import com.intellij.ui.EditorTextField; -import com.intellij.ui.TableToolbarDecorator; import com.intellij.ui.TableUtil; +import com.intellij.ui.ToolbarDecorator; import com.intellij.ui.table.JBTable; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; @@ -196,7 +196,7 @@ public class GrChangeSignatureDialog extends RefactoringDialog { myExceptionsTable = new JBTable(myExceptionTableModel); myExceptionsTable.setPreferredScrollableViewportSize(new Dimension(200, myExceptionsTable.getRowHeight() * 8)); - myExceptionsButtonPanel = TableToolbarDecorator.createDecorator(myExceptionsTable).createPanel(); + myExceptionsButtonPanel = ToolbarDecorator.createDecorator(myExceptionsTable).createPanel(); myExceptionsTable.getColumnModel().getColumn(0).setCellRenderer(new CodeFragmentTableCellRenderer(myProject)); myExceptionsTable.getColumnModel().getColumn(0).setCellEditor(new JavaCodeFragmentTableCellEditor(myProject)); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/IntroduceParameterTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/IntroduceParameterTest.java index 2a5f58f23970..870ca0eaa75b 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/IntroduceParameterTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduceParameter/IntroduceParameterTest.java @@ -16,15 +16,16 @@ package org.jetbrains.plugins.groovy.refactoring.introduceParameter; -import com.intellij.codeInsight.CodeInsightUtil; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Pass; import com.intellij.psi.*; import com.intellij.psi.impl.source.PostprocessReformattingAspect; -import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.refactoring.HelpID; import com.intellij.refactoring.IntroduceParameterRefactoring; +import com.intellij.refactoring.introduceField.ElementToWorkOn; import com.intellij.refactoring.introduceParameter.IntroduceParameterProcessor; import com.intellij.refactoring.introduceParameter.Util; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; @@ -71,19 +72,22 @@ public class IntroduceParameterTest extends LightCodeInsightFixtureTestCase { int startOffset = editor.getSelectionModel().getSelectionStart(); int endOffset = editor.getSelectionModel().getSelectionEnd(); - final PsiFile file = myFixture.getFile(); - PsiExpression expr = CodeInsightUtil.findExpressionInRange(file, startOffset, endOffset); + final PsiFile myFile = myFixture.getFile(); + final ElementToWorkOn[] elementToWorkOn = new ElementToWorkOn[1]; + ElementToWorkOn + .processElementToWorkOn(editor, myFile, "INtr param", HelpID.INTRODUCE_PARAMETER, getProject(), new Pass() { + @Override + public void pass(final ElementToWorkOn e) { + if (e == null) return; - PsiLocalVariable localVariable = null; - if (expr == null) { - PsiElement element = CodeInsightUtil.findElementInRange(file, startOffset, endOffset, PsiElement.class); - localVariable = PsiTreeUtil.getParentOfType(element, PsiLocalVariable.class); - if (localVariable == null) { - return false; - } - } + elementToWorkOn[0] = e; + } + }); - PsiElement context = expr == null ? localVariable : expr; + final PsiExpression expr = elementToWorkOn[0].getExpression(); + final PsiLocalVariable localVar = elementToWorkOn[0].getLocalVariable(); + + PsiElement context = expr == null ? localVar : expr; PsiMethod method = Util.getContainingMethod(context); if (method == null) return false; @@ -96,11 +100,11 @@ public class IntroduceParameterTest extends LightCodeInsightFixtureTestCase { methodToSearchFor = method; } - PsiExpression initializer = (expr == null) ? localVariable.getInitializer() : expr; + PsiExpression initializer = expr == null ? localVar.getInitializer() : expr; TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, initializer, null) : new TIntArrayList(); final Project project = myFixture.getProject(); final IntroduceParameterProcessor processor = - new IntroduceParameterProcessor(project, method, methodToSearchFor, initializer, expr, localVariable, true, parameterName, + new IntroduceParameterProcessor(project, method, methodToSearchFor, initializer, expr, localVar, true, parameterName, replaceAllOccurences, replaceFieldsWithGetters, declareFinal, generateDelegate, null, parametersToRemove); diff --git a/plugins/java-i18n/src/com/intellij/codeInspection/i18n/I18nizeConcatenationQuickFix.java b/plugins/java-i18n/src/com/intellij/codeInspection/i18n/I18nizeConcatenationQuickFix.java index 7528eca7cba4..0bd365da2f3f 100644 --- a/plugins/java-i18n/src/com/intellij/codeInspection/i18n/I18nizeConcatenationQuickFix.java +++ b/plugins/java-i18n/src/com/intellij/codeInspection/i18n/I18nizeConcatenationQuickFix.java @@ -39,14 +39,14 @@ public class I18nizeConcatenationQuickFix extends I18nizeQuickFix{ @NonNls private static final String PARAMETERS_OPTION_KEY = "PARAMETERS"; public void checkApplicability(final PsiFile psiFile, final Editor editor) throws IncorrectOperationException { - PsiBinaryExpression concatenation = getEnclosingLiteralConcatenation(psiFile, editor); + PsiPolyadicExpression concatenation = getEnclosingLiteralConcatenation(psiFile, editor); if (concatenation != null) return; String message = CodeInsightBundle.message("quickfix.i18n.concatentation.error"); throw new IncorrectOperationException(message); } public JavaI18nizeQuickFixDialog createDialog(Project project, Editor editor, PsiFile psiFile) { - PsiBinaryExpression concatenation = getEnclosingLiteralConcatenation(psiFile, editor); + PsiPolyadicExpression concatenation = getEnclosingLiteralConcatenation(psiFile, editor); PsiLiteralExpression literalExpression = getContainingLiteral(concatenation); if (literalExpression == null) return null; return createDialog(project, psiFile, literalExpression); @@ -61,7 +61,7 @@ public class I18nizeConcatenationQuickFix extends I18nizeQuickFix{ @NotNull final Editor editor, @Nullable PsiLiteralExpression literalExpression, String i18nizedText) throws IncorrectOperationException { - PsiBinaryExpression concatenation = getEnclosingLiteralConcatenation(psiFile, editor); + PsiPolyadicExpression concatenation = getEnclosingLiteralConcatenation(psiFile, editor); PsiExpression expression = JavaPsiFacade.getInstance(psiFile.getProject()).getElementFactory().createExpressionFromText(i18nizedText, concatenation); return concatenation.replace(expression); } @@ -79,7 +79,7 @@ public class I18nizeConcatenationQuickFix extends I18nizeQuickFix{ } protected JavaI18nizeQuickFixDialog createDialog(final Project project, final PsiFile context, final PsiLiteralExpression literalExpression) { - PsiBinaryExpression concatenation = getEnclosingLiteralConcatenation(literalExpression); + PsiPolyadicExpression concatenation = getEnclosingLiteralConcatenation(literalExpression); StringBuilder formatString = new StringBuilder(); final List args = new ArrayList(); try { @@ -111,45 +111,39 @@ public class I18nizeConcatenationQuickFix extends I18nizeQuickFix{ } @Nullable - private static PsiBinaryExpression getEnclosingLiteralConcatenation(@NotNull PsiFile file, @NotNull Editor editor) { + private static PsiPolyadicExpression getEnclosingLiteralConcatenation(@NotNull PsiFile file, @NotNull Editor editor) { final PsiElement elementAt = file.findElementAt(editor.getCaretModel().getOffset()); return getEnclosingLiteralConcatenation(elementAt); } @Nullable - public static PsiBinaryExpression getEnclosingLiteralConcatenation(final PsiElement psiElement) { - PsiBinaryExpression element = PsiTreeUtil.getParentOfType(psiElement, PsiBinaryExpression.class, false, PsiMember.class); + public static PsiPolyadicExpression getEnclosingLiteralConcatenation(final PsiElement psiElement) { + PsiPolyadicExpression element = PsiTreeUtil.getParentOfType(psiElement, PsiPolyadicExpression.class, false, PsiMember.class); if (element == null) return null; - PsiBinaryExpression concatenation = null; + + PsiPolyadicExpression concatenation = null; boolean stringLiteralOccured = false; while (true) { - PsiExpression lOperand = element.getLOperand(); - PsiExpression rOperand = element.getROperand(); if (element.getOperationTokenType() != JavaTokenType.PLUS) return concatenation; - stringLiteralOccured |= lOperand instanceof PsiLiteralExpression && ((PsiLiteralExpression)lOperand).getValue() instanceof String || - rOperand instanceof PsiLiteralExpression && ((PsiLiteralExpression)rOperand).getValue() instanceof String; + for (PsiExpression operand : element.getOperands()) { + stringLiteralOccured |= operand instanceof PsiLiteralExpression && ((PsiLiteralExpression)operand).getValue() instanceof String; + } if (stringLiteralOccured) { concatenation = element; } PsiElement parent = element.getParent(); - if (!(parent instanceof PsiBinaryExpression)) return concatenation; - element = (PsiBinaryExpression) parent; + if (!(parent instanceof PsiPolyadicExpression)) return concatenation; + element = (PsiPolyadicExpression) parent; } } - private static PsiLiteralExpression getContainingLiteral(final PsiBinaryExpression concatenation) { - PsiExpression operand = concatenation.getLOperand(); - PsiLiteralExpression literalExpression = null; - if (operand instanceof PsiLiteralExpression) { - literalExpression = (PsiLiteralExpression)operand; - } - else { - operand = concatenation.getROperand(); + private static PsiLiteralExpression getContainingLiteral(final PsiPolyadicExpression concatenation) { + for (PsiExpression operand : concatenation.getOperands()) { if (operand instanceof PsiLiteralExpression) { - literalExpression = (PsiLiteralExpression)operand; + return (PsiLiteralExpression)operand; } } - return literalExpression; + return null; } } diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic b/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic index 748c45c29a61..b7962ea61edb 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic +++ b/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic @@ -267,6 +267,7 @@ plugin plugins pointcut pointcuts +polyadic popup popups posix @@ -417,6 +418,7 @@ workflow wsdl xcode xcodeproj +xhtml xmlschema xmlschemas xmltype diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnHistoryProvider.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnHistoryProvider.java index 734a4690519c..6c64cccb68c7 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnHistoryProvider.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnHistoryProvider.java @@ -35,7 +35,6 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.ColoredTableCellRenderer; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.SimpleTextAttributes; -import com.intellij.util.CollectConsumer; import com.intellij.util.Consumer; import com.intellij.util.ThrowableConsumer; import com.intellij.util.ui.ColumnInfo; @@ -57,7 +56,6 @@ import javax.swing.table.TableCellRenderer; import java.awt.*; import java.awt.event.MouseEvent; import java.io.File; -import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; @@ -186,31 +184,53 @@ public class SvnHistoryProvider implements VcsHistoryProvider, VcsCacheableHisto @Nullable public VcsHistorySession createSessionFor(final FilePath filePath) throws VcsException { - final FilePath committedPath = ChangesUtil.getCommittedPath(myVcs.getProject(), filePath); - final Ref supports15Ref = new Ref(); - final List revisions = new ArrayList(); - getRevisionsList(committedPath, supports15Ref, new CollectConsumer(revisions)); - return new MyHistorySession(revisions, committedPath, Boolean.TRUE.equals(supports15Ref.get()), null); + final VcsAppendableHistoryPartnerAdapter adapter = new VcsAppendableHistoryPartnerAdapter(); + reportAppendableHistory(filePath, adapter); + adapter.check(); + + return adapter.getSession(); } public void reportAppendableHistory(FilePath path, final VcsAppendableHistorySessionPartner partner) throws VcsException { final FilePath committedPath = ChangesUtil.getCommittedPath(myVcs.getProject(), path); - final Ref supports15Ref = new Ref(); + + final LogLoader logLoader; + if (path.isNonLocal()) { + logLoader = new RepositoryLoader(myVcs, path); + } else { + logLoader = new LocalLoader(myVcs, path); + } + + try { + logLoader.preliminary(); + } catch (SVNCancelException e) { + return; + } catch (SVNException e) { + throw new VcsException(e); + } + logLoader.initSupports15(); final MyHistorySession historySession = - new MyHistorySession(Collections.emptyList(), committedPath, Boolean.TRUE.equals(supports15Ref.get()), null); + new MyHistorySession(Collections.emptyList(), committedPath, Boolean.TRUE.equals(logLoader.mySupport15), null); final Ref sessionReported = new Ref(); - - getRevisionsList(committedPath, supports15Ref, new Consumer() { + final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); + if (indicator != null) { + indicator.setText(SvnBundle.message("progress.text2.collecting.history", path.getName())); + } + final Consumer consumer = new Consumer() { public void consume(VcsFileRevision vcsFileRevision) { - if (! Boolean.TRUE.equals(sessionReported.get())) { + if (!Boolean.TRUE.equals(sessionReported.get())) { partner.reportCreatedEmptySession(historySession); sessionReported.set(true); } partner.acceptRevision(vcsFileRevision); } - }); + }; + + logLoader.setConsumer(consumer); + logLoader.load(); + logLoader.check(); } @Nullable @@ -250,6 +270,97 @@ public class SvnHistoryProvider implements VcsHistoryProvider, VcsCacheableHisto } } + private static abstract class LogLoader { + protected String myUrl; + protected boolean mySupport15; + protected final SvnVcs myVcs; + protected final FilePath myFile; + protected Consumer myConsumer; + protected final ProgressIndicator myPI; + protected VcsException myException; + + protected LogLoader(SvnVcs vcs, FilePath file) { + myVcs = vcs; + myFile = file; + myPI = ProgressManager.getInstance().getProgressIndicator(); + } + + public void setConsumer(Consumer consumer) { + myConsumer = consumer; + } + + protected void initSupports15() { + assert myUrl != null; + mySupport15 = SvnUtil.checkRepositoryVersion15(myVcs, myUrl); + } + + public void check() throws VcsException { + if (myException != null) throw myException; + } + + protected abstract void preliminary() throws SVNException; + protected abstract void load(); + } + + private static class LocalLoader extends LogLoader { + private SVNInfo myInfo; + + private LocalLoader(SvnVcs vcs, FilePath file) { + super(vcs, file); + } + + @Override + protected void preliminary() throws SVNException { + SVNWCClient wcClient = myVcs.createWCClient(); + myInfo = wcClient.doInfo(new File(myFile.getIOFile().getAbsolutePath()), SVNRevision.WORKING); + wcClient.setEventHandler(new ISVNEventHandler() { + public void handleEvent(SVNEvent event, double progress) throws SVNException { + } + + public void checkCancelled() throws SVNCancelException { + myPI.checkCanceled(); + } + }); + if (myInfo == null || myInfo.getRepositoryRootURL() == null) { + myException = new VcsException("File ''{0}'' is not under version control" + myFile.getIOFile()); + return; + } + if (myInfo.getURL() == null) { + myException = new VcsException("File " + myFile.getPath() + " is not under Subversion control"); + return; + } + myUrl = myInfo.getURL().toString(); + } + + @Override + protected void load() { + String relativeUrl = myUrl; + final SVNURL repoRootURL = myInfo.getRepositoryRootURL(); + + final String root = repoRootURL.toString(); + if (myUrl != null && myUrl.startsWith(root)) { + relativeUrl = myUrl.substring(root.length()); + } + if (myPI != null) { + myPI.setText2(SvnBundle.message("progress.text2.changes.establishing.connection", myUrl)); + } + final SVNRevision pegRevision = myInfo.getRevision(); + SVNLogClient client = myVcs.createLogClient(); + try { + client.doLog(new File[]{new File(myFile.getIOFile().getAbsolutePath())}, SVNRevision.HEAD, SVNRevision.create(1), SVNRevision.UNDEFINED, + false, true, mySupport15, 0, null, + new MyLogEntryHandler(myVcs, myUrl, pegRevision, relativeUrl, myConsumer, repoRootURL)); + } catch (SVNCancelException e) { + // + } catch (SVNException e) { + myException = new VcsException(e); + } + catch (VcsException e) { + myException = e; + } + } + } + private void collectLogEntries(final ProgressIndicator indicator, FilePath file, VcsException[] exception, final Consumer result, final Ref supports15Ref) throws SVNException, VcsException { @@ -285,7 +396,46 @@ public class SvnHistoryProvider implements VcsHistoryProvider, VcsCacheableHisto supports15Ref.set(supports15); client.doLog(new File[]{new File(file.getIOFile().getAbsolutePath())}, SVNRevision.HEAD, SVNRevision.create(1), SVNRevision.UNDEFINED, false, true, supports15, 0, null, - new MyLogEntryHandler(url, pegRevision, relativeUrl, result, repoRootURL)); + new MyLogEntryHandler(myVcs, url, pegRevision, relativeUrl, result, repoRootURL)); + } + + private static class RepositoryLoader extends LogLoader { + private RepositoryLoader(SvnVcs vcs, FilePath file) { + super(vcs, file); + } + + @Override + protected void preliminary() throws SVNException { + myUrl = myFile.getPath().replace('\\', '/'); + } + + @Override + protected void load() { + if (myPI != null) { + myPI.setText2(SvnBundle.message("progress.text2.changes.establishing.connection", myUrl)); + } + SVNWCClient wcClient = myVcs.createWCClient(); + try { + final SVNURL svnurl = SVNURL.parseURIEncoded(myUrl); + SVNInfo info = null; + info = wcClient.doInfo(svnurl, SVNRevision.UNDEFINED, SVNRevision.HEAD); + final String root = info.getRepositoryRootURL().toString(); + String relativeUrl = myUrl; + if (myUrl.startsWith(root)) { + relativeUrl = myUrl.substring(root.length()); + } + SVNLogClient client = myVcs.createLogClient(); + client.doLog(svnurl, new String[] {}, SVNRevision.UNDEFINED, SVNRevision.HEAD, SVNRevision.create(1), false, true, mySupport15, 0, null, + new RepositoryLogEntryHandler(myVcs, myUrl, SVNRevision.UNDEFINED, relativeUrl, myConsumer, info.getRepositoryRootURL())); + } catch (SVNCancelException e) { + // + } catch (SVNException e) { + myException = new VcsException(e); + } + catch (VcsException e) { + myException = e; + } + } } private void collectLogEntriesForRepository(final ProgressIndicator indicator, FilePath file, final Consumer result, @@ -307,7 +457,7 @@ public class SvnHistoryProvider implements VcsHistoryProvider, VcsCacheableHisto supports15Ref.set(supports15); // todo log in history provider client.doLog(svnurl, new String[] {}, SVNRevision.UNDEFINED, SVNRevision.HEAD, SVNRevision.create(1), false, true, supports15, 0, null, - new RepositoryLogEntryHandler(url, SVNRevision.UNDEFINED, relativeUrl, result, info.getRepositoryRootURL())); + new RepositoryLogEntryHandler(myVcs, url, SVNRevision.UNDEFINED, relativeUrl, result, info.getRepositoryRootURL())); } public String getHelpId() { @@ -343,8 +493,9 @@ public class SvnHistoryProvider implements VcsHistoryProvider, VcsCacheableHisto return false; } - private class MyLogEntryHandler implements ISVNLogEntryHandler { + private static class MyLogEntryHandler implements ISVNLogEntryHandler { private final ProgressIndicator myIndicator; + protected final SvnVcs myVcs; private String myLastPath; protected final Consumer myResult; private VcsFileRevision myPrevious; @@ -353,12 +504,13 @@ public class SvnHistoryProvider implements VcsHistoryProvider, VcsCacheableHisto private final SvnMergeSourceTracker myTracker; private SVNURL myRepositoryRoot; - public MyLogEntryHandler(final String url, + public MyLogEntryHandler(SvnVcs vcs, final String url, final SVNRevision pegRevision, String lastPath, final Consumer result, SVNURL repoRootURL) throws SVNException, VcsException { + myVcs = vcs; myLastPath = lastPath; myIndicator = ProgressManager.getInstance().getProgressIndicator(); myResult = result; @@ -436,14 +588,14 @@ public class SvnHistoryProvider implements VcsHistoryProvider, VcsCacheableHisto } } - private class RepositoryLogEntryHandler extends MyLogEntryHandler { - public RepositoryLogEntryHandler(final String url, + private static class RepositoryLogEntryHandler extends MyLogEntryHandler { + public RepositoryLogEntryHandler(final SvnVcs vcs, final String url, final SVNRevision pegRevision, String lastPath, final Consumer result, SVNURL repoRootURL) throws VcsException, SVNException { - super(url, pegRevision, lastPath, result, repoRootURL); + super(vcs, url, pegRevision, lastPath, result, repoRootURL); } @Override diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index 398073393100..4e648ae57daf 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -78,6 +78,10 @@ + +