Search in sources :

Example 6 with RefactoringStatusContext

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

the class RenameNonVirtualMethodProcessor method doCheckFinalConditions.

//----------- preconditions --------------
@Override
protected RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext checkContext) throws CoreException {
    try {
        //$NON-NLS-1$
        pm.beginTask("", 3);
        RefactoringStatus result = new RefactoringStatus();
        result.merge(super.doCheckFinalConditions(new SubProgressMonitor(pm, 1), checkContext));
        if (result.hasFatalError())
            return result;
        final IMethod method = getMethod();
        final IType declaring = method.getDeclaringType();
        final String name = getNewElementName();
        IMethod[] hierarchyMethods = hierarchyDeclaresMethodName(new SubProgressMonitor(pm, 1), declaring.newTypeHierarchy(new SubProgressMonitor(pm, 1)), 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())) {
                String message = Messages.format(RefactoringCoreMessages.RenamePrivateMethodRefactoring_hierarchy_defines, new String[] { BasicElementLabels.getJavaElementName(declaring.getFullyQualifiedName('.')), BasicElementLabels.getJavaElementName(name) });
                result.addError(message, context);
            } else {
                String message = Messages.format(RefactoringCoreMessages.RenamePrivateMethodRefactoring_hierarchy_defines2, new String[] { BasicElementLabels.getJavaElementName(declaring.getFullyQualifiedName('.')), BasicElementLabels.getJavaElementName(name) });
                result.addWarning(message, context);
            }
        }
        return result;
    } finally {
        pm.done();
    }
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) 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 RefactoringStatusContext

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

the class RenameAnalyzeUtil method addReferenceShadowedError.

private static void addReferenceShadowedError(ICompilationUnit cu, SearchMatch newMatch, String newElementName, RefactoringStatus result) {
    //TODO: should not have to filter declarations:
    if (newMatch instanceof MethodDeclarationMatch || newMatch instanceof FieldDeclarationMatch)
        return;
    ISourceRange range = getOldSourceRange(newMatch);
    RefactoringStatusContext context = JavaStatusContext.create(cu, range);
    String message = Messages.format(RefactoringCoreMessages.RenameAnalyzeUtil_reference_shadowed, new String[] { BasicElementLabels.getFileName(cu), BasicElementLabels.getJavaElementName(newElementName) });
    result.addError(message, context);
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) MethodDeclarationMatch(org.eclipse.jdt.core.search.MethodDeclarationMatch) FieldDeclarationMatch(org.eclipse.jdt.core.search.FieldDeclarationMatch) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Example 8 with RefactoringStatusContext

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

the class RenameAnalyzeUtil method addShadowsError.

private static void addShadowsError(ICompilationUnit cu, SearchMatch oldMatch, RefactoringStatus result) {
    //TODO: should not have to filter declarations:
    if (oldMatch instanceof MethodDeclarationMatch || oldMatch instanceof FieldDeclarationMatch)
        return;
    ISourceRange range = new SourceRange(oldMatch.getOffset(), oldMatch.getLength());
    RefactoringStatusContext context = JavaStatusContext.create(cu, range);
    String message = Messages.format(RefactoringCoreMessages.RenameAnalyzeUtil_shadows, BasicElementLabels.getFileName(cu));
    result.addError(message, context);
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) ISourceRange(org.eclipse.jdt.core.ISourceRange) SourceRange(org.eclipse.jdt.core.SourceRange) MethodDeclarationMatch(org.eclipse.jdt.core.search.MethodDeclarationMatch) FieldDeclarationMatch(org.eclipse.jdt.core.search.FieldDeclarationMatch) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Example 9 with RefactoringStatusContext

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

the class ChangeSignatureProcessor method checkInitialConditions.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.Refactoring#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor monitor) throws CoreException {
    try {
        //$NON-NLS-1$
        monitor.beginTask("", 5);
        RefactoringStatus result = Checks.checkIfCuBroken(fMethod);
        if (result.hasFatalError())
            return result;
        if (fMethod == null || !fMethod.exists()) {
            String message = Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_method_deleted, BasicElementLabels.getFileName(getCu()));
            return RefactoringStatus.createFatalErrorStatus(message);
        }
        if (fMethod.getDeclaringType().isInterface()) {
            fTopMethod = MethodChecks.overridesAnotherMethod(fMethod, fMethod.getDeclaringType().newSupertypeHierarchy(new SubProgressMonitor(monitor, 1)));
            monitor.worked(1);
        } else if (MethodChecks.isVirtual(fMethod)) {
            ITypeHierarchy hierarchy = getCachedTypeHierarchy(new SubProgressMonitor(monitor, 1));
            fTopMethod = MethodChecks.isDeclaredInInterface(fMethod, hierarchy, new SubProgressMonitor(monitor, 1));
            if (fTopMethod == null)
                fTopMethod = MethodChecks.overridesAnotherMethod(fMethod, hierarchy);
        }
        if (fTopMethod == null)
            fTopMethod = fMethod;
        if (!fTopMethod.equals(fMethod)) {
            if (fTopMethod.getDeclaringType().isInterface()) {
                RefactoringStatusContext context = JavaStatusContext.create(fTopMethod);
                String message = Messages.format(RefactoringCoreMessages.MethodChecks_implements, new String[] { JavaElementUtil.createMethodSignature(fTopMethod), BasicElementLabels.getJavaElementName(fTopMethod.getDeclaringType().getFullyQualifiedName('.')) });
                return RefactoringStatus.createStatus(RefactoringStatus.FATAL, message, context, Corext.getPluginId(), RefactoringStatusCodes.METHOD_DECLARED_IN_INTERFACE, fTopMethod);
            } else {
                RefactoringStatusContext context = JavaStatusContext.create(fTopMethod);
                String message = Messages.format(RefactoringCoreMessages.MethodChecks_overrides, new String[] { JavaElementUtil.createMethodSignature(fTopMethod), BasicElementLabels.getJavaElementName(fTopMethod.getDeclaringType().getFullyQualifiedName('.')) });
                return RefactoringStatus.createStatus(RefactoringStatus.FATAL, message, context, Corext.getPluginId(), RefactoringStatusCodes.OVERRIDES_ANOTHER_METHOD, fTopMethod);
            }
        }
        if (monitor.isCanceled())
            throw new OperationCanceledException();
        if (fBaseCuRewrite == null || !fBaseCuRewrite.getCu().equals(getCu())) {
            fBaseCuRewrite = new CompilationUnitRewrite(getCu());
            fBaseCuRewrite.getASTRewrite().setTargetSourceRangeComputer(new TightSourceRangeComputer());
        }
        RefactoringStatus[] status = TypeContextChecker.checkMethodTypesSyntax(fMethod, getParameterInfos(), fReturnTypeInfo);
        for (int i = 0; i < status.length; i++) {
            result.merge(status[i]);
        }
        monitor.worked(1);
        result.merge(createExceptionInfoList());
        monitor.worked(1);
        return result;
    } finally {
        monitor.done();
    }
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) TightSourceRangeComputer(org.eclipse.jdt.internal.corext.refactoring.util.TightSourceRangeComputer) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 10 with RefactoringStatusContext

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

the class InlineTempRefactoring method checkAssignments.

private RefactoringStatus checkAssignments(VariableDeclaration decl) {
    TempAssignmentFinder assignmentFinder = new TempAssignmentFinder(decl);
    getASTRoot().accept(assignmentFinder);
    if (!assignmentFinder.hasAssignments())
        return new RefactoringStatus();
    ASTNode firstAssignment = assignmentFinder.getFirstAssignment();
    int start = firstAssignment.getStartPosition();
    int length = firstAssignment.getLength();
    ISourceRange range = new SourceRange(start, length);
    RefactoringStatusContext context = JavaStatusContext.create(fCu, range);
    String message = Messages.format(RefactoringCoreMessages.InlineTempRefactoring_assigned_more_once, BasicElementLabels.getJavaElementName(decl.getName().getIdentifier()));
    return RefactoringStatus.createFatalErrorStatus(message, context);
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) ASTNode(org.eclipse.jdt.core.dom.ASTNode) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ISourceRange(org.eclipse.jdt.core.ISourceRange) SourceRange(org.eclipse.jdt.core.SourceRange) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Aggregations

RefactoringStatusContext (org.eclipse.ltk.core.refactoring.RefactoringStatusContext)14 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)9 IMethod (org.eclipse.jdt.core.IMethod)4 ISourceRange (org.eclipse.jdt.core.ISourceRange)4 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 IType (org.eclipse.jdt.core.IType)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)2 SourceRange (org.eclipse.jdt.core.SourceRange)2 FieldDeclarationMatch (org.eclipse.jdt.core.search.FieldDeclarationMatch)2 MethodDeclarationMatch (org.eclipse.jdt.core.search.MethodDeclarationMatch)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 IImportDeclaration (org.eclipse.jdt.core.IImportDeclaration)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 ASTVisitor (org.eclipse.jdt.core.dom.ASTVisitor)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)1 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)1 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)1