Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
69e1ff67
Commit
69e1ff67
authored
7 years ago
by
Tagir Valeev
Browse files
Options
Download
Email Patches
Plain Diff
ReplaceShiftWithMultiplyIntention: support parentheses; tests
parent
dc328949
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceShiftWithMultiplyIntention.java
+3
-2
...om/siyeh/ipp/shift/ReplaceShiftWithMultiplyIntention.java
plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ShiftByLiteralPredicate.java
+2
-1
...rPak/src/com/siyeh/ipp/shift/ShiftByLiteralPredicate.java
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/LeftShift.java
+5
-0
...iyeh/ipp/shift/replace_shift_with_multiply/LeftShift.java
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/LeftShiftAssign.java
+5
-0
...pp/shift/replace_shift_with_multiply/LeftShiftAssign.java
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/LeftShiftAssign_after.java
+5
-0
...ft/replace_shift_with_multiply/LeftShiftAssign_after.java
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/LeftShift_after.java
+5
-0
...pp/shift/replace_shift_with_multiply/LeftShift_after.java
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/Parentheses.java
+5
-0
...eh/ipp/shift/replace_shift_with_multiply/Parentheses.java
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/Parentheses_after.java
+5
-0
.../shift/replace_shift_with_multiply/Parentheses_after.java
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/RightShift.java
+5
-0
...yeh/ipp/shift/replace_shift_with_multiply/RightShift.java
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/RightShift_after.java
+5
-0
...p/shift/replace_shift_with_multiply/RightShift_after.java
plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/shift/ReplaceShiftWithMultiplyIntentionTest.java
+17
-0
...iyeh/ipp/shift/ReplaceShiftWithMultiplyIntentionTest.java
with
62 additions
and
3 deletions
+62
-3
plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceShiftWithMultiplyIntention.java
+
3
-
2
View file @
69e1ff67
...
...
@@ -17,6 +17,7 @@ package com.siyeh.ipp.shift;
import
com.intellij.psi.*
;
import
com.intellij.psi.tree.IElementType
;
import
com.intellij.psi.util.PsiUtil
;
import
com.siyeh.IntentionPowerPackBundle
;
import
com.siyeh.ig.PsiReplacementUtil
;
import
com.siyeh.ig.psiutils.CommentTracker
;
...
...
@@ -69,7 +70,7 @@ public class ReplaceShiftWithMultiplyIntention extends MutablyNamedIntention {
}
@Override
public
void
processIntention
(
PsiElement
element
)
{
public
void
processIntention
(
@NotNull
PsiElement
element
)
{
if
(
element
instanceof
PsiBinaryExpression
)
{
replaceShiftWithMultiplyOrDivide
(
element
);
}
...
...
@@ -100,7 +101,7 @@ public class ReplaceShiftWithMultiplyIntention extends MutablyNamedIntention {
private
static
void
replaceShiftWithMultiplyOrDivide
(
PsiElement
element
)
{
final
PsiBinaryExpression
exp
=
(
PsiBinaryExpression
)
element
;
final
PsiExpression
lhs
=
exp
.
getLOperand
();
final
PsiExpression
rhs
=
exp
.
getROperand
();
final
PsiExpression
rhs
=
PsiUtil
.
skipParenthesizedExprDown
(
exp
.
getROperand
()
)
;
final
IElementType
tokenType
=
exp
.
getOperationTokenType
();
final
String
operatorString
;
if
(
tokenType
.
equals
(
JavaTokenType
.
LTLT
))
{
...
...
This diff is collapsed.
Click to expand it.
plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ShiftByLiteralPredicate.java
+
2
-
1
View file @
69e1ff67
...
...
@@ -17,6 +17,7 @@ package com.siyeh.ipp.shift;
import
com.intellij.psi.*
;
import
com.intellij.psi.tree.IElementType
;
import
com.intellij.psi.util.PsiUtil
;
import
com.siyeh.ipp.base.PsiElementPredicate
;
class
ShiftByLiteralPredicate
implements
PsiElementPredicate
{
...
...
@@ -68,7 +69,7 @@ class ShiftByLiteralPredicate implements PsiElementPredicate {
if
(!
ShiftUtils
.
isIntegral
(
lhsType
))
{
return
false
;
}
final
PsiExpression
rhs
=
expression
.
getROperand
();
final
PsiExpression
rhs
=
PsiUtil
.
skipParenthesizedExprDown
(
expression
.
getROperand
()
)
;
return
ShiftUtils
.
isIntLiteral
(
rhs
);
}
}
This diff is collapsed.
Click to expand it.
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/LeftShift.java
0 → 100644
+
5
-
0
View file @
69e1ff67
class
Test
{
void
test
(
int
foo
)
{
int
x
=
foo
<<
1
<
caret
>
2
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/LeftShiftAssign.java
0 → 100644
+
5
-
0
View file @
69e1ff67
class
Test
{
void
test
(
int
foo
)
{
foo
<<=
1
<
caret
>
2
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/LeftShiftAssign_after.java
0 → 100644
+
5
-
0
View file @
69e1ff67
class
Test
{
void
test
(
int
foo
)
{
foo
*=
4096
<
caret
>;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/LeftShift_after.java
0 → 100644
+
5
-
0
View file @
69e1ff67
class
Test
{
void
test
(
int
foo
)
{
int
x
=
foo
*
4096
<
caret
>;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/Parentheses.java
0 → 100644
+
5
-
0
View file @
69e1ff67
class
Test
{
void
test
(
int
foo
)
{
int
x
=
foo
<<
(
2
<
caret
>
4
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/Parentheses_after.java
0 → 100644
+
5
-
0
View file @
69e1ff67
class
Test
{
void
test
(
int
foo
)
{
int
x
=
foo
*
16777
<
caret
>
216
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/RightShift.java
0 → 100644
+
5
-
0
View file @
69e1ff67
class
Test
{
void
test
(
int
foo
)
{
int
x
=
foo
>>
1
<
caret
>
2
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
plugins/IntentionPowerPak/test/com/siyeh/ipp/shift/replace_shift_with_multiply/RightShift_after.java
0 → 100644
+
5
-
0
View file @
69e1ff67
class
Test
{
void
test
(
int
foo
)
{
int
x
=
foo
/
4096
<
caret
>;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/shift/ReplaceShiftWithMultiplyIntentionTest.java
0 → 100644
+
17
-
0
View file @
69e1ff67
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package
com.siyeh.ipp.shift
;
import
com.siyeh.ipp.IPPTestCase
;
public
class
ReplaceShiftWithMultiplyIntentionTest
extends
IPPTestCase
{
public
void
testLeftShift
()
{
doTest
(
"Replace '<<' with '*'"
);
}
public
void
testLeftShiftAssign
()
{
doTest
(
"Replace '<<=' with '*='"
);
}
public
void
testParentheses
()
{
doTest
(
"Replace '<<' with '*'"
);
}
public
void
testRightShift
()
{
doTest
(
"Replace '>>' with '/'"
);
}
@Override
protected
String
getRelativePath
()
{
return
"shift/replace_shift_with_multiply"
;
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help