use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GrChangeSignatureUsageProcessor method processClassUsage.
private static void processClassUsage(GrTypeDefinition psiClass, JavaChangeInfo changeInfo) {
String name = psiClass.getName();
GrMethod constructor = GroovyPsiElementFactory.getInstance(psiClass.getProject()).createConstructorFromText(name, ArrayUtil.EMPTY_STRING_ARRAY, ArrayUtil.EMPTY_STRING_ARRAY, "{}", null);
GrModifierList list = constructor.getModifierList();
if (psiClass.hasModifierProperty(PsiModifier.PRIVATE))
list.setModifierProperty(PsiModifier.PRIVATE, true);
if (psiClass.hasModifierProperty(PsiModifier.PROTECTED))
list.setModifierProperty(PsiModifier.PROTECTED, true);
if (!list.hasExplicitVisibilityModifiers()) {
list.setModifierProperty(GrModifier.DEF, true);
}
constructor = (GrMethod) psiClass.add(constructor);
processConstructor(constructor, changeInfo);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GrMethodConflictUtil method checkForClosurePropertySignatureOverload.
private static void checkForClosurePropertySignatureOverload(PsiClass clazz, GrMethod prototype, final GrMethod refactoredMethod, final MultiMap<PsiElement, String> conflicts, final List<MethodSignature> prototypeSignatures) {
final boolean isStatic = prototype.hasModifierProperty(PsiModifier.STATIC);
final String name = prototype.getName();
if (!GroovyPropertyUtils.isProperty(clazz, name, isStatic))
return;
final PsiMethod getter = GroovyPropertyUtils.findPropertyGetter(clazz, name, isStatic, true);
final PsiType returnType;
if (getter instanceof GrMethod) {
returnType = ((GrMethod) getter).getInferredReturnType();
} else if (getter instanceof GrAccessorMethod) {
returnType = ((GrAccessorMethod) getter).getInferredReturnType();
} else {
return;
}
if (!(returnType instanceof GrClosureType))
return;
final GrSignature signature = ((GrClosureType) returnType).getSignature();
signature.accept(new GrRecursiveSignatureVisitor() {
@Override
public void visitClosureSignature(GrClosureSignature signature) {
NextSignature: for (MethodSignature prototypeSignature : prototypeSignatures) {
final GrClosureParameter[] params = signature.getParameters();
final PsiType[] types = prototypeSignature.getParameterTypes();
if (types.length != params.length)
continue;
for (int i = 0; i < types.length; i++) {
if (!TypesUtil.isAssignableByMethodCallConversion(types[i], params[i].getType(), refactoredMethod.getParameterList())) {
continue NextSignature;
}
}
conflicts.putValue(getter, GroovyRefactoringBundle.message("refactored.method.will.cover.closure.property", name, RefactoringUIUtil.getDescription(getter.getContainingClass(), false)));
}
}
});
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GrChangeSignatureConflictSearcher method addMethodConflicts.
private void addMethodConflicts(MultiMap<PsiElement, String> conflicts) {
try {
GrMethod prototype;
final PsiMethod method = myChangeInfo.getMethod();
if (!(method instanceof GrMethod))
return;
PsiManager manager = method.getManager();
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(manager.getProject());
final CanonicalTypes.Type returnType = myChangeInfo.getNewReturnType();
String newMethodName = myChangeInfo.getNewName();
if (method.isConstructor()) {
prototype = factory.createConstructorFromText("foo", ArrayUtil.EMPTY_STRING_ARRAY, ArrayUtil.EMPTY_STRING_ARRAY, "{}", method);
} else {
prototype = factory.createMethodFromText("", "foo", returnType != null ? returnType.getTypeText() : null, ArrayUtil.EMPTY_STRING_ARRAY, method);
}
prototype.setName(newMethodName);
JavaParameterInfo[] parameters = myChangeInfo.getNewParameters();
for (JavaParameterInfo info : parameters) {
GrParameter param;
if (info instanceof GrParameterInfo) {
param = factory.createParameter(info.getName(), info.getTypeText(), ((GrParameterInfo) info).getDefaultInitializer(), (GroovyPsiElement) method);
} else {
param = factory.createParameter(info.getName(), info.getTypeText(), (GroovyPsiElement) method);
}
prototype.getParameterList().add(param);
}
ConflictsUtil.checkMethodConflicts(method.getContainingClass(), method, prototype, conflicts);
GrMethodConflictUtil.checkMethodConflicts(method.getContainingClass(), prototype, ((GrMethod) method), conflicts, true);
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GroovyOverrideImplementUtil method chooseAndOverrideOrImplementMethods.
public static void chooseAndOverrideOrImplementMethods(@NotNull Project project, @NotNull final Editor editor, @NotNull final GrTypeDefinition aClass, boolean toImplement) {
LOG.assertTrue(aClass.isValid());
ApplicationManager.getApplication().assertReadAccessAllowed();
Collection<CandidateInfo> candidates = GroovyOverrideImplementExploreUtil.getMethodsToOverrideImplement(aClass, toImplement);
Collection<CandidateInfo> secondary = toImplement || aClass.isInterface() ? ContainerUtil.<CandidateInfo>newArrayList() : GroovyOverrideImplementExploreUtil.getMethodsToOverrideImplement(aClass, true);
if (toImplement) {
for (Iterator<CandidateInfo> iterator = candidates.iterator(); iterator.hasNext(); ) {
CandidateInfo candidate = iterator.next();
PsiElement element = candidate.getElement();
if (element instanceof GrMethod) {
GrMethod method = (GrMethod) element;
if (GrTraitUtil.isTrait(method.getContainingClass()) && !GrTraitUtil.isMethodAbstract(method)) {
iterator.remove();
secondary.add(candidate);
}
}
}
}
final MemberChooser<PsiMethodMember> chooser = OverrideImplementUtil.showOverrideImplementChooser(editor, aClass, toImplement, candidates, secondary);
if (chooser == null)
return;
final List<PsiMethodMember> selectedElements = chooser.getSelectedElements();
if (selectedElements == null || selectedElements.isEmpty())
return;
LOG.assertTrue(aClass.isValid());
new WriteCommandAction(project, aClass.getContainingFile()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
OverrideImplementUtil.overrideOrImplementMethodsInRightPlace(editor, aClass, selectedElements, chooser.isCopyJavadoc(), chooser.isInsertOverrideAnnotation());
}
}.execute();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod in project intellij-community by JetBrains.
the class GroovyOverrideImplementUtil method setupReturnType.
private static void setupReturnType(GrMethod result, PsiMethod method) {
if (method instanceof GrMethod && ((GrMethod) method).getReturnTypeElementGroovy() == null) {
result.setReturnType(null);
GrModifierList modifierList = result.getModifierList();
if (!modifierList.hasExplicitVisibilityModifiers()) {
modifierList.setModifierProperty(GrModifier.DEF, true);
}
}
}
Aggregations