use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GroovyOverrideImplementUtil method generateTraitMethodPrototype.
public static GrMethod generateTraitMethodPrototype(GrTypeDefinition aClass, GrTraitMethod method, PsiSubstitutor substitutor) {
final Project project = aClass.getProject();
final GrMethod result = (GrMethod) GenerateMembersUtil.substituteGenericMethod(method, substitutor, aClass);
setupModifierList(result);
setupTraitMethodBody(project, result, method);
setupReturnType(result, method);
setupAnnotations(aClass, method, result);
GroovyChangeContextUtil.encodeContextInfo(result);
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GroovyOverrideImplementUtil method generateMethodPrototype.
public static GrMethod generateMethodPrototype(GrTypeDefinition aClass, PsiMethod method, PsiSubstitutor substitutor) {
final Project project = aClass.getProject();
final boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);
String templName = isAbstract ? JavaTemplateUtil.TEMPLATE_IMPLEMENTED_METHOD_BODY : JavaTemplateUtil.TEMPLATE_OVERRIDDEN_METHOD_BODY;
final FileTemplate template = FileTemplateManager.getInstance(method.getProject()).getCodeTemplate(templName);
final GrMethod result = (GrMethod) GenerateMembersUtil.substituteGenericMethod(method, substitutor, aClass);
setupModifierList(result);
setupOverridingMethodBody(project, method, result, template, substitutor);
setupReturnType(result, method);
setupAnnotations(aClass, method, result);
GroovyChangeContextUtil.encodeContextInfo(result);
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GroovyParameterInfoHandler method updateConstructorParams.
private static PsiParameter[] updateConstructorParams(PsiMethod method, PsiParameter[] params, PsiElement place) {
if (GrInnerClassConstructorUtil.isInnerClassConstructorUsedOutsideOfItParent(method, place)) {
GrMethod grMethod = (GrMethod) method;
params = GrInnerClassConstructorUtil.addEnclosingInstanceParam(grMethod, method.getContainingClass().getContainingClass(), grMethod.getParameters(), true);
}
return params;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class CreateParameterFromUsageFix method findScope.
private void findScope(@NotNull final GrReferenceExpression ref, @NotNull final Editor editor, final Project project) {
PsiElement place = ref;
final List<GrMethod> scopes = new ArrayList<>();
while (true) {
final GrMethod parent = PsiTreeUtil.getParentOfType(place, GrMethod.class);
if (parent == null)
break;
scopes.add(parent);
place = parent;
}
if (scopes.size() == 1) {
final GrMethod owner = scopes.get(0);
final PsiMethod toSearchFor;
toSearchFor = SuperMethodWarningUtil.checkSuperMethod(owner, RefactoringBundle.message("to.refactor"));
//if it is null, refactoring was canceled
if (toSearchFor == null)
return;
showDialog(toSearchFor, ref, project);
} else if (scopes.size() > 1) {
myEnclosingMethodsPopup = MethodOrClosureScopeChooser.create(scopes, editor, this, (owner, element) -> {
showDialog((PsiMethod) owner, ref, project);
return null;
});
myEnclosingMethodsPopup.showInBestPositionFor(editor);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class CreateParameterFromUsageFix method showDialog.
private static void showDialog(final PsiMethod method, final GrReferenceExpression ref, final Project project) {
final String name = ref.getReferenceName();
final List<PsiType> types = GroovyExpectedTypesProvider.getDefaultExpectedTypes(ref);
PsiType unboxed = types.isEmpty() ? null : TypesUtil.unboxPrimitiveTypeWrapper(types.get(0));
@NotNull final PsiType type = unboxed != null ? unboxed : PsiType.getJavaLangObject(ref.getManager(), ref.getResolveScope());
if (method instanceof GrMethod) {
GrMethodDescriptor descriptor = new GrMethodDescriptor((GrMethod) method);
GrChangeSignatureDialog dialog = new GrChangeSignatureDialog(project, descriptor, true, ref);
List<GrParameterInfo> parameters = dialog.getParameters();
parameters.add(createParameterInfo(name, type));
dialog.setParameterInfos(parameters);
dialog.show();
} else if (method != null) {
JavaChangeSignatureDialog dialog = new JavaChangeSignatureDialog(project, method, false, ref);
final List<ParameterInfoImpl> parameterInfos = new ArrayList<>(Arrays.asList(ParameterInfoImpl.fromMethod(method)));
ParameterInfoImpl parameterInfo = new ParameterInfoImpl(-1, name, type, PsiTypesUtil.getDefaultValueOfType(type), false);
if (!method.isVarArgs()) {
parameterInfos.add(parameterInfo);
} else {
parameterInfos.add(parameterInfos.size() - 1, parameterInfo);
}
dialog.setParameterInfos(parameterInfos);
dialog.show();
}
}
Aggregations