Search in sources :

Example 1 with JavaParameterInfo

use of com.intellij.refactoring.changeSignature.JavaParameterInfo 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);
    }
}
Also used : CanonicalTypes(com.intellij.refactoring.util.CanonicalTypes) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) IncorrectOperationException(com.intellij.util.IncorrectOperationException) JavaParameterInfo(com.intellij.refactoring.changeSignature.JavaParameterInfo)

Aggregations

JavaParameterInfo (com.intellij.refactoring.changeSignature.JavaParameterInfo)1 CanonicalTypes (com.intellij.refactoring.util.CanonicalTypes)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)1 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)1 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)1 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)1