mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Groovy magic: running of static main(args){}
This commit is contained in:
@@ -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) {
|
||||
|
||||
+7
-11
@@ -118,7 +118,7 @@ public class GrParameterImpl extends GrVariableBaseImpl<GrParameterStub> 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<GrParameterStub> 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) {
|
||||
|
||||
+4
@@ -236,6 +236,10 @@ public abstract class GrMethodBaseImpl extends GrStubElementBase<GrMethodStub> i
|
||||
|
||||
@Nullable
|
||||
private PsiType getNominalType() {
|
||||
if (PsiImplUtil.isMainMethod(this)) {
|
||||
return PsiType.VOID;
|
||||
}
|
||||
|
||||
final GrTypeElement element = getReturnTypeElementGroovy();
|
||||
if (element != null) {
|
||||
return element.getType();
|
||||
|
||||
Reference in New Issue
Block a user