use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation in project intellij-community by JetBrains.
the class GrIntroduceFieldDialog method isAlwaysInvokedConstructor.
private static boolean isAlwaysInvokedConstructor(@Nullable PsiMethod method, @NotNull PsiClass clazz) {
if (method == null)
return false;
if (!method.isConstructor())
return false;
final PsiMethod[] constructors = clazz.getConstructors();
if (constructors.length == 1)
return true;
final GrConstructorInvocation invocation = PsiImplUtil.getChainingConstructorInvocation((GrMethod) method);
if (invocation != null && invocation.isThisCall())
return false;
for (PsiMethod constructor : constructors) {
if (constructor == method)
continue;
final GrConstructorInvocation inv = PsiImplUtil.getChainingConstructorInvocation((GrMethod) constructor);
if (inv == null || inv.isSuperCall())
return false;
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation in project intellij-community by JetBrains.
the class StubGenerator method resolveChainingConstructor.
@Nullable
private static GroovyResolveResult resolveChainingConstructor(GrMethod constructor) {
LOG.assertTrue(constructor.isConstructor());
final GrConstructorInvocation constructorInvocation = PsiImplUtil.getChainingConstructorInvocation(constructor);
if (constructorInvocation == null) {
return null;
}
GroovyResolveResult resolveResult = constructorInvocation.advancedResolve();
if (resolveResult.getElement() != null) {
return resolveResult;
}
final GroovyResolveResult[] results = constructorInvocation.multiResolve(false);
if (results.length > 0) {
int i = 0;
while (results.length > i + 1) {
final PsiMethod candidate = (PsiMethod) results[i].getElement();
final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(constructor.getProject()).getResolveHelper();
if (candidate != null && candidate != constructor && resolveHelper.isAccessible(candidate, constructorInvocation, null)) {
break;
}
i++;
}
return results[i];
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation in project intellij-community by JetBrains.
the class GrSuperReferenceResolver method resolveSuperExpression.
@Nullable("null if ref is not 'super' reference")
public static GroovyResolveResult[] resolveSuperExpression(@NotNull GrReferenceExpression ref) {
GrExpression qualifier = ref.getQualifier();
if (qualifier == null) {
final PsiElement parent = ref.getParent();
if (parent instanceof GrConstructorInvocation) {
return ((GrConstructorInvocation) parent).multiResolve(false);
}
PsiClass aClass = PsiUtil.getContextClass(ref);
if (aClass != null) {
return getSuperClass(aClass);
}
} else if (qualifier instanceof GrReferenceExpression) {
GroovyResolveResult result = ((GrReferenceExpression) qualifier).advancedResolve();
PsiElement resolved = result.getElement();
if (resolved instanceof PsiClass) {
PsiClass superClass = (PsiClass) resolved;
GrTypeDefinition scopeClass = PsiTreeUtil.getParentOfType(ref, GrTypeDefinition.class, true);
if (scopeClass != null && GrTraitUtil.isTrait(superClass) && scopeClass.isInheritor(superClass, false)) {
PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, scopeClass, PsiSubstitutor.EMPTY);
return new GroovyResolveResultImpl[] { new GroovyResolveResultImpl(superClass, null, null, superClassSubstitutor, true, true) };
}
if (PsiUtil.hasEnclosingInstanceInScope(superClass, ref, false)) {
return getSuperClass(superClass);
}
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation in project intellij-community by JetBrains.
the class PsiImplUtil method getChainingConstructorInvocation.
@Nullable
public static GrConstructorInvocation getChainingConstructorInvocation(GrMethod constructor) {
if (constructor instanceof GrReflectedMethod && ((GrReflectedMethod) constructor).getSkippedParameters().length > 0)
return null;
LOG.assertTrue(constructor.isConstructor());
GrOpenBlock body = constructor.getBlock();
if (body == null)
return null;
GrStatement[] statements = body.getStatements();
if (statements.length > 0 && statements[0] instanceof GrConstructorInvocation) {
return (GrConstructorInvocation) statements[0];
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation in project intellij-community by JetBrains.
the class GrCreateFieldForParameterIntention method getAnchor.
@Nullable
private static GrStatement getAnchor(GrOpenBlock block) {
GrStatement[] statements = block.getStatements();
GrStatement fist = ArrayUtil.getFirstElement(statements);
if (fist instanceof GrConstructorInvocation) {
return statements.length > 1 ? statements[1] : null;
} else {
return fist;
}
}
Aggregations