mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java: no annotations needed in type cast
This commit is contained in:
+5
-6
@@ -81,14 +81,14 @@ public class AddTypeCastFix extends LocalQuickFixAndIntentionActionOnPsiElement
|
||||
originalExpression.replace(typeCast);
|
||||
}
|
||||
|
||||
static PsiExpression createCastExpression(PsiExpression originalExpression, Project project, PsiType type) {
|
||||
static PsiExpression createCastExpression(PsiExpression original, Project project, PsiType type) {
|
||||
// remove nested casts
|
||||
PsiElement expression = PsiUtil.deparenthesizeExpression(originalExpression);
|
||||
PsiElement expression = PsiUtil.deparenthesizeExpression(original);
|
||||
if (expression == null) return null;
|
||||
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(originalExpression.getProject()).getElementFactory();
|
||||
PsiTypeCastExpression typeCast = (PsiTypeCastExpression)factory.createExpressionFromText("(Type)value", null);
|
||||
assertNotNull(typeCast.getCastType()).replace(factory.createTypeElement(type));
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(original.getProject()).getElementFactory();
|
||||
String text = "(" + type.getCanonicalText(false) + ")value";
|
||||
PsiTypeCastExpression typeCast = (PsiTypeCastExpression)factory.createExpressionFromText(text, original);
|
||||
typeCast = (PsiTypeCastExpression)CodeStyleManager.getInstance(project).reformat(typeCast);
|
||||
|
||||
if (expression instanceof PsiConditionalExpression) {
|
||||
@@ -124,5 +124,4 @@ public class AddTypeCastFix extends LocalQuickFixAndIntentionActionOnPsiElement
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,6 +7,6 @@ import static java.lang.annotation.ElementType.*;
|
||||
class C {
|
||||
{
|
||||
Object o = null;
|
||||
@TA int @TA [] a = (@TA int @TA[]) o;
|
||||
@TA int @TA [] a = (int[]) o;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
// "Cast to 'java.lang.Integer'" "true"
|
||||
// "Cast to 'java.util.List<java.lang.Integer>'" "true"
|
||||
import java.lang.annotation.*;
|
||||
import java.util.*;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
|
||||
@Target({TYPE_USE}) @interface TA { }
|
||||
@@ -7,6 +8,6 @@ import static java.lang.annotation.ElementType.*;
|
||||
class C {
|
||||
{
|
||||
Object o = null;
|
||||
@TA <caret>Integer i = (@TA Integer) o;
|
||||
@TA List<@TA Integer> i = (List<Integer>) o;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
// "Cast to 'java.lang.Integer'" "true"
|
||||
// "Cast to 'java.util.List<java.lang.Integer>'" "true"
|
||||
import java.lang.annotation.*;
|
||||
import java.util.*;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
|
||||
@Target({TYPE_USE}) @interface TA { }
|
||||
@@ -7,6 +8,6 @@ import static java.lang.annotation.ElementType.*;
|
||||
class C {
|
||||
{
|
||||
Object o = null;
|
||||
@TA <caret>Integer i = o;
|
||||
@TA <caret>List<@TA Integer> i = o;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user