mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-16027 implemented
This commit is contained in:
+43
-23
@@ -555,38 +555,58 @@ public class CreateFromUsageUtils {
|
||||
return result.toArray(new PsiVariable[result.size()]);
|
||||
}
|
||||
|
||||
private static void getExpectedInformation (PsiExpression expression, List<ExpectedTypeInfo[]> types,
|
||||
List<String> expectedMethodNames,
|
||||
List<String> expectedFieldNames) {
|
||||
PsiExpression[] expressions = collectExpressions(expression, PsiMember.class, PsiFile.class);
|
||||
|
||||
for (PsiExpression expr : expressions) {
|
||||
private static void getExpectedInformation(PsiExpression expression,
|
||||
List<ExpectedTypeInfo[]> types,
|
||||
List<String> expectedMethodNames,
|
||||
List<String> expectedFieldNames) {
|
||||
for (PsiExpression expr : collectExpressions(expression, PsiMember.class, PsiFile.class)) {
|
||||
PsiElement parent = expr.getParent();
|
||||
if (parent instanceof PsiReferenceExpression) {
|
||||
PsiElement pparent = parent.getParent();
|
||||
if (pparent instanceof PsiMethodCallExpression) {
|
||||
String refName = ((PsiReferenceExpression)parent).getReferenceName();
|
||||
if (refName != null) {
|
||||
expectedMethodNames.add(refName);
|
||||
}
|
||||
}
|
||||
else if (pparent instanceof PsiReferenceExpression || pparent instanceof PsiVariable ||
|
||||
pparent instanceof PsiExpression) {
|
||||
String refName = ((PsiReferenceExpression)parent).getReferenceName();
|
||||
if (refName != null) {
|
||||
expectedFieldNames.add(refName);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
if (!(parent instanceof PsiReferenceExpression)) {
|
||||
ExpectedTypeInfo[] someExpectedTypes = ExpectedTypesProvider.getExpectedTypes(expr, false);
|
||||
if (someExpectedTypes.length > 0) {
|
||||
types.add(someExpectedTypes);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
String refName = ((PsiReferenceExpression)parent).getReferenceName();
|
||||
if (refName == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PsiElement pparent = parent.getParent();
|
||||
if (pparent instanceof PsiMethodCallExpression) {
|
||||
expectedMethodNames.add(refName);
|
||||
if (refName.equals("equals")) {
|
||||
ExpectedTypeInfo[] someExpectedTypes = equalsExpectedTypes((PsiMethodCallExpression)pparent);
|
||||
if (someExpectedTypes.length > 0) {
|
||||
types.add(someExpectedTypes);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pparent instanceof PsiReferenceExpression ||
|
||||
pparent instanceof PsiVariable ||
|
||||
pparent instanceof PsiExpression) {
|
||||
expectedFieldNames.add(refName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ExpectedTypeInfo[] equalsExpectedTypes(PsiMethodCallExpression methodCall) {
|
||||
final PsiType[] argumentTypes = methodCall.getArgumentList().getExpressionTypes();
|
||||
if (argumentTypes.length != 1) {
|
||||
return ExpectedTypeInfo.EMPTY_ARRAY;
|
||||
}
|
||||
PsiType type = argumentTypes[0];
|
||||
if (type instanceof PsiPrimitiveType) {
|
||||
type = ((PsiPrimitiveType)type).getBoxedType(methodCall);
|
||||
}
|
||||
return new ExpectedTypeInfo[]{ExpectedTypesProvider.createInfo(type, ExpectedTypeInfo.TYPE_STRICTLY, type, TailType.NONE)};
|
||||
}
|
||||
|
||||
public static ExpectedTypeInfo[] guessExpectedTypes (PsiExpression expression, boolean allowVoidType) {
|
||||
PsiManager manager = expression.getManager();
|
||||
GlobalSearchScope resolveScope = expression.getResolveScope();
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Create Field 'VAR'" "true"
|
||||
class A {
|
||||
private String VAR<caret>;
|
||||
|
||||
public IDEA16027() {
|
||||
VAR.equals("");
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Create Field 'VAR'" "true"
|
||||
class A {
|
||||
private Integer VAR<caret>;
|
||||
|
||||
public IDEA16027() {
|
||||
VAR.equals(5);
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// "Create Field 'VAR'" "true"
|
||||
class A {
|
||||
public IDEA16027() {
|
||||
V<caret>AR.equals("");
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// "Create Field 'VAR'" "true"
|
||||
class A {
|
||||
public IDEA16027() {
|
||||
V<caret>AR.equals(5);
|
||||
}
|
||||
}
|
||||
+2
@@ -19,6 +19,8 @@ public class CreateFieldFromUsageTest extends LightQuickFixTestCase{
|
||||
public void testQualifyInner() throws Exception { doSingleTest(); }
|
||||
public void testTypeArgsFormatted() throws Exception { doSingleTest(); }
|
||||
public void testInsideStaticInnerClass() throws Exception { doSingleTest(); }
|
||||
public void testCreateFromEquals() throws Exception { doSingleTest(); }
|
||||
public void testCreateFromEqualsToPrimitiveType() throws Exception { doSingleTest(); }
|
||||
|
||||
public void testSortByRelevance() throws Exception {
|
||||
new WriteCommandAction(getProject()) {
|
||||
|
||||
Reference in New Issue
Block a user