Search in sources :

Example 6 with RefactoringStatus

use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.

the class RenameVirtualMethodProcessor method checkInitialConditions.

//------------ preconditions -------------
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor monitor) throws CoreException {
    RefactoringStatus result = super.checkInitialConditions(monitor);
    if (result.hasFatalError())
        return result;
    try {
        //$NON-NLS-1$
        monitor.beginTask("", 3);
        if (!fActivationChecked) {
            // the following code may change the method to be changed.
            IMethod method = getMethod();
            fOriginalMethod = method;
            ITypeHierarchy hierarchy = null;
            IType declaringType = method.getDeclaringType();
            if (!declaringType.isInterface())
                hierarchy = getCachedHierarchy(declaringType, new SubProgressMonitor(monitor, 1));
            IMethod topmost = getMethod();
            if (MethodChecks.isVirtual(topmost))
                topmost = MethodChecks.getTopmostMethod(getMethod(), hierarchy, monitor);
            if (topmost != null)
                initialize(topmost);
            fActivationChecked = true;
        }
    } finally {
        monitor.done();
    }
    return result;
}
Also used : ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IMethod(org.eclipse.jdt.core.IMethod) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IType(org.eclipse.jdt.core.IType)

Example 7 with RefactoringStatus

use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.

the class RenameVirtualMethodProcessor method doCheckFinalConditions.

@Override
protected RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext checkContext) throws CoreException {
    try {
        //$NON-NLS-1$
        pm.beginTask("", 9);
        RefactoringStatus result = new RefactoringStatus();
        result.merge(super.doCheckFinalConditions(new SubProgressMonitor(pm, 7), checkContext));
        if (result.hasFatalError())
            return result;
        final IMethod method = getMethod();
        final IType declaring = method.getDeclaringType();
        final ITypeHierarchy hierarchy = getCachedHierarchy(declaring, new SubProgressMonitor(pm, 1));
        final String name = getNewElementName();
        if (declaring.isInterface()) {
            if (isSpecialCase())
                result.addError(RefactoringCoreMessages.RenameMethodInInterfaceRefactoring_special_case);
            pm.worked(1);
            IMethod[] relatedMethods = relatedTypeDeclaresMethodName(new SubProgressMonitor(pm, 1), method, name);
            for (int i = 0; i < relatedMethods.length; i++) {
                IMethod relatedMethod = relatedMethods[i];
                RefactoringStatusContext context = JavaStatusContext.create(relatedMethod);
                result.addError(RefactoringCoreMessages.RenameMethodInInterfaceRefactoring_already_defined, context);
            }
        } else {
            if (classesDeclareOverridingNativeMethod(hierarchy.getAllSubtypes(declaring))) {
                result.addError(Messages.format(RefactoringCoreMessages.RenameVirtualMethodRefactoring_requieres_renaming_native, //$NON-NLS-1$
                new String[] { BasicElementLabels.getJavaElementName(method.getElementName()), "UnsatisfiedLinkError" }));
            }
            IMethod[] hierarchyMethods = hierarchyDeclaresMethodName(new SubProgressMonitor(pm, 1), hierarchy, method, name);
            for (int i = 0; i < hierarchyMethods.length; i++) {
                IMethod hierarchyMethod = hierarchyMethods[i];
                RefactoringStatusContext context = JavaStatusContext.create(hierarchyMethod);
                if (Checks.compareParamTypes(method.getParameterTypes(), hierarchyMethod.getParameterTypes())) {
                    result.addError(Messages.format(RefactoringCoreMessages.RenameVirtualMethodRefactoring_hierarchy_declares2, BasicElementLabels.getJavaElementName(name)), context);
                } else {
                    result.addWarning(Messages.format(RefactoringCoreMessages.RenameVirtualMethodRefactoring_hierarchy_declares1, BasicElementLabels.getJavaElementName(name)), context);
                }
            }
        }
        fCachedHierarchy = null;
        return result;
    } finally {
        pm.done();
    }
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IMethod(org.eclipse.jdt.core.IMethod) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IType(org.eclipse.jdt.core.IType)

Example 8 with RefactoringStatus

use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.

the class RenameTypeProcessor method doCheckFinalConditions.

@Override
protected RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException {
    //$NON-NLS-1$
    Assert.isNotNull(fType, "type");
    //$NON-NLS-1$
    Assert.isNotNull(getNewElementName(), "newName");
    RefactoringStatus result = new RefactoringStatus();
    int referenceSearchTicks = fUpdateReferences || fUpdateSimilarElements ? 15 : 0;
    int affectedCusTicks = fUpdateReferences || fUpdateSimilarElements ? 10 : 1;
    int similarElementTicks = fUpdateSimilarElements ? 85 : 0;
    int createChangeTicks = 5;
    int qualifiedNamesTicks = fUpdateQualifiedNames ? 50 : 0;
    try {
        //$NON-NLS-1$
        pm.beginTask("", 12 + referenceSearchTicks + affectedCusTicks + similarElementTicks + createChangeTicks + qualifiedNamesTicks);
        pm.setTaskName(RefactoringCoreMessages.RenameTypeRefactoring_checking);
        fChangeManager = new TextChangeManager(true);
        result.merge(checkNewElementName(getNewElementName()));
        if (result.hasFatalError())
            return result;
        result.merge(Checks.checkIfCuBroken(fType));
        if (result.hasFatalError())
            return result;
        pm.worked(1);
        result.merge(checkTypesInCompilationUnit());
        pm.worked(1);
        result.merge(checkForMethodsWithConstructorNames());
        pm.worked(1);
        result.merge(checkImportedTypes());
        pm.worked(1);
        if (Checks.isTopLevel(fType)) {
            ICompilationUnit cu = fType.getCompilationUnit();
            String newCUName = JavaModelUtil.getRenamedCUName(cu, getNewElementName());
            if (!newCUName.equals(cu.getElementName()))
                result.merge(Checks.checkCompilationUnitNewName(cu, getNewElementName()));
        }
        pm.worked(1);
        if (isPrimaryType())
            result.merge(checkNewPathValidity());
        pm.worked(1);
        result.merge(checkEnclosingTypes());
        pm.worked(1);
        result.merge(checkEnclosedTypes());
        pm.worked(1);
        result.merge(checkTypesInPackage());
        pm.worked(1);
        result.merge(checkTypesImportedInCu());
        pm.worked(1);
        result.merge(Checks.checkForMainAndNativeMethods(fType));
        pm.worked(1);
        // before doing any expensive analysis
        if (result.hasFatalError())
            return result;
        result.merge(analyseEnclosedTypes());
        pm.worked(1);
        // before doing _the really_ expensive analysis
        if (result.hasFatalError())
            return result;
        // Load references, including similarly named elements
        if (fUpdateReferences || fUpdateSimilarElements) {
            pm.setTaskName(RefactoringCoreMessages.RenameTypeRefactoring_searching);
            result.merge(initializeReferences(new SubProgressMonitor(pm, referenceSearchTicks)));
        } else {
            fReferences = new SearchResultGroup[0];
        }
        pm.setTaskName(RefactoringCoreMessages.RenameTypeRefactoring_checking);
        if (pm.isCanceled())
            throw new OperationCanceledException();
        if (fUpdateReferences || fUpdateSimilarElements) {
            result.merge(analyzeAffectedCompilationUnits(new SubProgressMonitor(pm, affectedCusTicks)));
        } else {
            Checks.checkCompileErrorsInAffectedFile(result, fType.getResource());
            pm.worked(affectedCusTicks);
        }
        if (result.hasFatalError())
            return result;
        if (fUpdateSimilarElements) {
            result.merge(initializeSimilarElementsRenameProcessors(new SubProgressMonitor(pm, similarElementTicks), context));
            if (result.hasFatalError())
                return result;
        }
        createChanges(new SubProgressMonitor(pm, createChangeTicks));
        if (fUpdateQualifiedNames)
            computeQualifiedNameMatches(new SubProgressMonitor(pm, qualifiedNamesTicks));
        return result;
    } finally {
        pm.done();
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) TextChangeManager(org.eclipse.jdt.internal.corext.refactoring.util.TextChangeManager)

Example 9 with RefactoringStatus

use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.

the class RenameTypeProcessor method analyzeAffectedCompilationUnits.

/*
	 * Analyzes all compilation units in which type is referenced
	 */
private RefactoringStatus analyzeAffectedCompilationUnits(IProgressMonitor pm) throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    result.merge(Checks.checkCompileErrorsInAffectedFiles(fReferences, fType.getResource()));
    //$NON-NLS-1$
    pm.beginTask("", fReferences.length);
    result.merge(checkConflictingTypes(pm));
    return result;
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Example 10 with RefactoringStatus

use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.

the class RenameTypeProcessor method checkImportedTypes.

private RefactoringStatus checkImportedTypes() throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    IImportDeclaration[] imports = fType.getCompilationUnit().getImports();
    for (int i = 0; i < imports.length; i++) analyzeImportDeclaration(imports[i], result);
    return result;
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IImportDeclaration(org.eclipse.jdt.core.IImportDeclaration)

Aggregations

RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)235 IType (org.eclipse.jdt.core.IType)62 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)53 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)30 IMethod (org.eclipse.jdt.core.IMethod)29 IJavaElement (org.eclipse.jdt.core.IJavaElement)28 Test (org.junit.Test)26 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)24 ArrayList (java.util.ArrayList)22 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)22 BaseTest (org.eclipse.che.plugin.java.server.che.BaseTest)21 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)19 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)18 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)16 ASTNode (org.eclipse.jdt.core.dom.ASTNode)16 IField (org.eclipse.jdt.core.IField)15 IStatus (org.eclipse.core.runtime.IStatus)14 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)13 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)13 IFile (org.eclipse.core.resources.IFile)12