Search in sources :

Example 26 with RefactoringStatus

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

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

the class RenamePackageProcessor method checkNewElementName.

public RefactoringStatus checkNewElementName(String newName) throws CoreException {
    //$NON-NLS-1$
    Assert.isNotNull(newName, "new name");
    RefactoringStatus result = Checks.checkPackageName(newName, fPackage);
    if (result.hasFatalError())
        return result;
    if (Checks.isAlreadyNamed(fPackage, newName)) {
        result.addFatalError(RefactoringCoreMessages.RenamePackageRefactoring_another_name);
        return result;
    }
    result.merge(checkPackageInCurrentRoot(newName));
    return result;
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Example 28 with RefactoringStatus

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

the class RenamePackageProcessor method checkTypeNameConflicts.

private RefactoringStatus checkTypeNameConflicts(IPackageFragmentRoot root, String newName, Set<String> topLevelTypeNames) throws CoreException {
    IPackageFragment otherPack = root.getPackageFragment(newName);
    if (fPackage.equals(otherPack))
        return null;
    ICompilationUnit[] cus = otherPack.getCompilationUnits();
    RefactoringStatus result = new RefactoringStatus();
    for (int i = 0; i < cus.length; i++) {
        result.merge(checkTypeNameConflicts(cus[i], topLevelTypeNames));
    }
    return result;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Example 29 with RefactoringStatus

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

the class RenameAnalyzeUtil method analyzeLocalRenames.

/**
	 * This method analyzes a set of local variable renames inside one cu. It checks whether
	 * any new compile errors have been introduced by the rename(s) and whether the correct
	 * node(s) has/have been renamed.
	 *
	 * @param analyzePackages the LocalAnalyzePackages containing the information about the local renames
	 * @param cuChange the TextChange containing all local variable changes to be applied.
	 * @param oldCUNode the fully (incl. bindings) resolved AST node of the original compilation unit
	 * @param recovery whether statements and bindings recovery should be performed when parsing the changed CU
	 * @return a RefactoringStatus containing errors if compile errors or wrongly renamed nodes are found
	 * @throws CoreException thrown if there was an error greating the preview content of the change
	 */
public static RefactoringStatus analyzeLocalRenames(LocalAnalyzePackage[] analyzePackages, TextChange cuChange, CompilationUnit oldCUNode, boolean recovery) throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    ICompilationUnit compilationUnit = (ICompilationUnit) oldCUNode.getJavaElement();
    String newCuSource = cuChange.getPreviewContent(new NullProgressMonitor());
    CompilationUnit newCUNode = new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(newCuSource, compilationUnit, true, recovery, null);
    result.merge(analyzeCompileErrors(newCuSource, newCUNode, oldCUNode));
    if (result.hasError())
        return result;
    for (int i = 0; i < analyzePackages.length; i++) {
        ASTNode enclosing = getEnclosingBlockOrMethodOrLambda(analyzePackages[i].fDeclarationEdit, cuChange, newCUNode);
        // get new declaration
        IRegion newRegion = RefactoringAnalyzeUtil.getNewTextRange(analyzePackages[i].fDeclarationEdit, cuChange);
        ASTNode newDeclaration = NodeFinder.perform(newCUNode, newRegion.getOffset(), newRegion.getLength());
        Assert.isTrue(newDeclaration instanceof Name);
        VariableDeclaration declaration = getVariableDeclaration((Name) newDeclaration);
        Assert.isNotNull(declaration);
        SimpleName[] problemNodes = ProblemNodeFinder.getProblemNodes(enclosing, declaration, analyzePackages[i].fOccurenceEdits, cuChange);
        result.merge(RefactoringAnalyzeUtil.reportProblemNodes(newCuSource, problemNodes));
    }
    return result;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SimpleName(org.eclipse.jdt.core.dom.SimpleName) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IRegion(org.eclipse.jface.text.IRegion) SimpleName(org.eclipse.jdt.core.dom.SimpleName) Name(org.eclipse.jdt.core.dom.Name) RefactoringASTParser(org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser) ASTNode(org.eclipse.jdt.core.dom.ASTNode) VariableDeclaration(org.eclipse.jdt.core.dom.VariableDeclaration)

Example 30 with RefactoringStatus

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

the class InlineTempRefactoring method checkInitialConditions.

/*
	 * @see Refactoring#checkActivation(IProgressMonitor)
	 */
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
    try {
        //$NON-NLS-1$
        pm.beginTask("", 1);
        RefactoringStatus result = Checks.validateModifiesFiles(ResourceUtil.getFiles(new ICompilationUnit[] { fCu }), getValidationContext());
        if (result.hasFatalError())
            return result;
        VariableDeclaration declaration = getVariableDeclaration();
        result.merge(checkSelection(declaration));
        if (result.hasFatalError())
            return result;
        result.merge(checkInitializer(declaration));
        return result;
    } finally {
        pm.done();
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) VariableDeclaration(org.eclipse.jdt.core.dom.VariableDeclaration) SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration)

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