mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-67218 enum default constructors don't support maps
This commit is contained in:
@@ -353,4 +353,5 @@ no.super.method.found=No super methods found
|
||||
wrong.package.name=Package name ''{0}'' does not corresponding to the file path ''{1}''
|
||||
cannot.assign.string.to.enum.0=Cannot assign string to enum ''{0}''
|
||||
cannot.find.enum.constant.0.in.enum.1=Cannot find enum constant ''{0}'' in enum ''{1}''
|
||||
recursive.constructor.invocation=Recursive constructor invocation
|
||||
recursive.constructor.invocation=Recursive constructor invocation
|
||||
the.usage.of.a.map.entry.expression.to.initialize.an.enum.is.currently.not.supported=The usage of a map entry expression to initialize an Enum is currently not supported
|
||||
@@ -87,6 +87,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement;
|
||||
@@ -389,6 +390,22 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator {
|
||||
checkRecursiveConstructors(holder, constructors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnumConstant(GrEnumConstant enumConstant) {
|
||||
super.visitEnumConstant(enumConstant);
|
||||
final GrArgumentList argumentList = enumConstant.getArgumentList();
|
||||
|
||||
if (argumentList!=null && argumentList.getNamedArguments().length > 0 && argumentList.getExpressionArguments().length == 0) {
|
||||
final PsiMethod constructor = enumConstant.resolveConstructor();
|
||||
if (constructor != null) {
|
||||
if (!PsiUtil.isConstructorHasRequiredParameters(constructor)) {
|
||||
myHolder.createErrorAnnotation(argumentList, GroovyBundle.message("the.usage.of.a.map.entry.expression.to.initialize.an.enum.is.currently.not.supported"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkRecursiveConstructors(AnnotationHolder holder, PsiMethod[] constructors) {
|
||||
Map<PsiMethod, PsiMethod> nodes = new HashMap<PsiMethod, PsiMethod>(constructors.length);
|
||||
|
||||
|
||||
+7
-4
@@ -45,10 +45,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrBuilderMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.*;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrClosureType;
|
||||
@@ -333,6 +330,12 @@ public class GroovyAssignabilityCheckInspection extends BaseInspection {
|
||||
checkMethodCall(applicationStatement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnumConstant(GrEnumConstant enumConstant) {
|
||||
super.visitEnumConstant(enumConstant);
|
||||
checkConstructorCall(enumConstant, enumConstant);
|
||||
}
|
||||
|
||||
private void checkNamedArgumentsType(GrCall call) {
|
||||
GrNamedArgument[] namedArguments = PsiUtil.getFirstMapNamedArguments(call);
|
||||
|
||||
|
||||
@@ -200,7 +200,8 @@ public class PsiUtil {
|
||||
}
|
||||
@Nullable
|
||||
public static PsiType[] getArgumentTypes(PsiElement place, boolean nullAsBottom, @Nullable GrExpression stopAt) {
|
||||
PsiElement parent = place.getParent();
|
||||
PsiElement parent = place instanceof GrEnumConstant ? place : place.getParent();
|
||||
|
||||
if (parent instanceof GrCall) {
|
||||
GrCall call = (GrCall)parent;
|
||||
GrNamedArgument[] namedArgs = call.getNamedArguments();
|
||||
|
||||
@@ -460,4 +460,8 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testRecursiveConstructors() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testEnumConstantConstructors() {
|
||||
doTest(new GroovyAssignabilityCheckInspection());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
enum E {
|
||||
a,
|
||||
b(),
|
||||
c<error descr="The usage of a map entry expression to initialize an Enum is currently not supported">(a:2)</error>,
|
||||
d(1),
|
||||
e<warning descr="'E' in 'E' cannot be applied to '(java.lang.Integer, java.lang.Integer)'">(1, 2)</warning>,
|
||||
f<warning descr="'E' in 'E' cannot be applied to '(java.lang.Integer, java.lang.Integer)'">(1, 2)</warning>{}
|
||||
|
||||
def E(int x){}
|
||||
def E(){}
|
||||
}
|
||||
Reference in New Issue
Block a user