diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/PsiImplUtil.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/PsiImplUtil.java index 46f3230e3e18..9b47c654a40d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/PsiImplUtil.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/PsiImplUtil.java @@ -65,6 +65,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; 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.GrReflectedMethod; +import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.arithmetic.GrAdditiveExpressionImpl; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.arithmetic.GrMultiplicativeExpressionImpl; @@ -441,8 +442,27 @@ public class PsiImplUtil { } public static boolean isMainMethod(GrMethod method) { - return method.getName().equals(MAIN_METHOD) && - method.hasModifierProperty(PsiModifier.STATIC); + if (!method.getName().equals(MAIN_METHOD)) return false; + else if (!method.hasModifierProperty(PsiModifier.STATIC))return false; + + final GrParameter[] parameters = method.getParameters(); + + if (parameters.length == 0) return false; + if (parameters.length == 1 && parameters[0].getTypeElementGroovy() == null) return true; + + int args_count = 0; + int optional_count = 0; + + for (GrParameter p : parameters) { + final GrTypeElement declaredType = p.getTypeElementGroovy(); + if ((declaredType == null || declaredType.getType().equalsToText(CommonClassNames.JAVA_LANG_STRING + "[]")) && + p.getDefaultInitializer() == null) { + args_count++; + } + if (p.getDefaultInitializer() != null) optional_count++; + } + + return optional_count == parameters.length - 1 && args_count == 1; } public static void deleteStatementTail(PsiElement container, @NotNull PsiElement statement) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/params/GrParameterImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/params/GrParameterImpl.java index 4a2139b8b7ad..a3a7c786abd9 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/params/GrParameterImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/params/GrParameterImpl.java @@ -118,7 +118,7 @@ public class GrParameterImpl extends GrVariableBaseImpl impleme public PsiType getType() { PsiType type = super.getType(); if (isMainMethodFirstUntypedParameter()) { - return TypesUtil.createTypeByFQClassName("java.lang.String", this).createArrayType(); + return TypesUtil.createTypeByFQClassName(CommonClassNames.JAVA_LANG_STRING, this).createArrayType(); } if (getParent() instanceof GrForClause) { //inside for loop final PsiType typeGroovy = getTypeGroovy(); @@ -129,18 +129,14 @@ public class GrParameterImpl extends GrVariableBaseImpl impleme private boolean isMainMethodFirstUntypedParameter() { if (getTypeElementGroovy() != null) return false; + if (!(getParent() instanceof GrParameterList)) return false; + if (getDefaultInitializer() != null) return false; - if (getParent() instanceof GrParameterList) { - GrParameterList parameterList = (GrParameterList)getParent(); - GrParameter[] params = parameterList.getParameters(); - if (params.length != 1 || this != params[0]) return false; + GrParameterList parameterList = (GrParameterList)getParent(); + if (!(parameterList.getParent() instanceof GrMethod)) return false; - if (parameterList.getParent() instanceof GrMethod) { - GrMethod method = (GrMethod)parameterList.getParent(); - return PsiImplUtil.isMainMethod(method); - } - } - return false; + GrMethod method = (GrMethod)parameterList.getParent(); + return PsiImplUtil.isMainMethod(method); } public void setType(@Nullable PsiType type) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodBaseImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodBaseImpl.java index acb8be0ae21d..03a0052d57a0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodBaseImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodBaseImpl.java @@ -236,6 +236,10 @@ public abstract class GrMethodBaseImpl extends GrStubElementBase i @Nullable private PsiType getNominalType() { + if (PsiImplUtil.isMainMethod(this)) { + return PsiType.VOID; + } + final GrTypeElement element = getReturnTypeElementGroovy(); if (element != null) { return element.getType();