Project Coin numeric literals (IntentionPowerPack)

This commit is contained in:
Roman Shevchenko
2011-02-08 12:20:44 +01:00
parent 6bb01e2fba
commit e6ebb46ea9
78 changed files with 600 additions and 218 deletions
@@ -4,6 +4,7 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/testSrc" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
@@ -13,6 +14,7 @@
<orderEntry type="library" name="JDOM" level="project" />
<orderEntry type="library" name="JUnit4" level="project" />
<orderEntry type="module" module-name="jsp-openapi" />
<orderEntry type="module" module-name="testFramework-java" scope="TEST" />
</component>
</module>
@@ -35,6 +35,11 @@
<categoryKey>intention.category.numbers</categoryKey>
</intentionAction>
<intentionAction>
<className>com.siyeh.ipp.integer.ConvertIntegerToBinaryIntention</className>
<categoryKey>intention.category.numbers</categoryKey>
</intentionAction>
<!-- Boolean -->
<intentionAction>
<className>com.siyeh.ipp.bool.DemorgansIntention</className>
@@ -55,6 +55,8 @@ move.comment.to.separate.line.intention.name=Move comment to separate line
move.comment.to.separate.line.intention.family.name=Move Comment to Separate Line
convert.integer.to.hex.intention.name=Convert to hex
convert.integer.to.hex.intention.family.name=Convert to Hexadecimal
convert.integer.to.binary.intention.name=Convert to binary
convert.integer.to.binary.intention.family.name=Convert to Binary
convert.to.engineering.notation.intention.name=Convert to Engineering notation
convert.to.engineering.notation.intention.family.name=Convert to Engineering notation
convert.to.plain.intention.name=Convert to Plain
@@ -0,0 +1,42 @@
/*
* 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.siyeh.ipp.integer;
import com.intellij.psi.PsiType;
import com.siyeh.ipp.base.PsiElementPredicate;
import org.jetbrains.annotations.NotNull;
public class ConvertIntegerToBinaryIntention extends ConvertNumberIntentionBase {
@Override
@NotNull
public PsiElementPredicate getElementPredicate() {
return new ConvertIntegerToBinaryPredicate();
}
@Override
protected String convertValue(final Number value, final PsiType type, final boolean negated) {
if (PsiType.INT.equals(type)) {
final int intValue = negated ? -value.intValue() : value.intValue();
return "0b" + Integer.toBinaryString(intValue);
}
else if (PsiType.LONG.equals(type)) {
final long longValue = negated ? -value.longValue() : value.longValue();
return "0b" + Long.toBinaryString(longValue) + "L";
}
return null;
}
}
@@ -0,0 +1,43 @@
/*
* 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.siyeh.ipp.integer;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiLiteralExpression;
import com.intellij.psi.PsiType;
import com.intellij.psi.util.PsiUtil;
import com.siyeh.ipp.base.PsiElementPredicate;
class ConvertIntegerToBinaryPredicate implements PsiElementPredicate {
@Override
public boolean satisfiedBy(final PsiElement element) {
if (!(element instanceof PsiLiteralExpression)) {
return false;
}
if (!PsiUtil.isLanguageLevel7OrHigher(element)) {
return false;
}
final PsiType type = ((PsiLiteralExpression)element).getType();
if (PsiType.INT.equals(type) || PsiType.LONG.equals(type)) {
final String text = element.getText();
return !(text.startsWith("0b") || text.startsWith("0B"));
}
return false;
}
}
@@ -15,65 +15,36 @@
*/
package com.siyeh.ipp.integer;
import com.intellij.psi.*;
import com.intellij.util.IncorrectOperationException;
import com.siyeh.ipp.base.Intention;
import com.intellij.psi.PsiType;
import com.siyeh.ipp.base.PsiElementPredicate;
import com.siyeh.ipp.psiutils.ExpressionUtils;
import org.jetbrains.annotations.NotNull;
public class ConvertIntegerToDecimalIntention extends Intention {
public class ConvertIntegerToDecimalIntention extends ConvertNumberIntentionBase {
@Override
@NotNull
public PsiElementPredicate getElementPredicate() {
return new ConvertIntegerToDecimalPredicate();
}
@Override @NotNull
public PsiElementPredicate getElementPredicate() {
return new ConvertIntegerToDecimalPredicate();
@Override
protected String convertValue(final Number value, final PsiType type, final boolean negated) {
if (PsiType.INT.equals(type)) {
final int intValue = negated ? -value.intValue() : value.intValue();
return Integer.toString(intValue);
}
else if (PsiType.LONG.equals(type)) {
final long longValue = negated ? -value.longValue() : value.longValue();
return Long.toString(longValue) + "L";
}
else if (PsiType.FLOAT.equals(type)) {
final float floatValue = negated ? -value.floatValue() : value.floatValue();
return Float.toString(floatValue) + 'f';
}
else if (PsiType.DOUBLE.equals(type)) {
final double doubleValue = negated ? -value.doubleValue() : value.doubleValue();
return Double.toString(doubleValue);
}
@Override
public void processIntention(@NotNull PsiElement element)
throws IncorrectOperationException {
final PsiExpression expression = (PsiExpression)element;
final boolean negated = ExpressionUtils.isNegated(expression);
final Number value =
(Number)ExpressionUtils.computeConstantExpression(expression);
if (value == null) {
return;
}
final PsiType type = expression.getType();
final String decimalString;
if (PsiType.INT.equals(type)) {
if (negated) {
decimalString = String.valueOf(-value.intValue());
} else {
decimalString = String.valueOf(value.intValue());
}
} else if (PsiType.LONG.equals(type)) {
if (negated) {
decimalString = String.valueOf(-value.longValue()) + 'L';
} else {
decimalString = String.valueOf(value.longValue()) + 'L';
}
} else if (PsiType.FLOAT.equals(type)) {
if (negated) {
decimalString = String.valueOf(-value.floatValue()) + 'f';
} else {
decimalString = String.valueOf(value.floatValue()) + 'f';
}
}
else if (PsiType.DOUBLE.equals(type)) {
if (negated) {
decimalString = String.valueOf(-value.doubleValue());
} else {
decimalString = String.valueOf(value.doubleValue());
}
} else {
return;
}
if (negated) {
replaceExpression(decimalString,
(PsiExpression)expression.getParent());
} else {
replaceExpression(decimalString, expression);
}
}
return null;
}
}
@@ -18,7 +18,6 @@ package com.siyeh.ipp.integer;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiLiteralExpression;
import com.intellij.psi.PsiType;
import com.intellij.psi.util.PsiUtil;
import com.siyeh.ipp.base.PsiElementPredicate;
import org.jetbrains.annotations.NonNls;
@@ -41,9 +40,6 @@ class ConvertIntegerToDecimalPredicate implements PsiElementPredicate{
return text.charAt(0) == '0';
}
if(PsiType.DOUBLE.equals(type) || PsiType.FLOAT.equals(type)){
if(!PsiUtil.isLanguageLevel5OrHigher(expression)){
return false;
}
@NonNls final String text = expression.getText();
if(text == null || text.length() < 2){
return false;
@@ -15,90 +15,36 @@
*/
package com.siyeh.ipp.integer;
import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.IncorrectOperationException;
import com.siyeh.ipp.base.Intention;
import com.intellij.psi.PsiType;
import com.siyeh.ipp.base.PsiElementPredicate;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.math.BigInteger;
public class ConvertIntegerToHexIntention extends ConvertNumberIntentionBase {
@Override
@NotNull
public PsiElementPredicate getElementPredicate() {
return new ConvertIntegerToHexPredicate();
}
public class ConvertIntegerToHexIntention extends Intention {
private static final BigInteger LONG_BINARY_ONES =
new BigInteger("ffffffffffffffff", 16);
private static final BigInteger INT_BINARY_ONES =
new BigInteger("ffffffff", 16);
@Override @NotNull
public PsiElementPredicate getElementPredicate() {
return new ConvertIntegerToHexPredicate();
@Override
protected String convertValue(final Number value, final PsiType type, final boolean negated) {
if (PsiType.INT.equals(type)) {
final int intValue = negated ? -value.intValue() : value.intValue();
return "0x" + Integer.toHexString(intValue);
}
else if (PsiType.LONG.equals(type)) {
final long longValue = negated ? -value.longValue() : value.longValue();
return "0x" + Long.toHexString(longValue) + "L";
}
else if (PsiType.FLOAT.equals(type)) {
final float floatValue = negated ? -value.floatValue() : value.floatValue();
return Float.toHexString(floatValue) + 'f';
}
else if (PsiType.DOUBLE.equals(type)) {
final double doubleValue = negated ? -value.doubleValue() : value.doubleValue();
return Double.toHexString(doubleValue);
}
@Override
public void processIntention(@NotNull PsiElement element)
throws IncorrectOperationException {
final PsiExpression expression = (PsiExpression)element;
final PsiType type = expression.getType();
if (PsiType.INT.equals(type) || PsiType.LONG.equals(type)) {
String textString = expression.getText();
final int textLength = textString.length();
final char lastChar = textString.charAt(textLength - 1);
final boolean isLong = lastChar == 'l' || lastChar == 'L';
if (isLong) {
textString = textString.substring(0, textLength - 1);
}
BigInteger value;
if (textString.charAt(0) == '0') {
value = new BigInteger(textString, 8);
} else {
value = new BigInteger(textString, 10);
final PsiElement parent = expression.getParent();
if (parent instanceof PsiPrefixExpression) {
final PsiPrefixExpression prefixExpression =
(PsiPrefixExpression)parent;
final IElementType tokenType =
prefixExpression.getOperationTokenType();
if (JavaTokenType.MINUS == tokenType) {
if (isLong) {
value = value.xor(LONG_BINARY_ONES).add(BigInteger.ONE);
} else {
value = value.xor(INT_BINARY_ONES).add(BigInteger.ONE);
}
@NonNls String hexString = "0x" + value.toString(16);
if (isLong) {
hexString += 'L';
}
replaceExpression(hexString, prefixExpression);
return;
}
}
}
@NonNls String hexString = "0x" + value.toString(16);
if (isLong) {
hexString += 'L';
}
replaceExpression(hexString, expression);
} else {
String textString = expression.getText();
final int textLength = textString.length();
final char lastChar = textString.charAt(textLength - 1);
final boolean isFloat = lastChar == 'f' || lastChar == 'F';
if (isFloat) {
textString = textString.substring(0, textLength - 1);
}
if (isFloat) {
final float floatValue = Float.parseFloat(textString);
final String floatString =
Float.toHexString(floatValue) + lastChar;
replaceExpression(floatString, expression);
} else {
final double doubleValue = Double.parseDouble(textString);
final String floatString = Double.toHexString(doubleValue);
replaceExpression(floatString, expression);
}
}
}
return null;
}
}
@@ -15,73 +15,28 @@
*/
package com.siyeh.ipp.integer;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiExpression;
import com.intellij.psi.PsiPrefixExpression;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.IncorrectOperationException;
import com.siyeh.ipp.base.Intention;
import com.intellij.psi.PsiType;
import com.siyeh.ipp.base.PsiElementPredicate;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.math.BigInteger;
public class ConvertIntegerToOctalIntention extends ConvertNumberIntentionBase {
@Override
@NotNull
public PsiElementPredicate getElementPredicate() {
return new ConvertIntegerToOctalPredicate();
}
public class ConvertIntegerToOctalIntention extends Intention {
private static final BigInteger LONG_BINARY_ONES =
new BigInteger("ffffffffffffffff", 16);
private static final BigInteger INT_BINARY_ONES =
new BigInteger("ffffffff", 16);
@Override @NotNull
public PsiElementPredicate getElementPredicate() {
return new ConvertIntegerToOctalPredicate();
@Override
protected String convertValue(final Number value, final PsiType type, final boolean negated) {
if (PsiType.INT.equals(type)) {
final int intValue = negated ? -value.intValue() : value.intValue();
return "0" + Integer.toOctalString(intValue);
}
else if (PsiType.LONG.equals(type)) {
final long longValue = negated ? -value.longValue() : value.longValue();
return "0" + Long.toOctalString(longValue) + "L";
}
@Override
public void processIntention(@NotNull PsiElement element)
throws IncorrectOperationException {
final PsiExpression expression = (PsiExpression)element;
@NonNls String textString = expression.getText();
final int textLength = textString.length();
final char lastChar = textString.charAt(textLength - 1);
final boolean isLong = lastChar == 'l' || lastChar == 'L';
if (isLong) {
textString = textString.substring(0, textLength - 1);
}
BigInteger value;
if (textString.startsWith("0x")) {
final String rawTextString = textString.substring(2);
value = new BigInteger(rawTextString, 16);
} else {
value = new BigInteger(textString, 10);
final PsiElement parent = expression.getParent();
if (parent instanceof PsiPrefixExpression) {
final PsiPrefixExpression prefixExpression =
(PsiPrefixExpression)parent;
final IElementType tokenType =
prefixExpression.getOperationTokenType();
if (JavaTokenType.MINUS == tokenType) {
if (isLong) {
value = value.xor(LONG_BINARY_ONES).add(BigInteger.ONE);
} else {
value = value.xor(INT_BINARY_ONES).add(BigInteger.ONE);
}
@NonNls String hexString = '0' + value.toString(8);
if (isLong) {
hexString += 'L';
}
replaceExpression(hexString, prefixExpression);
return;
}
}
}
String octString = '0' + value.toString(8);
if (isLong) {
octString += 'L';
}
replaceExpression(octString, expression);
}
return null;
}
}
@@ -33,15 +33,16 @@ class ConvertIntegerToOctalPredicate implements PsiElementPredicate{
return false;
}
@NonNls final String text = expression.getText();
if(text == null || text.length() == 0){
return false;
}
if(text.startsWith("0x") || text.startsWith("0X")){
if (text.charAt(0) != '0') {
return true;
}
if("0".equals(text) || "0L".equals(text)){
return false;
if (text.length() < 2) {
return true;
}
return text.charAt(0) != '0';
final char c1 = text.charAt(1);
if (c1 != '_' && (c1 < '0' || c1 > '7')) {
return true;
}
return false;
}
}
@@ -0,0 +1,49 @@
/*
* 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.siyeh.ipp.integer;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiExpression;
import com.intellij.psi.PsiType;
import com.intellij.util.IncorrectOperationException;
import com.siyeh.ipp.base.Intention;
import com.siyeh.ipp.psiutils.ExpressionUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class ConvertNumberIntentionBase extends Intention {
@Override
protected void processIntention(@NotNull final PsiElement element) throws IncorrectOperationException {
final PsiExpression expression = (PsiExpression)element;
final Number value = (Number)ExpressionUtils.computeConstantExpression(expression);
if (value == null) return;
final PsiType type = expression.getType();
final boolean negated = ExpressionUtils.isNegated(expression);
final String resultString = convertValue(value, type, negated);
if (resultString == null) return;
if (negated) {
replaceExpression(resultString, (PsiExpression)expression.getParent());
}
else {
replaceExpression(resultString, expression);
}
}
@Nullable
protected abstract String convertValue(final Number value, final PsiType type, final boolean negated);
}
@@ -0,0 +1,5 @@
public class X {
void f() {
int i = 0b101;
}
}
@@ -0,0 +1,5 @@
public class X {
void f() {
int i = <spot>5</spot>;
}
}
@@ -0,0 +1,6 @@
<html>
<body>
<font face="verdana" size="-1">This intention converts selected integer literal into <b>binary</b> notation
(supported in JDK 7 or higher).</font>
</body>
</html>
@@ -1,7 +1,5 @@
<html>
<body>
<font face="verdana" size="-1">This intention converts selected integer literal (written in either <b>hex</b> or <b>octal</b> notation)
back into <b>decimal</b> notation.
</font>
<font face="verdana" size="-1">This intention converts selected integer literal into <b>decimal</b> notation.</font>
</body>
</html>
@@ -1,7 +1,5 @@
<html>
<body>
<font face="verdana" size="-1">This intention converts selected integer literal (written in either <b>decimal</b> or <b>octal</b> notation)
into <b>hexadecimal</b> notation.
</font>
<font face="verdana" size="-1">This intention converts selected integer literal into <b>hexadecimal</b> notation.</font>
</body>
</html>
@@ -1,7 +1,5 @@
<html>
<body>
<font face="verdana" size="-1">This intention converts selected integer literal (written in either <b>decimal</b> or <b>hexadecimal</b> notation)
into <b>octal</b> notation.
</font>
<font face="verdana" size="-1">This intention converts selected integer literal into <b>octal</b> notation.</font>
</body>
</html>
@@ -0,0 +1,3 @@
class C {
int i = <caret>0b0__1010_1011_1100_1101;
}
@@ -0,0 +1,3 @@
class C {
int i = 43981;
}
@@ -0,0 +1,3 @@
class C {
long l = -<caret>0b0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L;
}
@@ -0,0 +1,3 @@
class C {
long l = -9223372036854775807L;
}
@@ -0,0 +1,3 @@
class C {
int i = <caret>0b0__1010_1011_1100_1101;
}
@@ -0,0 +1,3 @@
class C {
int i = 0xabcd;
}
@@ -0,0 +1,3 @@
class C {
long l = -<caret>0b0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L;
}
@@ -0,0 +1,3 @@
class C {
long l = 0x8000000000000001L;
}
@@ -0,0 +1,3 @@
class C {
int i = <caret>0b0__1010_1011_1100_1101;
}
@@ -0,0 +1,3 @@
class C {
int i = 0125715;
}
@@ -0,0 +1,3 @@
class C {
long l = -<caret>0b0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L;
}
@@ -0,0 +1,3 @@
class C {
long l = 01000000000000000000001L;
}
@@ -0,0 +1,3 @@
class C {
int i = <caret>12__345;
}
@@ -0,0 +1,3 @@
class C {
int i = 0b11000000111001;
}
@@ -0,0 +1,3 @@
class C {
long l = -<caret>922_3372_0368_5477_5807L;
}
@@ -0,0 +1,3 @@
class C {
long l = 0b1000000000000000000000000000000000000000000000000000000000000001L;
}
@@ -0,0 +1,3 @@
class C {
int i = <caret>12__345;
}
@@ -0,0 +1,3 @@
class C {
int i = 0x3039;
}
@@ -0,0 +1,3 @@
class C {
long l = -<caret>922_3372_0368_5477_5807L;
}
@@ -0,0 +1,3 @@
class C {
long l = 0x8000000000000001L;
}
@@ -0,0 +1,3 @@
class C {
float f = <caret>1.844_696_84E1_1f;
}
@@ -0,0 +1,3 @@
class C {
float f = 0x1.579ap37f;
}
@@ -0,0 +1,3 @@
class C {
double d = -<caret>1.797_693_134_862__3157E3_0_8;
}
@@ -0,0 +1,3 @@
class C {
double d = -0x1.fffffffffffffp1023;
}
@@ -0,0 +1,3 @@
class C {
int i = <caret>12__345;
}
@@ -0,0 +1,3 @@
class C {
int i = 030071;
}
@@ -0,0 +1,3 @@
class C {
long l = -<caret>922_3372_0368_5477_5807L;
}
@@ -0,0 +1,3 @@
class C {
long l = 01000000000000000000001L;
}
@@ -0,0 +1,3 @@
class C {
int i = <caret>0xab_cd;
}
@@ -0,0 +1,3 @@
class C {
int i = 0b1010101111001101;
}
@@ -0,0 +1,3 @@
class C {
long l = -<caret>0x7fff_ffff_ffff_ffffL;
}
@@ -0,0 +1,3 @@
class C {
long l = 0b1000000000000000000000000000000000000000000000000000000000000001L;
}
@@ -0,0 +1,3 @@
class C {
int i = <caret>0xab_cd;
}
@@ -0,0 +1,3 @@
class C {
int i = 43981;
}
@@ -0,0 +1,3 @@
class C {
long l = -<caret>0x7fff_ffff_ffff_ffffL;
}
@@ -0,0 +1,3 @@
class C {
long l = -9223372036854775807L;
}
@@ -0,0 +1,3 @@
class C {
float f = <caret>0xab_cd.P2_2f;
}
@@ -0,0 +1,3 @@
class C {
float f = 1.84469684E11f;
}
@@ -0,0 +1,3 @@
class C {
double d = -<caret>0x1.ffff_ffff_ffff_fP1_023;
}
@@ -0,0 +1,3 @@
class C {
double d = -1.7976931348623157E308;
}
@@ -0,0 +1,3 @@
class C {
int i = <caret>0xab_cd;
}
@@ -0,0 +1,3 @@
class C {
int i = 0125715;
}
@@ -0,0 +1,3 @@
class C {
long l = -<caret>0x7fff_ffff_ffff_ffffL;
}
@@ -0,0 +1,3 @@
class C {
long l = 01000000000000000000001L;
}
@@ -0,0 +1,3 @@
class C {
int i = <caret>0_125_715;
}
@@ -0,0 +1,3 @@
class C {
int i = 0b1010101111001101;
}
@@ -0,0 +1,3 @@
class C {
long l = -<caret>0777777___77777_777__7777_777L;
}
@@ -0,0 +1,3 @@
class C {
long l = 0b1000000000000000000000000000000000000000000000000000000000000001L;
}
@@ -0,0 +1,3 @@
class C {
int i = <caret>0_125_715;
}
@@ -0,0 +1,3 @@
class C {
int i = 43981;
}
@@ -0,0 +1,3 @@
class C {
long l = -<caret>0777777___77777_777__7777_777L;
}
@@ -0,0 +1,3 @@
class C {
long l = -9223372036854775807L;
}
@@ -0,0 +1,3 @@
class C {
int i = <caret>0_125_715;
}
@@ -0,0 +1,3 @@
class C {
int i = 0xabcd;
}
@@ -0,0 +1,3 @@
class C {
long l = -<caret>0777777___77777_777__7777_777L;
}
@@ -0,0 +1,3 @@
class C {
long l = 0x8000000000000001L;
}
@@ -0,0 +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.siyeh.ipp;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.testFramework.fixtures.CodeInsightTestUtil;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
public abstract class IPPTestCase extends LightCodeInsightFixtureTestCase {
@Override
protected String getBasePath() {
return PluginPathManager.getPluginHomePathRelative("IntentionPowerPak") + "/test/com/siyeh/ipp/" + getRelativePath();
}
protected abstract String getRelativePath();
protected void doTest() {
final String testName = getTestName(false);
CodeInsightTestUtil.doIntentionTest(myFixture, getIntentionName(), testName + ".java", testName + "_after.java");
}
protected abstract String getIntentionName();
}
@@ -0,0 +1,38 @@
/*
* 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.siyeh.ipp.integer;
import com.siyeh.IntentionPowerPackBundle;
import com.siyeh.ipp.IPPTestCase;
public class ConvertIntegerToBinaryTest extends IPPTestCase {
public void testDecToBin1() { doTest(); }
public void testDecToBin2() { doTest(); }
public void testHexToBin1() { doTest(); }
public void testHexToBin2() { doTest(); }
public void testOctToBin1() { doTest(); }
public void testOctToBin2() { doTest(); }
@Override
protected String getIntentionName() {
return IntentionPowerPackBundle.message("convert.integer.to.binary.intention.name");
}
@Override
protected String getRelativePath() {
return "integer";
}
}
@@ -0,0 +1,40 @@
/*
* 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.siyeh.ipp.integer;
import com.siyeh.IntentionPowerPackBundle;
import com.siyeh.ipp.IPPTestCase;
public class ConvertIntegerToDecimalTest extends IPPTestCase {
public void testHexToDec1() { doTest(); }
public void testHexToDec2() { doTest(); }
public void testHexToDec3() { doTest(); }
public void testHexToDec4() { doTest(); }
public void testOctToDec1() { doTest(); }
public void testOctToDec2() { doTest(); }
public void testBinToDec1() { doTest(); }
public void testBinToDec2() { doTest(); }
@Override
protected String getIntentionName() {
return IntentionPowerPackBundle.message("convert.integer.to.decimal.intention.name");
}
@Override
protected String getRelativePath() {
return "integer";
}
}
@@ -0,0 +1,40 @@
/*
* 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.siyeh.ipp.integer;
import com.siyeh.IntentionPowerPackBundle;
import com.siyeh.ipp.IPPTestCase;
public class ConvertIntegerToHexTest extends IPPTestCase {
public void testDecToHex1() { doTest(); }
public void testDecToHex2() { doTest(); }
public void testDecToHex3() { doTest(); }
public void testDecToHex4() { doTest(); }
public void testOctToHex1() { doTest(); }
public void testOctToHex2() { doTest(); }
public void testBinToHex1() { doTest(); }
public void testBinToHex2() { doTest(); }
@Override
protected String getIntentionName() {
return IntentionPowerPackBundle.message("convert.integer.to.hex.intention.name");
}
@Override
protected String getRelativePath() {
return "integer";
}
}
@@ -0,0 +1,38 @@
/*
* 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.siyeh.ipp.integer;
import com.siyeh.IntentionPowerPackBundle;
import com.siyeh.ipp.IPPTestCase;
public class ConvertIntegerToOctalTest extends IPPTestCase {
public void testDecToOct1() { doTest(); }
public void testDecToOct2() { doTest(); }
public void testHexToOct1() { doTest(); }
public void testHexToOct2() { doTest(); }
public void testBinToOct1() { doTest(); }
public void testBinToOct2() { doTest(); }
@Override
protected String getIntentionName() {
return IntentionPowerPackBundle.message("convert.integer.to.octal.intention.name");
}
@Override
protected String getRelativePath() {
return "integer";
}
}