Search in sources :

Example 6 with ExceptionInfo

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

the class ChangeSignatureProcessor method createExceptionInfoList.

private RefactoringStatus createExceptionInfoList() {
    if (fExceptionInfos == null || fExceptionInfos.isEmpty()) {
        fExceptionInfos = new ArrayList<ExceptionInfo>(0);
        try {
            ASTNode nameNode = NodeFinder.perform(fBaseCuRewrite.getRoot(), fMethod.getNameRange());
            if (nameNode == null || !(nameNode instanceof Name) || !(nameNode.getParent() instanceof MethodDeclaration))
                return null;
            MethodDeclaration methodDeclaration = (MethodDeclaration) nameNode.getParent();
            List<Type> exceptions = methodDeclaration.thrownExceptionTypes();
            List<ExceptionInfo> result = new ArrayList<ExceptionInfo>(exceptions.size());
            for (int i = 0; i < exceptions.size(); i++) {
                Type type = exceptions.get(i);
                ITypeBinding typeBinding = type.resolveBinding();
                if (typeBinding == null)
                    return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ChangeSignatureRefactoring_no_exception_binding);
                IJavaElement element = typeBinding.getJavaElement();
                result.add(ExceptionInfo.createInfoForOldException(element, typeBinding));
            }
            fExceptionInfos = result;
        } catch (JavaModelException e) {
            JavaPlugin.log(e);
        }
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) ArrayList(java.util.ArrayList) SimpleName(org.eclipse.jdt.core.dom.SimpleName) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) Name(org.eclipse.jdt.core.dom.Name) IType(org.eclipse.jdt.core.IType) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) Type(org.eclipse.jdt.core.dom.Type) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ASTNode(org.eclipse.jdt.core.dom.ASTNode) ExceptionInfo(org.eclipse.jdt.internal.corext.refactoring.ExceptionInfo)

Example 7 with ExceptionInfo

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

the class ChangeSignatureProcessor method getOldMethodThrows.

private String getOldMethodThrows() {
    //$NON-NLS-1$
    final String throwsString = " throws ";
    StringBuffer buff = new StringBuffer(throwsString);
    for (Iterator<ExceptionInfo> iter = fExceptionInfos.iterator(); iter.hasNext(); ) {
        ExceptionInfo info = iter.next();
        if (!info.isAdded()) {
            buff.append(info.getElement().getElementName());
            //$NON-NLS-1$
            buff.append(", ");
        }
    }
    if (buff.length() == throwsString.length())
        //$NON-NLS-1$
        return "";
    buff.delete(buff.length() - 2, buff.length());
    return buff.toString();
}
Also used : ExceptionInfo(org.eclipse.jdt.internal.corext.refactoring.ExceptionInfo)

Aggregations

ExceptionInfo (org.eclipse.jdt.internal.corext.refactoring.ExceptionInfo)7 JavaModelException (org.eclipse.jdt.core.JavaModelException)4 ParameterInfo (org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)4 ArrayList (java.util.ArrayList)3 IJavaElement (org.eclipse.jdt.core.IJavaElement)2 JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 StringTokenizer (java.util.StringTokenizer)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IType (org.eclipse.jdt.core.IType)1 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)1 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)1 MethodRefParameter (org.eclipse.jdt.core.dom.MethodRefParameter)1 Name (org.eclipse.jdt.core.dom.Name)1 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)1 QualifiedName (org.eclipse.jdt.core.dom.QualifiedName)1 SimpleName (org.eclipse.jdt.core.dom.SimpleName)1 Type (org.eclipse.jdt.core.dom.Type)1