Search in sources :

Example 1 with RefactoringStatusContext

use of org.eclipse.ltk.core.refactoring.RefactoringStatusContext 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 2 with RefactoringStatusContext

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

the class RenameTypeProcessor method analyseEnclosedTypes.

private RefactoringStatus analyseEnclosedTypes() throws CoreException {
    final ISourceRange typeRange = fType.getSourceRange();
    final RefactoringStatus result = new RefactoringStatus();
    CompilationUnit cuNode = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(fType.getCompilationUnit(), false);
    cuNode.accept(new ASTVisitor() {

        @Override
        public boolean visit(TypeDeclaration node) {
            // enums and annotations can't be local
            if (node.getStartPosition() <= typeRange.getOffset())
                return true;
            if (node.getStartPosition() > typeRange.getOffset() + typeRange.getLength())
                return true;
            if (getNewElementName().equals(node.getName().getIdentifier())) {
                RefactoringStatusContext context = JavaStatusContext.create(fType.getCompilationUnit(), node);
                String msg = null;
                if (node.isLocalTypeDeclaration()) {
                    msg = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_local_type, new String[] { JavaElementUtil.createSignature(fType), getNewElementLabel() });
                } else if (node.isMemberTypeDeclaration()) {
                    msg = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_member_type, new String[] { JavaElementUtil.createSignature(fType), getNewElementLabel() });
                }
                if (msg != null)
                    result.addError(msg, context);
            }
            MethodDeclaration[] methods = node.getMethods();
            for (int i = 0; i < methods.length; i++) {
                if (Modifier.isNative(methods[i].getModifiers())) {
                    RefactoringStatusContext context = JavaStatusContext.create(fType.getCompilationUnit(), methods[i]);
                    String msg = Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_enclosed_type_native, BasicElementLabels.getJavaElementName(node.getName().getIdentifier()));
                    result.addWarning(msg, context);
                }
            }
            return true;
        }
    });
    return result;
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) RefactoringASTParser(org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) ISourceRange(org.eclipse.jdt.core.ISourceRange) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor)

Example 3 with RefactoringStatusContext

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

the class RenamePackageProcessor method checkTypeNameConflicts.

private RefactoringStatus checkTypeNameConflicts(ICompilationUnit iCompilationUnit, Set<String> topLevelTypeNames) throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    IType[] types = iCompilationUnit.getTypes();
    for (int i = 0; i < types.length; i++) {
        String name = types[i].getElementName();
        if (topLevelTypeNames.contains(name)) {
            String[] keys = { getElementLabel(iCompilationUnit.getParent()), getElementLabel(types[i]) };
            String msg = Messages.format(RefactoringCoreMessages.RenamePackageRefactoring_contains_type, keys);
            RefactoringStatusContext context = JavaStatusContext.create(types[i]);
            result.addError(msg, context);
        }
    }
    return result;
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IType(org.eclipse.jdt.core.IType)

Example 4 with RefactoringStatusContext

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

the class MethodChecks method checkIfOverridesAnother.

public static RefactoringStatus checkIfOverridesAnother(IMethod method, ITypeHierarchy hierarchy) throws JavaModelException {
    IMethod overrides = MethodChecks.overridesAnotherMethod(method, hierarchy);
    if (overrides == null)
        return null;
    RefactoringStatusContext context = JavaStatusContext.create(overrides);
    String message = Messages.format(RefactoringCoreMessages.MethodChecks_overrides, new String[] { JavaElementUtil.createMethodSignature(overrides), JavaElementLabels.getElementLabel(overrides.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED) });
    return RefactoringStatus.createStatus(RefactoringStatus.FATAL, message, context, Corext.getPluginId(), RefactoringStatusCodes.OVERRIDES_ANOTHER_METHOD, overrides);
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) IMethod(org.eclipse.jdt.core.IMethod)

Example 5 with RefactoringStatusContext

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

the class MethodChecks method checkIfComesFromInterface.

public static RefactoringStatus checkIfComesFromInterface(IMethod method, ITypeHierarchy hierarchy, IProgressMonitor monitor) throws JavaModelException {
    IMethod inInterface = MethodChecks.isDeclaredInInterface(method, hierarchy, monitor);
    if (inInterface == null)
        return null;
    RefactoringStatusContext context = JavaStatusContext.create(inInterface);
    String message = Messages.format(RefactoringCoreMessages.MethodChecks_implements, new String[] { JavaElementUtil.createMethodSignature(inInterface), JavaElementLabels.getElementLabel(inInterface.getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED) });
    return RefactoringStatus.createStatus(RefactoringStatus.FATAL, message, context, Corext.getPluginId(), RefactoringStatusCodes.METHOD_DECLARED_IN_INTERFACE, inInterface);
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) IMethod(org.eclipse.jdt.core.IMethod)

Aggregations

RefactoringStatusContext (org.eclipse.ltk.core.refactoring.RefactoringStatusContext)15 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)10 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