Search in sources :

Example 76 with RefactoringStatus

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

the class IntroduceFactoryRefactoring method checkFinalConditions.

/*
	 * @see org.eclipse.jdt.internal.corext.refactoring.base.Refactoring#checkInput(org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
    try {
        pm.beginTask(RefactoringCoreMessages.IntroduceFactory_checking_preconditions, 1);
        RefactoringStatus result = new RefactoringStatus();
        if (fFactoryClassName != null)
            result.merge(setFactoryClass(fFactoryClassName));
        if (result.hasFatalError())
            return result;
        fArgTypes = fCtorBinding.getParameterTypes();
        fCtorIsVarArgs = fCtorBinding.isVarargs();
        fAllCallsTo = findAllCallsTo(fCtorBinding, pm, result);
        fFormalArgNames = findCtorArgNames();
        ICompilationUnit[] affectedFiles = collectAffectedUnits(fAllCallsTo);
        result.merge(Checks.validateModifiesFiles(ResourceUtil.getFiles(affectedFiles), getValidationContext()));
        if (fCallSitesInBinaryUnits)
            result.merge(RefactoringStatus.createWarningStatus(RefactoringCoreMessages.IntroduceFactory_callSitesInBinaryClass));
        if (Modifier.isAbstract(fCtorBinding.getDeclaringClass().getModifiers())) {
            result.merge(RefactoringStatus.createWarningStatus(RefactoringCoreMessages.IntroduceFactory_abstractClass));
        }
        return result;
    } finally {
        pm.done();
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Example 77 with RefactoringStatus

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

the class IntroduceFactoryRefactoring method setFactoryClass.

/**
	 * Sets the class on which the generated factory method is to be placed.
	 * @param fullyQualifiedTypeName an <code>IType</code> referring to an existing class
	 * @return return the resulting status
	 */
public RefactoringStatus setFactoryClass(String fullyQualifiedTypeName) {
    IType factoryType;
    try {
        factoryType = findFactoryClass(fullyQualifiedTypeName);
        if (factoryType == null)
            return RefactoringStatus.createErrorStatus(Messages.format(RefactoringCoreMessages.IntroduceFactory_noSuchClass, BasicElementLabels.getJavaElementName(fullyQualifiedTypeName)));
        if (factoryType.isAnnotation())
            return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceFactory_cantPutFactoryMethodOnAnnotation);
        if (factoryType.isInterface())
            return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceFactory_cantPutFactoryMethodOnInterface);
    } catch (JavaModelException e) {
        return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceFactory_cantCheckForInterface);
    }
    ICompilationUnit factoryUnitHandle = factoryType.getCompilationUnit();
    if (factoryType.isBinary())
        return RefactoringStatus.createErrorStatus(RefactoringCoreMessages.IntroduceFactory_cantPutFactoryInBinaryClass);
    else {
        try {
            if (!fFactoryUnitHandle.equals(factoryUnitHandle)) {
                fFactoryCU = getASTFor(factoryUnitHandle);
                fFactoryUnitHandle = factoryUnitHandle;
            }
            fFactoryOwningClass = (AbstractTypeDeclaration) ASTNodes.getParent(NodeFinder.perform(fFactoryCU, factoryType.getNameRange()), AbstractTypeDeclaration.class);
            String factoryPkg = factoryType.getPackageFragment().getElementName();
            String ctorPkg = fCtorOwningClass.resolveBinding().getPackage().getName();
            if (!factoryPkg.equals(ctorPkg))
                fConstructorVisibility = Modifier.PUBLIC;
            else if (fFactoryOwningClass != fCtorOwningClass)
                // No such thing as Modifier.PACKAGE...
                fConstructorVisibility = 0;
            if (fFactoryOwningClass != fCtorOwningClass)
                // No such thing as Modifier.PACKAGE...
                fConstructorVisibility = 0;
        } catch (JavaModelException e) {
            return RefactoringStatus.createFatalErrorStatus(e.getMessage());
        }
        return new RefactoringStatus();
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JavaModelException(org.eclipse.jdt.core.JavaModelException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IType(org.eclipse.jdt.core.IType)

Example 78 with RefactoringStatus

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

the class IntroduceIndirectionRefactoring method adjustVisibility.

private RefactoringStatus adjustVisibility(IMember whoToAdjust, ModifierKeyword neededVisibility, boolean alsoIncreaseEnclosing, IProgressMonitor monitor) throws CoreException {
    Map<IMember, IncomingMemberVisibilityAdjustment> adjustments;
    if (isRewriteKept(whoToAdjust.getCompilationUnit()))
        adjustments = fIntermediaryAdjustments;
    else
        adjustments = new HashMap<IMember, IncomingMemberVisibilityAdjustment>();
    int existingAdjustments = adjustments.size();
    addAdjustment(whoToAdjust, neededVisibility, adjustments);
    if (alsoIncreaseEnclosing)
        while (whoToAdjust.getDeclaringType() != null) {
            whoToAdjust = whoToAdjust.getDeclaringType();
            addAdjustment(whoToAdjust, neededVisibility, adjustments);
        }
    boolean hasNewAdjustments = (adjustments.size() - existingAdjustments) > 0;
    if (hasNewAdjustments && ((whoToAdjust.isReadOnly() || whoToAdjust.isBinary())))
        return RefactoringStatus.createErrorStatus(Messages.format(RefactoringCoreMessages.IntroduceIndirectionRefactoring_cannot_update_binary_target_visibility, new String[] { JavaElementLabels.getElementLabel(whoToAdjust, JavaElementLabels.ALL_DEFAULT) }), JavaStatusContext.create(whoToAdjust));
    RefactoringStatus status = new RefactoringStatus();
    // Don't create a rewrite if it is not necessary
    if (!hasNewAdjustments)
        return status;
    try {
        monitor.beginTask(RefactoringCoreMessages.MemberVisibilityAdjustor_adjusting, 2);
        Map<ICompilationUnit, CompilationUnitRewrite> rewrites;
        if (!isRewriteKept(whoToAdjust.getCompilationUnit())) {
            CompilationUnitRewrite rewrite = new CompilationUnitRewrite(whoToAdjust.getCompilationUnit());
            rewrite.setResolveBindings(false);
            rewrites = new HashMap<ICompilationUnit, CompilationUnitRewrite>();
            rewrites.put(whoToAdjust.getCompilationUnit(), rewrite);
            status.merge(rewriteVisibility(adjustments, rewrites, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)));
            rewrite.attachChange((CompilationUnitChange) fTextChangeManager.get(whoToAdjust.getCompilationUnit()), true, new SubProgressMonitor(monitor, 1, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
        }
    } finally {
        monitor.done();
    }
    return status;
}
Also used : CompilationUnitRewrite(org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite) IncomingMemberVisibilityAdjustment(org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.IncomingMemberVisibilityAdjustment) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) HashMap(java.util.HashMap) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IMember(org.eclipse.jdt.core.IMember) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 79 with RefactoringStatus

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

the class ExtractTempRefactoring method checkInitialConditions.

@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
    try {
        //$NON-NLS-1$
        pm.beginTask("", 6);
        RefactoringStatus result = Checks.validateModifiesFiles(ResourceUtil.getFiles(new ICompilationUnit[] { fCu }), getValidationContext());
        if (result.hasFatalError())
            return result;
        if (fCompilationUnitNode == null) {
            fCompilationUnitNode = RefactoringASTParser.parseWithASTProvider(fCu, true, new SubProgressMonitor(pm, 3));
        } else {
            pm.worked(3);
        }
        result.merge(checkSelection(new SubProgressMonitor(pm, 3)));
        if (!result.hasFatalError() && isLiteralNodeSelected())
            fReplaceAllOccurrences = false;
        return result;
    } finally {
        pm.done();
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 80 with RefactoringStatus

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

the class ExtractTempRefactoring method checkMatchingFragments.

private RefactoringStatus checkMatchingFragments() throws JavaModelException {
    RefactoringStatus result = new RefactoringStatus();
    IASTFragment[] matchingFragments = getMatchingFragments();
    for (int i = 0; i < matchingFragments.length; i++) {
        ASTNode node = matchingFragments[i].getAssociatedNode();
        if (isLeftValue(node) && !isReferringToLocalVariableFromFor((Expression) node)) {
            String msg = RefactoringCoreMessages.ExtractTempRefactoring_assigned_to;
            result.addWarning(msg, JavaStatusContext.create(fCu, node));
        }
    }
    return result;
}
Also used : IASTFragment(org.eclipse.jdt.internal.corext.dom.fragments.IASTFragment) ASTNode(org.eclipse.jdt.core.dom.ASTNode) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus)

Aggregations

RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)251 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 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)28 IJavaElement (org.eclipse.jdt.core.IJavaElement)28 Test (org.junit.Test)26 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)24 ArrayList (java.util.ArrayList)23 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 IFile (org.eclipse.core.resources.IFile)16 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)16 ASTNode (org.eclipse.jdt.core.dom.ASTNode)16 CoreException (org.eclipse.core.runtime.CoreException)15 IField (org.eclipse.jdt.core.IField)15 IStatus (org.eclipse.core.runtime.IStatus)14 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)13