Search in sources :

Example 21 with ParameterInfo

use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project che by eclipse.

the class ChangeSignatureProcessor method checkParameterNamesAndValues.

private void checkParameterNamesAndValues(RefactoringStatus result) {
    int i = 1;
    for (Iterator<ParameterInfo> iter = fParameterInfos.iterator(); iter.hasNext(); i++) {
        ParameterInfo info = iter.next();
        if (info.isDeleted())
            continue;
        checkParameterName(result, info, i);
        if (result.hasFatalError())
            return;
        if (info.isAdded()) {
            checkParameterDefaultValue(result, info);
            if (result.hasFatalError())
                return;
        }
    }
}
Also used : ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)

Example 22 with ParameterInfo

use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project che by eclipse.

the class ChangeSignatureProcessor method initialize.

private RefactoringStatus initialize(JavaRefactoringArguments arguments) {
    final String handle = arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
    if (handle != null) {
        final IJavaElement element = JavaRefactoringDescriptorUtil.handleToElement(arguments.getProject(), handle, false);
        if (element == null || !element.exists() || element.getElementType() != IJavaElement.METHOD)
            return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getProcessorName(), IJavaRefactorings.CHANGE_METHOD_SIGNATURE);
        else {
            fMethod = (IMethod) element;
            fMethodName = fMethod.getElementName();
            try {
                fVisibility = JdtFlags.getVisibilityCode(fMethod);
                fReturnTypeInfo = new ReturnTypeInfo(Signature.toString(Signature.getReturnType(fMethod.getSignature())));
            } catch (JavaModelException exception) {
                return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { new Integer(fVisibility), ATTRIBUTE_VISIBILITY }));
            }
        }
    } else
        return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT));
    final String name = arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME);
    if (name != null) {
        fMethodName = name;
        final RefactoringStatus status = Checks.checkMethodName(fMethodName, fMethod);
        if (status.hasError())
            return status;
    } else
        return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME));
    final String type = arguments.getAttribute(ATTRIBUTE_RETURN);
    if (//$NON-NLS-1$
    type != null && !"".equals(type))
        fReturnTypeInfo.setNewTypeName(type);
    final String visibility = arguments.getAttribute(ATTRIBUTE_VISIBILITY);
    if (visibility != null && !"".equals(visibility)) {
        //$NON-NLS-1$
        int flag = 0;
        try {
            flag = Integer.parseInt(visibility);
        } catch (NumberFormatException exception) {
            return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_VISIBILITY));
        }
        fVisibility = flag;
    }
    int count = 1;
    String attribute = ATTRIBUTE_PARAMETER + count;
    String value = null;
    fParameterInfos = new ArrayList<ParameterInfo>(3);
    while ((value = arguments.getAttribute(attribute)) != null) {
        //$NON-NLS-1$
        StringTokenizer tokenizer = new StringTokenizer(value, " ");
        if (tokenizer.countTokens() < 6)
            return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { value, ATTRIBUTE_PARAMETER }));
        String oldTypeName = tokenizer.nextToken();
        String oldName = tokenizer.nextToken();
        String oldIndex = tokenizer.nextToken();
        String newTypeName = tokenizer.nextToken();
        String newName = tokenizer.nextToken();
        String deleted = tokenizer.nextToken();
        ParameterInfo info = null;
        try {
            int index = Integer.parseInt(oldIndex);
            if (index == -1) {
                String result = arguments.getAttribute(ATTRIBUTE_DEFAULT + count);
                if (result == null)
                    //$NON-NLS-1$
                    result = "";
                info = ParameterInfo.createInfoForAddedParameter(newTypeName, newName, result);
            } else {
                info = new ParameterInfo(oldTypeName, oldName, index);
                info.setNewTypeName(newTypeName);
                info.setNewName(newName);
                if (Boolean.valueOf(deleted).booleanValue())
                    info.markAsDeleted();
            }
            fParameterInfos.add(info);
        } catch (NumberFormatException exception) {
            return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { value, ATTRIBUTE_PARAMETER }));
        }
        count++;
        attribute = ATTRIBUTE_PARAMETER + count;
    }
    count = 1;
    fExceptionInfos = new ArrayList<ExceptionInfo>(2);
    attribute = JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + count;
    while ((value = arguments.getAttribute(attribute)) != null) {
        ExceptionInfo info = null;
        final String kind = arguments.getAttribute(ATTRIBUTE_KIND + count);
        if (kind != null) {
            final IJavaElement element = JavaRefactoringDescriptorUtil.handleToElement(arguments.getProject(), value, false);
            if (element == null || !element.exists())
                return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getProcessorName(), IJavaRefactorings.CHANGE_METHOD_SIGNATURE);
            else {
                try {
                    info = new ExceptionInfo(element, Integer.valueOf(kind).intValue(), null);
                } catch (NumberFormatException exception) {
                    return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { kind, ATTRIBUTE_KIND }));
                }
            }
        } else
            return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { kind, ATTRIBUTE_KIND }));
        fExceptionInfos.add(info);
        count++;
        attribute = JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + count;
    }
    final String deprecate = arguments.getAttribute(ATTRIBUTE_DEPRECATE);
    if (deprecate != null) {
        fDelegateDeprecation = Boolean.valueOf(deprecate).booleanValue();
    } else
        return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_DEPRECATE));
    final String delegate = arguments.getAttribute(ATTRIBUTE_DELEGATE);
    if (delegate != null) {
        fDelegateUpdating = Boolean.valueOf(delegate).booleanValue();
    } else
        return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_DELEGATE));
    return new RefactoringStatus();
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo) StringTokenizer(java.util.StringTokenizer) ReturnTypeInfo(org.eclipse.jdt.internal.corext.refactoring.ReturnTypeInfo) ExceptionInfo(org.eclipse.jdt.internal.corext.refactoring.ExceptionInfo)

Example 23 with ParameterInfo

use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project che by eclipse.

the class ChangeSignatureProcessor method checkVarargs.

private RefactoringStatus checkVarargs() throws JavaModelException {
    RefactoringStatus result = checkOriginalVarargs();
    if (result != null)
        return result;
    if (fRippleMethods != null) {
        for (int iRipple = 0; iRipple < fRippleMethods.length; iRipple++) {
            IMethod rippleMethod = fRippleMethods[iRipple];
            if (!JdtFlags.isVarargs(rippleMethod))
                continue;
            // Vararg method can override method that takes an array as last argument
            fOldVarargIndex = rippleMethod.getNumberOfParameters() - 1;
            List<ParameterInfo> notDeletedInfos = getNotDeletedInfos();
            for (int i = 0; i < notDeletedInfos.size(); i++) {
                ParameterInfo info = notDeletedInfos.get(i);
                if (fOldVarargIndex != -1 && info.getOldIndex() == fOldVarargIndex && !info.isNewVarargs()) {
                    String rippleMethodType = rippleMethod.getDeclaringType().getFullyQualifiedName('.');
                    String message = Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_ripple_cannot_convert_vararg, new Object[] { BasicElementLabels.getJavaElementName(info.getNewName()), BasicElementLabels.getJavaElementName(rippleMethodType) });
                    return RefactoringStatus.createFatalErrorStatus(message, JavaStatusContext.create(rippleMethod));
                }
            }
        }
    }
    return null;
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IMethod(org.eclipse.jdt.core.IMethod) ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)

Example 24 with ParameterInfo

use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project che by eclipse.

the class ChangeSignatureProcessor method getMethodParameters.

private String getMethodParameters() {
    StringBuffer buff = new StringBuffer();
    int i = 0;
    for (Iterator<ParameterInfo> iter = getNotDeletedInfos().iterator(); iter.hasNext(); i++) {
        ParameterInfo info = iter.next();
        if (i != 0)
            //$NON-NLS-1$
            buff.append(", ");
        buff.append(createDeclarationString(info));
    }
    return buff.toString();
}
Also used : ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)

Example 25 with ParameterInfo

use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project che by eclipse.

the class ChangeSignatureProcessor method addArgumentsToNewSuperConstructorCall.

private void addArgumentsToNewSuperConstructorCall(SuperConstructorInvocation superCall, CompilationUnitRewrite cuRewrite) {
    Iterator<ParameterInfo> iter = getNotDeletedInfos().iterator();
    while (iter.hasNext()) {
        ParameterInfo info = iter.next();
        Expression newExpression = createNewExpression(info, getParameterInfos(), superCall.arguments(), cuRewrite, (MethodDeclaration) ASTNodes.getParent(superCall, MethodDeclaration.class));
        if (newExpression != null)
            superCall.arguments().add(newExpression);
    }
}
Also used : Expression(org.eclipse.jdt.core.dom.Expression) LambdaExpression(org.eclipse.jdt.core.dom.LambdaExpression) ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)

Aggregations

ParameterInfo (org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)30 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)6 ArrayList (java.util.ArrayList)5 JavaModelException (org.eclipse.jdt.core.JavaModelException)4 ASTNode (org.eclipse.jdt.core.dom.ASTNode)4 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)4 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)4 ExceptionInfo (org.eclipse.jdt.internal.corext.refactoring.ExceptionInfo)4 RichString (org.eclipse.xtend.core.xtend.RichString)4 HashSet (java.util.HashSet)3 ExtractMethodRefactoring (org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)3 Test (org.junit.Test)3 Expression (org.eclipse.jdt.core.dom.Expression)2 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)2 ReturnStatement (org.eclipse.jdt.core.dom.ReturnStatement)2 SimpleName (org.eclipse.jdt.core.dom.SimpleName)2 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)2 VariableDeclaration (org.eclipse.jdt.core.dom.VariableDeclaration)2