Search in sources :

Example 16 with RefactoringStatus

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

the class RenameFieldProcessor method checkAccessorDeclarations.

private RefactoringStatus checkAccessorDeclarations(IProgressMonitor pm, IMethod existingAccessor) throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    SearchPattern pattern = SearchPattern.createPattern(existingAccessor, IJavaSearchConstants.DECLARATIONS, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
    IJavaSearchScope scope = SearchEngine.createHierarchyScope(fField.getDeclaringType());
    SearchResultGroup[] groupDeclarations = RefactoringSearchEngine.search(pattern, scope, pm, result);
    Assert.isTrue(groupDeclarations.length > 0);
    if (groupDeclarations.length != 1) {
        String message = Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_overridden, JavaElementUtil.createMethodSignature(existingAccessor));
        result.addError(message);
    } else {
        SearchResultGroup group = groupDeclarations[0];
        Assert.isTrue(group.getSearchResults().length > 0);
        if (group.getSearchResults().length != 1) {
            String message = Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_overridden_or_overrides, JavaElementUtil.createMethodSignature(existingAccessor));
            result.addError(message);
        }
    }
    return result;
}
Also used : IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SearchResultGroup(org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup)

Example 17 with RefactoringStatus

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

the class RenameFieldProcessor method analyzeAffectedCompilationUnits.

/*
	 * (non java-doc)
	 * Analyzes all compilation units in which type is referenced
	 */
private RefactoringStatus analyzeAffectedCompilationUnits() throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    fReferences = Checks.excludeCompilationUnits(fReferences, result);
    if (result.hasFatalError())
        return result;
    result.merge(Checks.checkCompileErrorsInAffectedFiles(fReferences));
    return result;
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Example 18 with RefactoringStatus

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

the class RenameFieldProcessor method checkNestedHierarchy.

private RefactoringStatus checkNestedHierarchy(IType type) throws CoreException {
    IType[] nestedTypes = type.getTypes();
    if (nestedTypes == null)
        return null;
    RefactoringStatus result = new RefactoringStatus();
    for (int i = 0; i < nestedTypes.length; i++) {
        IField otherField = nestedTypes[i].getField(getNewElementName());
        if (otherField.exists()) {
            String msg = Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_hiding, new String[] { BasicElementLabels.getJavaElementName(fField.getElementName()), BasicElementLabels.getJavaElementName(getNewElementName()), BasicElementLabels.getJavaElementName(nestedTypes[i].getFullyQualifiedName('.')) });
            result.addWarning(msg, JavaStatusContext.create(otherField));
        }
        result.merge(checkNestedHierarchy(nestedTypes[i]));
    }
    return result;
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IField(org.eclipse.jdt.core.IField) IType(org.eclipse.jdt.core.IType)

Example 19 with RefactoringStatus

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

the class RenameFieldProcessor method checkAccessor.

//----------
private RefactoringStatus checkAccessor(IProgressMonitor pm, IMethod existingAccessor, String newAccessorName) throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    result.merge(checkAccessorDeclarations(pm, existingAccessor));
    result.merge(checkNewAccessor(existingAccessor, newAccessorName));
    return result;
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Example 20 with RefactoringStatus

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

the class RenameFieldProcessor method doCheckFinalConditions.

@Override
protected RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException {
    try {
        //$NON-NLS-1$
        pm.beginTask("", 18);
        pm.setTaskName(RefactoringCoreMessages.RenameFieldRefactoring_checking);
        RefactoringStatus result = new RefactoringStatus();
        result.merge(Checks.checkIfCuBroken(fField));
        if (result.hasFatalError())
            return result;
        result.merge(checkNewElementName(getNewElementName()));
        pm.worked(1);
        result.merge(checkEnclosingHierarchy());
        pm.worked(1);
        result.merge(checkNestedHierarchy(fField.getDeclaringType()));
        pm.worked(1);
        if (fUpdateReferences) {
            pm.setTaskName(RefactoringCoreMessages.RenameFieldRefactoring_searching);
            fReferences = getReferences(new SubProgressMonitor(pm, 3), result);
            pm.setTaskName(RefactoringCoreMessages.RenameFieldRefactoring_checking);
        } else {
            fReferences = new SearchResultGroup[0];
            pm.worked(3);
        }
        if (fUpdateReferences)
            result.merge(analyzeAffectedCompilationUnits());
        else
            Checks.checkCompileErrorsInAffectedFile(result, fField.getResource());
        if (getGetter() != null && fRenameGetter) {
            result.merge(checkAccessor(new SubProgressMonitor(pm, 1), getGetter(), getNewGetterName()));
            result.merge(Checks.checkIfConstructorName(getGetter(), getNewGetterName(), fField.getDeclaringType().getElementName()));
        } else {
            pm.worked(1);
        }
        if (getSetter() != null && fRenameSetter) {
            result.merge(checkAccessor(new SubProgressMonitor(pm, 1), getSetter(), getNewSetterName()));
            result.merge(Checks.checkIfConstructorName(getSetter(), getNewSetterName(), fField.getDeclaringType().getElementName()));
        } else {
            pm.worked(1);
        }
        result.merge(createChanges(new SubProgressMonitor(pm, 10)));
        if (result.hasFatalError())
            return result;
        return result;
    } finally {
        pm.done();
    }
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

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